diff options
-rw-r--r-- | base/file_util_proxy.cc | 51 | ||||
-rw-r--r-- | base/file_util_proxy.h | 7 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.cc | 270 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.h | 72 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 183 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 29 |
6 files changed, 133 insertions, 479 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc index 4c79465..9b51d34 100644 --- a/base/file_util_proxy.cc +++ b/base/file_util_proxy.cc @@ -176,19 +176,6 @@ class CreateTemporaryHelper { DISALLOW_COPY_AND_ASSIGN(CreateTemporaryHelper); }; -PlatformFileError DeleteHelper(const FilePath& file_path, bool recursive) { - if (!file_util::PathExists(file_path)) { - return PLATFORM_FILE_ERROR_NOT_FOUND; - } - if (!file_util::Delete(file_path, recursive)) { - if (!recursive && !file_util::IsDirectoryEmpty(file_path)) { - return PLATFORM_FILE_ERROR_NOT_EMPTY; - } - return PLATFORM_FILE_ERROR_FAILED; - } - return PLATFORM_FILE_OK; -} - class GetFileInfoHelper { public: GetFileInfoHelper() @@ -297,6 +284,19 @@ PlatformFileError CloseAdapter(PlatformFile file_handle) { return PLATFORM_FILE_OK; } +PlatformFileError DeleteAdapter(const FilePath& file_path, bool recursive) { + if (!file_util::PathExists(file_path)) { + return PLATFORM_FILE_ERROR_NOT_FOUND; + } + if (!file_util::Delete(file_path, recursive)) { + if (!recursive && !file_util::IsDirectoryEmpty(file_path)) { + return PLATFORM_FILE_ERROR_NOT_EMPTY; + } + return PLATFORM_FILE_ERROR_FAILED; + } + return PLATFORM_FILE_OK; +} + } // namespace // static @@ -367,10 +367,10 @@ bool FileUtilProxy::Delete(scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& file_path, bool recursive, const StatusCallback& callback) { - return PostTaskAndReplyWithStatus<PlatformFileError>( + return RelayFileTask( message_loop_proxy, FROM_HERE, - Bind(&DeleteHelper, file_path, recursive), callback, - new PlatformFileError); + Bind(&DeleteAdapter, file_path, recursive), + callback); } // static @@ -378,10 +378,10 @@ bool FileUtilProxy::RecursiveDelete( scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& file_path, const StatusCallback& callback) { - return PostTaskAndReplyWithStatus<PlatformFileError>( + return RelayFileTask( message_loop_proxy, FROM_HERE, - Bind(&DeleteHelper, file_path, true /* recursive */), callback, - new PlatformFileError); + Bind(&DeleteAdapter, file_path, true /* recursive */), + callback); } // static @@ -472,6 +472,19 @@ bool FileUtilProxy::Flush( } // static +bool FileUtilProxy::RelayFileTask( + scoped_refptr<MessageLoopProxy> message_loop_proxy, + const tracked_objects::Location& from_here, + const FileTask& file_task, + const StatusCallback& callback) { + PlatformFileError* result = new PlatformFileError; + return message_loop_proxy->PostTaskAndReply( + from_here, + ReturnAsParam(file_task, result), + ReplyHelper(callback, Owned(result))); +} + +// static bool FileUtilProxy::RelayCreateOrOpen( scoped_refptr<MessageLoopProxy> message_loop_proxy, const CreateOrOpenTask& open_task, diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h index 15a3e82..1cde1ce 100644 --- a/base/file_util_proxy.h +++ b/base/file_util_proxy.h @@ -53,6 +53,7 @@ class BASE_EXPORT FileUtilProxy { typedef Callback<PlatformFileError(PlatformFile*, bool*)> CreateOrOpenTask; typedef Callback<PlatformFileError(PlatformFile)> CloseTask; + typedef Callback<PlatformFileError(void)> FileTask; // Creates or opens a file with the given flags. It is invalid to pass a null // callback. If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to @@ -168,6 +169,12 @@ class BASE_EXPORT FileUtilProxy { const StatusCallback& callback); // Relay helpers. + static bool RelayFileTask( + scoped_refptr<MessageLoopProxy> message_loop_proxy, + const tracked_objects::Location& from_here, + const FileTask& task, + const StatusCallback& callback); + static bool RelayCreateOrOpen( scoped_refptr<MessageLoopProxy> message_loop_proxy, const CreateOrOpenTask& open_task, diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc index 6c54cdc..9569d41 100644 --- a/webkit/fileapi/file_system_file_util_proxy.cc +++ b/webkit/fileapi/file_system_file_util_proxy.cc @@ -71,27 +71,6 @@ class MessageLoopRelay fileapi::FileSystemFileUtil* file_util_; }; -class RelayWithStatusCallback : public MessageLoopRelay { - public: - RelayWithStatusCallback( - const fileapi::FileSystemOperationContext& context, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : MessageLoopRelay(context), - callback_(callback) { - // It is OK for callback to be NULL. - } - - protected: - virtual void RunCallback() { - // The caller may not have been interested in the result. - if (!callback_.is_null()) - callback_.Run(error_code()); - } - - private: - fileapi::FileSystemFileUtilProxy::StatusCallback callback_; -}; - class RelayEnsureFileExists : public MessageLoopRelay { public: RelayEnsureFileExists( @@ -126,35 +105,6 @@ class RelayEnsureFileExists : public MessageLoopRelay { }; -class RelayGetLocalPath : public MessageLoopRelay { - public: - RelayGetLocalPath( - const fileapi::FileSystemOperationContext& context, - const FilePath& virtual_path, - fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback) - : MessageLoopRelay(context), - callback_(callback), - virtual_path_(virtual_path) { - DCHECK(callback); - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->GetLocalFilePath( - context(), virtual_path_, &local_path_)); - } - - virtual void RunCallback() { - callback_->Run(error_code(), local_path_); - delete callback_; - } - - private: - fileapi::FileSystemFileUtilProxy::GetLocalPathCallback* callback_; - FilePath virtual_path_; - FilePath local_path_; -}; - class RelayGetFileInfo : public MessageLoopRelay { public: RelayGetFileInfo( @@ -212,145 +162,6 @@ class RelayReadDirectory : public MessageLoopRelay { std::vector<base::FileUtilProxy::Entry> entries_; }; -class RelayCreateDirectory : public RelayWithStatusCallback { - public: - RelayCreateDirectory( - const fileapi::FileSystemOperationContext& context, - const FilePath& file_path, - bool exclusive, - bool recursive, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - file_path_(file_path), - exclusive_(exclusive), - recursive_(recursive) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->CreateDirectory( - context(), file_path_, exclusive_, recursive_)); - } - - private: - FilePath file_path_; - bool exclusive_; - bool recursive_; -}; - -class RelayCopy : public RelayWithStatusCallback { - public: - RelayCopy(const fileapi::FileSystemOperationContext& context, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - src_file_path_(src_file_path), - dest_file_path_(dest_file_path) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->Copy( - context(), src_file_path_, dest_file_path_)); - } - - private: - FilePath src_file_path_; - FilePath dest_file_path_; -}; - -class RelayMove : public RelayWithStatusCallback { - public: - RelayMove(const fileapi::FileSystemOperationContext& context, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - src_file_path_(src_file_path), - dest_file_path_(dest_file_path) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->Move( - context(), src_file_path_, dest_file_path_)); - } - - private: - FilePath src_file_path_; - FilePath dest_file_path_; -}; - -class RelayDelete : public RelayWithStatusCallback { - public: - RelayDelete(const fileapi::FileSystemOperationContext& context, - const FilePath& file_path, - bool recursive, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - file_path_(file_path), - recursive_(recursive) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->Delete(context(), file_path_, recursive_)); - } - - private: - FilePath file_path_; - bool recursive_; -}; - -class RelayTouchFilePath : public RelayWithStatusCallback { - public: - RelayTouchFilePath( - const fileapi::FileSystemOperationContext& context, - const FilePath& file_path, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - file_path_(file_path), - last_access_time_(last_access_time), - last_modified_time_(last_modified_time) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->Touch( - context(), file_path_, last_access_time_, last_modified_time_)); - } - - private: - FilePath file_path_; - base::Time last_access_time_; - base::Time last_modified_time_; -}; - -class RelayTruncate : public RelayWithStatusCallback { - public: - RelayTruncate( - const fileapi::FileSystemOperationContext& context, - const FilePath& file_path, - int64 length, - const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) - : RelayWithStatusCallback(context, callback), - file_path_(file_path), - length_(length) { - } - - protected: - virtual void RunWork() { - set_error_code(file_util()->Truncate(context(), file_path_, length_)); - } - - private: - FilePath file_path_; - int64 length_; -}; - bool Start(const tracked_objects::Location& from_here, scoped_refptr<base::MessageLoopProxy> message_loop_proxy, scoped_refptr<MessageLoopRelay> relay) { @@ -372,16 +183,6 @@ bool FileSystemFileUtilProxy::EnsureFileExists( } // static -bool FileSystemFileUtilProxy::GetLocalPath( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& virtual_path, - GetLocalPathCallback* callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayGetLocalPath(context, virtual_path, callback)); -} - -// static bool FileSystemFileUtilProxy::GetFileInfo( const FileSystemOperationContext& context, scoped_refptr<MessageLoopProxy> message_loop_proxy, @@ -401,75 +202,4 @@ bool FileSystemFileUtilProxy::ReadDirectory( file_path, callback)); } -// static -bool FileSystemFileUtilProxy::CreateDirectory( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - bool exclusive, - bool recursive, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( - context, file_path, exclusive, recursive, callback)); -} - -// static -bool FileSystemFileUtilProxy::Copy( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayCopy(context, src_file_path, dest_file_path, - callback)); -} - -// static -bool FileSystemFileUtilProxy::Move( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayMove(context, src_file_path, dest_file_path, - callback)); -} - -// static -bool FileSystemFileUtilProxy::Delete( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - bool recursive, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayDelete(context, file_path, recursive, callback)); -} - -// static -bool FileSystemFileUtilProxy::Touch( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayTouchFilePath(context, file_path, last_access_time, - last_modified_time, callback)); -} - -// static -bool FileSystemFileUtilProxy::Truncate( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& path, - int64 length, - const StatusCallback& callback) { - return Start(FROM_HERE, message_loop_proxy, - new RelayTruncate(context, path, length, callback)); -} - } // namespace fileapi diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h index b6a9ada..48ac923 100644 --- a/webkit/fileapi/file_system_file_util_proxy.h +++ b/webkit/fileapi/file_system_file_util_proxy.h @@ -35,7 +35,6 @@ class FileSystemFileUtilProxy { public: typedef base::FileUtilProxy::Entry Entry; - typedef base::FileUtilProxy::StatusCallback StatusCallback; typedef base::Callback<void(PlatformFileError, bool /* created */ )> EnsureFileExistsCallback; @@ -47,10 +46,6 @@ class FileSystemFileUtilProxy { const std::vector<Entry>& )> ReadDirectoryCallback; - typedef Callback2<PlatformFileError /* error code */, - const FilePath& /* local_path, where possible */ - >::Type GetLocalPathCallback; - // Ensures that the given |file_path| exist. This creates a empty new file // at |file_path| if the |file_path| does not exist. // If a new file han not existed and is created at the |file_path|, @@ -66,13 +61,6 @@ class FileSystemFileUtilProxy { const FilePath& file_path, const EnsureFileExistsCallback& callback); - // Maps virtual file patch to its local physical location. - static bool GetLocalPath( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& virtual_path, - GetLocalPathCallback* callback); - // Retrieves the information about a file. It is invalid to pass NULL for the // callback. static bool GetFileInfo( @@ -86,66 +74,6 @@ class FileSystemFileUtilProxy { const FilePath& file_path, const ReadDirectoryCallback& callback); - // Creates directory at given path. It's an error to create - // if |exclusive| is true and dir already exists. - static bool CreateDirectory( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - bool exclusive, - bool recursive, - const StatusCallback& callback); - - // Copies a file or a directory from |src_file_path| to |dest_file_path| - // Error cases: - // If destination file doesn't exist or destination's parent - // doesn't exists. - // If source dir exists but destination path is an existing file. - // If source file exists but destination path is an existing directory. - // If source is a parent of destination. - // If source doesn't exists. - static bool Copy(const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const StatusCallback& callback); - - // Moves a file or a directory from src_file_path to dest_file_path. - // Error cases are similar to Copy method's error cases. - static bool Move( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& src_file_path, - const FilePath& dest_file_path, - const StatusCallback& callback); - - // Deletes a file or a directory. - // It is an error to delete a non-empty directory with recursive=false. - static bool Delete(const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - bool recursive, - const StatusCallback& callback); - - // Touches a file. The callback can be NULL. - static bool Touch( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& file_path, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback); - - // Truncates a file to the given length. If |length| is greater than the - // current length of the file, the file will be extended with zeroes. - // The callback can be NULL. - static bool Truncate( - const FileSystemOperationContext& context, - scoped_refptr<MessageLoopProxy> message_loop_proxy, - const FilePath& path, - int64 length, - const StatusCallback& callback); - private: DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemFileUtilProxy); }; diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index c65aee7..f329cc1 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -63,8 +63,7 @@ FileSystemOperation::FileSystemOperation( FileSystemContext* file_system_context) : proxy_(proxy), dispatcher_(dispatcher), - operation_context_(file_system_context, NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { + operation_context_(file_system_context, NULL) { #ifndef NDEBUG pending_operation_ = kOperationNone; #endif @@ -80,7 +79,7 @@ FileSystemOperation::~FileSystemOperation() { base::Unretained(c->src_file_util()), base::Owned(c)), file_writer_delegate_->file(), - FileSystemFileUtilProxy::StatusCallback()); + base::FileUtilProxy::StatusCallback()); } } @@ -104,7 +103,7 @@ void FileSystemOperation::OpenFileSystem( file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( origin_url, type, create, base::Bind(&FileSystemOperation::DidGetRootPath, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::CreateFile(const GURL& path, @@ -117,15 +116,14 @@ void FileSystemOperation::CreateFile(const GURL& path, delete this; return; } - exclusive_ = exclusive; - GetUsageAndQuotaThenCallback( operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedCreateFileForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this), exclusive)); } void FileSystemOperation::DelayedCreateFileForQuota( + bool exclusive, quota::QuotaStatusCode status, int64 usage, int64 quota) { operation_context_.set_allowed_bytes_growth(quota - usage); @@ -139,9 +137,9 @@ void FileSystemOperation::DelayedCreateFileForQuota( proxy_, src_virtual_path_, base::Bind( - exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive - : &FileSystemOperation::DidEnsureFileExistsNonExclusive, - weak_factory_.GetWeakPtr())); + exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive + : &FileSystemOperation::DidEnsureFileExistsNonExclusive, + base::Owned(this))); } void FileSystemOperation::CreateDirectory(const GURL& path, @@ -155,16 +153,14 @@ void FileSystemOperation::CreateDirectory(const GURL& path, delete this; return; } - exclusive_ = exclusive; - recursive_ = recursive; - GetUsageAndQuotaThenCallback( operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedCreateDirectoryForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this), exclusive, recursive)); } void FileSystemOperation::DelayedCreateDirectoryForQuota( + bool exclusive, bool recursive, quota::QuotaStatusCode status, int64 usage, int64 quota) { operation_context_.set_allowed_bytes_growth(quota - usage); @@ -173,11 +169,14 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota( operation_context_.src_origin_url(), operation_context_.src_type())); - FileSystemFileUtilProxy::CreateDirectory( - operation_context_, proxy_, src_virtual_path_, exclusive_, - recursive_, + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::CreateDirectory, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, exclusive, recursive), base::Bind(&FileSystemOperation::DidFinishFileOperation, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::Copy(const GURL& src_path, @@ -195,7 +194,7 @@ void FileSystemOperation::Copy(const GURL& src_path, GetUsageAndQuotaThenCallback( operation_context_.dest_origin_url(), base::Bind(&FileSystemOperation::DelayedCopyForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this))); } void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, @@ -207,11 +206,14 @@ void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, operation_context_.dest_origin_url(), operation_context_.dest_type())); - FileSystemFileUtilProxy::Copy( - operation_context_, proxy_, src_virtual_path_, - dest_virtual_path_, + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::Copy, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, dest_virtual_path_), base::Bind(&FileSystemOperation::DidFinishFileOperation, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::Move(const GURL& src_path, @@ -229,7 +231,7 @@ void FileSystemOperation::Move(const GURL& src_path, GetUsageAndQuotaThenCallback( operation_context_.dest_origin_url(), base::Bind(&FileSystemOperation::DelayedMoveForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this))); } void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, @@ -241,11 +243,14 @@ void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, operation_context_.dest_origin_url(), operation_context_.dest_type())); - FileSystemFileUtilProxy::Move( - operation_context_, proxy_, src_virtual_path_, - dest_virtual_path_, + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::Move, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, dest_virtual_path_), base::Bind(&FileSystemOperation::DidFinishFileOperation, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::DirectoryExists(const GURL& path) { @@ -260,8 +265,7 @@ void FileSystemOperation::DirectoryExists(const GURL& path) { FileSystemFileUtilProxy::GetFileInfo( operation_context_, proxy_, src_virtual_path_, - base::Bind(&FileSystemOperation::DidDirectoryExists, - weak_factory_.GetWeakPtr())); + base::Bind(&FileSystemOperation::DidDirectoryExists, base::Owned(this))); } void FileSystemOperation::FileExists(const GURL& path) { @@ -276,8 +280,7 @@ void FileSystemOperation::FileExists(const GURL& path) { FileSystemFileUtilProxy::GetFileInfo( operation_context_, proxy_, src_virtual_path_, - base::Bind(&FileSystemOperation::DidFileExists, - weak_factory_.GetWeakPtr())); + base::Bind(&FileSystemOperation::DidFileExists, base::Owned(this))); } void FileSystemOperation::GetMetadata(const GURL& path) { @@ -292,8 +295,7 @@ void FileSystemOperation::GetMetadata(const GURL& path) { FileSystemFileUtilProxy::GetFileInfo( operation_context_, proxy_, src_virtual_path_, - base::Bind(&FileSystemOperation::DidGetMetadata, - weak_factory_.GetWeakPtr())); + base::Bind(&FileSystemOperation::DidGetMetadata, base::Owned(this))); } void FileSystemOperation::ReadDirectory(const GURL& path) { @@ -308,8 +310,7 @@ void FileSystemOperation::ReadDirectory(const GURL& path) { FileSystemFileUtilProxy::ReadDirectory( operation_context_, proxy_, src_virtual_path_, - base::Bind(&FileSystemOperation::DidReadDirectory, - weak_factory_.GetWeakPtr())); + base::Bind(&FileSystemOperation::DidReadDirectory, base::Owned(this))); } void FileSystemOperation::Remove(const GURL& path, bool recursive) { @@ -322,10 +323,14 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) { return; } - FileSystemFileUtilProxy::Delete( - operation_context_, proxy_, src_virtual_path_, recursive, + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::Delete, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, recursive), base::Bind(&FileSystemOperation::DidFinishFileOperation, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::Write( @@ -350,7 +355,7 @@ void FileSystemOperation::Write( GetUsageAndQuotaThenCallback( operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedWriteForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this))); } void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, @@ -370,13 +375,13 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, proxy_, base::Bind(&FileSystemFileUtil::CreateOrOpen, base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_), + &operation_context_, src_virtual_path_, file_flags), base::Bind(&FileSystemFileUtil::Close, base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_)), + &operation_context_), base::Bind(&FileSystemOperation::OnFileOpenedForWrite, - weak_factory_.GetWeakPtr())); + base::Unretained(this))); } void FileSystemOperation::Truncate(const GURL& path, int64 length) { @@ -388,15 +393,14 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) { delete this; return; } - length_ = length; - GetUsageAndQuotaThenCallback( operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedTruncateForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this), length)); } -void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, +void FileSystemOperation::DelayedTruncateForQuota(int64 length, + quota::QuotaStatusCode status, int64 usage, int64 quota) { operation_context_.set_allowed_bytes_growth(quota - usage); @@ -405,10 +409,14 @@ void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, operation_context_.src_origin_url(), operation_context_.src_type())); - FileSystemFileUtilProxy::Truncate( - operation_context_, proxy_, src_virtual_path_, length_, + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::Truncate, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, length), base::Bind(&FileSystemOperation::DidFinishFileOperation, - weak_factory_.GetWeakPtr())); + base::Owned(this))); } void FileSystemOperation::TouchFile(const GURL& path, @@ -423,11 +431,13 @@ void FileSystemOperation::TouchFile(const GURL& path, return; } - FileSystemFileUtilProxy::Touch( - operation_context_, proxy_, src_virtual_path_, - last_access_time, last_modified_time, - base::Bind(&FileSystemOperation::DidTouchFile, - weak_factory_.GetWeakPtr())); + base::FileUtilProxy::RelayFileTask( + proxy_, FROM_HERE, + base::Bind(&FileSystemFileUtil::Touch, + base::Unretained(operation_context_.src_file_util()), + &operation_context_, + src_virtual_path_, last_access_time, last_modified_time), + base::Bind(&FileSystemOperation::DidTouchFile, base::Owned(this))); } void FileSystemOperation::OpenFile(const GURL& path, @@ -461,15 +471,14 @@ void FileSystemOperation::OpenFile(const GURL& path, return; } } - file_flags_ = file_flags; - GetUsageAndQuotaThenCallback( operation_context_.src_origin_url(), base::Bind(&FileSystemOperation::DelayedOpenFileForQuota, - weak_factory_.GetWeakPtr())); + base::Unretained(this), file_flags)); } -void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, +void FileSystemOperation::DelayedOpenFileForQuota(int file_flags, + quota::QuotaStatusCode status, int64 usage, int64 quota) { operation_context_.set_allowed_bytes_growth(quota - usage); @@ -482,13 +491,12 @@ void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, proxy_, base::Bind(&FileSystemFileUtil::CreateOrOpen, base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_), - src_virtual_path_, file_flags_), + &operation_context_, + src_virtual_path_, file_flags), base::Bind(&FileSystemFileUtil::Close, base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_)), - base::Bind(&FileSystemOperation::DidOpenFile, - weak_factory_.GetWeakPtr())); + &operation_context_), + base::Bind(&FileSystemOperation::DidOpenFile, base::Owned(this))); } void FileSystemOperation::SyncGetPlatformPath(const GURL& path, @@ -569,6 +577,8 @@ void FileSystemOperation::DidGetRootPath( const FilePath& path, const std::string& name) { DCHECK(success || path.empty()); GURL result; + if (!dispatcher_.get()) + return; // We ignore the path, and return a URL instead. The point was just to verify // that we could create/find the path. if (success) { @@ -576,9 +586,7 @@ void FileSystemOperation::DidGetRootPath( operation_context_.src_origin_url(), operation_context_.src_type()); } - if (dispatcher_.get()) - dispatcher_->DidOpenFileSystem(name, result); - delete this; + dispatcher_->DidOpenFileSystem(name, result); } void FileSystemOperation::DidEnsureFileExistsExclusive( @@ -586,7 +594,6 @@ void FileSystemOperation::DidEnsureFileExistsExclusive( if (rv == base::PLATFORM_FILE_OK && !created) { if (dispatcher_.get()) dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); - delete this; } else { DidFinishFileOperation(rv); } @@ -613,17 +620,14 @@ void FileSystemOperation::DidFinishFileOperation( else dispatcher_->DidFail(rv); } - delete this; } void FileSystemOperation::DidDirectoryExists( base::PlatformFileError rv, const base::PlatformFileInfo& file_info, const FilePath& unused) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) { if (file_info.is_directory) dispatcher_->DidSucceed(); @@ -632,17 +636,14 @@ void FileSystemOperation::DidDirectoryExists( } else { dispatcher_->DidFail(rv); } - delete this; } void FileSystemOperation::DidFileExists( base::PlatformFileError rv, const base::PlatformFileInfo& file_info, const FilePath& unused) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) { if (file_info.is_directory) dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); @@ -651,37 +652,30 @@ void FileSystemOperation::DidFileExists( } else { dispatcher_->DidFail(rv); } - delete this; } void FileSystemOperation::DidGetMetadata( base::PlatformFileError rv, const base::PlatformFileInfo& file_info, const FilePath& platform_path) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) dispatcher_->DidReadMetadata(file_info, platform_path); else dispatcher_->DidFail(rv); - delete this; } void FileSystemOperation::DidReadDirectory( base::PlatformFileError rv, const std::vector<base::FileUtilProxy::Entry>& entries) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) dispatcher_->DidReadDirectory(entries, false /* has_more */); else dispatcher_->DidFail(rv); - delete this; } void FileSystemOperation::DidWrite( @@ -701,42 +695,33 @@ void FileSystemOperation::DidWrite( } void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) dispatcher_->DidSucceed(); else dispatcher_->DidFail(rv); - delete this; } void FileSystemOperation::DidOpenFile( base::PlatformFileError rv, base::PassPlatformFile file, bool unused) { - if (!dispatcher_.get()) { - delete this; + if (!dispatcher_.get()) return; - } if (rv == base::PLATFORM_FILE_OK) dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); else dispatcher_->DidFail(rv); - delete this; } void FileSystemOperation::OnFileOpenedForWrite( base::PlatformFileError rv, base::PassPlatformFile file, bool created) { - if (!dispatcher_.get()) { - delete this; - return; - } - if (base::PLATFORM_FILE_OK != rv) { - dispatcher_->DidFail(rv); + if (base::PLATFORM_FILE_OK != rv || !dispatcher_.get()) { + if (dispatcher_.get()) + dispatcher_->DidFail(rv); delete this; return; } diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 0846ca6..fdf26fc 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -13,7 +13,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_callback_factory.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" #include "base/message_loop_proxy.h" #include "base/platform_file.h" #include "base/process.h" @@ -45,8 +44,8 @@ class FileSystemQuotaUtil; // Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, // GetMetadata, ReadDirectory and Remove) may be called during the lifetime of // this object and it should be called no more than once. -// This class is self-destructed and an instance automatically gets deleted -// when its operation is finished. +// This class is self-destructed, or get deleted via base::Owned() fater the +// operation finishes and completion callback is called. class FileSystemOperation { public: // |dispatcher| will be owned by this class. @@ -120,9 +119,11 @@ class FileSystemOperation { const GURL& origin_url, const quota::QuotaManager::GetUsageAndQuotaCallback& callback); - void DelayedCreateFileForQuota(quota::QuotaStatusCode status, + void DelayedCreateFileForQuota(bool exclusive, + quota::QuotaStatusCode status, int64 usage, int64 quota); - void DelayedCreateDirectoryForQuota(quota::QuotaStatusCode status, + void DelayedCreateDirectoryForQuota(bool exclusive, bool recursive, + quota::QuotaStatusCode status, int64 usage, int64 quota); void DelayedCopyForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota); @@ -130,9 +131,11 @@ class FileSystemOperation { int64 usage, int64 quota); void DelayedWriteForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota); - void DelayedTruncateForQuota(quota::QuotaStatusCode status, + void DelayedTruncateForQuota(int64 length, + quota::QuotaStatusCode status, int64 usage, int64 quota); - void DelayedOpenFileForQuota(quota::QuotaStatusCode status, + void DelayedOpenFileForQuota(int file_flags, + quota::QuotaStatusCode status, int64 usage, int64 quota); // A callback used for OpenFileSystem. @@ -256,8 +259,6 @@ class FileSystemOperation { FileSystemOperationContext operation_context_; - base::WeakPtrFactory<FileSystemOperation> weak_factory_; - scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_; // These are all used only by Write(). @@ -276,16 +277,6 @@ class FileSystemOperation { FilePath src_virtual_path_; FilePath dest_virtual_path_; - // Options for CreateFile and CreateDirectory. - bool exclusive_; - bool recursive_; - - // Options for OpenFile. - int file_flags_; - - // Length to be truncated. - int64 length_; - DISALLOW_COPY_AND_ASSIGN(FileSystemOperation); }; |