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_filehelper_h__ michael@0: #define mozilla_dom_file_filehelper_h__ michael@0: michael@0: #include "FileCommon.h" michael@0: michael@0: #include "nsIRequestObserver.h" michael@0: michael@0: class nsIFileStorage; michael@0: michael@0: BEGIN_FILE_NAMESPACE michael@0: michael@0: class FileHelper; michael@0: class FileRequest; michael@0: class FileOutputStreamWrapper; michael@0: class LockedFile; michael@0: michael@0: class FileHelperListener michael@0: { michael@0: public: michael@0: NS_IMETHOD_(MozExternalRefCountType) michael@0: AddRef() = 0; michael@0: michael@0: NS_IMETHOD_(MozExternalRefCountType) michael@0: Release() = 0; michael@0: michael@0: virtual void michael@0: OnFileHelperComplete(FileHelper* aFileHelper) = 0; michael@0: }; michael@0: michael@0: /** michael@0: * Must be subclassed. The subclass must implement DoAsyncRun. It may then michael@0: * choose to implement GetSuccessResult to properly set the result of the michael@0: * success event. Call Enqueue to start the file operation. michael@0: */ michael@0: class FileHelper : public nsIRequestObserver michael@0: { michael@0: friend class FileRequest; michael@0: friend class FileOutputStreamWrapper; michael@0: michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: michael@0: nsresult michael@0: Enqueue(); michael@0: michael@0: nsresult michael@0: AsyncRun(FileHelperListener* aListener); michael@0: michael@0: void michael@0: OnStreamProgress(uint64_t aProgress, uint64_t aProgressMax); michael@0: michael@0: void michael@0: OnStreamClose(); michael@0: michael@0: void michael@0: OnStreamDestroy(); michael@0: michael@0: static LockedFile* michael@0: GetCurrentLockedFile(); michael@0: michael@0: protected: michael@0: FileHelper(LockedFile* aLockedFile, FileRequest* aRequest); michael@0: michael@0: virtual ~FileHelper(); michael@0: michael@0: virtual nsresult michael@0: DoAsyncRun(nsISupports* aStream) = 0; michael@0: michael@0: virtual nsresult michael@0: GetSuccessResult(JSContext* aCx, JS::MutableHandle aVal); michael@0: michael@0: virtual void michael@0: ReleaseObjects(); michael@0: michael@0: void michael@0: Finish(); michael@0: michael@0: nsCOMPtr mFileStorage; michael@0: nsRefPtr mLockedFile; michael@0: nsRefPtr mFileRequest; michael@0: michael@0: nsRefPtr mListener; michael@0: nsCOMPtr mRequest; michael@0: michael@0: private: michael@0: nsresult mResultCode; michael@0: bool mFinished; michael@0: }; michael@0: michael@0: END_FILE_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_file_filehelper_h__