michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_file_metadatahelper_h__ michael@0: #define mozilla_dom_file_metadatahelper_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "FileCommon.h" michael@0: michael@0: #include "nsIFileStreams.h" michael@0: michael@0: #include "AsyncHelper.h" michael@0: #include "FileHelper.h" michael@0: michael@0: class nsIFileStream; michael@0: michael@0: BEGIN_FILE_NAMESPACE michael@0: michael@0: class MetadataHelper; michael@0: michael@0: class MetadataParameters MOZ_FINAL michael@0: { michael@0: friend class MetadataHelper; michael@0: michael@0: public: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataParameters) michael@0: michael@0: MetadataParameters(bool aSizeRequested, bool aLastModifiedRequested) michael@0: : mSizeRequested(aSizeRequested) michael@0: , mLastModifiedRequested(aLastModifiedRequested) michael@0: { michael@0: } michael@0: michael@0: bool michael@0: IsConfigured() const michael@0: { michael@0: return mSizeRequested || mLastModifiedRequested; michael@0: } michael@0: michael@0: bool michael@0: SizeRequested() const michael@0: { michael@0: return mSizeRequested; michael@0: } michael@0: michael@0: bool michael@0: LastModifiedRequested() const michael@0: { michael@0: return mLastModifiedRequested; michael@0: } michael@0: michael@0: uint64_t michael@0: Size() const michael@0: { michael@0: return mSize; michael@0: } michael@0: michael@0: int64_t michael@0: LastModified() const michael@0: { michael@0: return mLastModified; michael@0: } michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~MetadataParameters() michael@0: { michael@0: } michael@0: michael@0: uint64_t mSize; michael@0: int64_t mLastModified; michael@0: bool mSizeRequested; michael@0: bool mLastModifiedRequested; michael@0: }; michael@0: michael@0: class MetadataHelper : public FileHelper michael@0: { michael@0: public: michael@0: MetadataHelper(LockedFile* aLockedFile, michael@0: FileRequest* aFileRequest, michael@0: MetadataParameters* aParams) michael@0: : FileHelper(aLockedFile, aFileRequest), michael@0: mParams(aParams) michael@0: { } michael@0: michael@0: nsresult michael@0: DoAsyncRun(nsISupports* aStream) MOZ_OVERRIDE; michael@0: michael@0: nsresult michael@0: GetSuccessResult(JSContext* aCx, michael@0: JS::MutableHandle aVal) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: class AsyncMetadataGetter : public AsyncHelper michael@0: { michael@0: public: michael@0: AsyncMetadataGetter(nsISupports* aStream, MetadataParameters* aParams, michael@0: bool aReadWrite) michael@0: : AsyncHelper(aStream), michael@0: mParams(aParams), mReadWrite(aReadWrite) michael@0: { } michael@0: michael@0: protected: michael@0: nsresult michael@0: DoStreamWork(nsISupports* aStream) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: nsRefPtr mParams; michael@0: bool mReadWrite; michael@0: }; michael@0: michael@0: nsRefPtr mParams; michael@0: }; michael@0: michael@0: END_FILE_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_file_metadatahelper_h__