diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 12:14:18 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 12:14:18 +0000 |
commit | e1514f400c33e31b42cd6fc6f6dfbe8dd9970a9a (patch) | |
tree | d174f1597de79c06ef7e6e8d47e0c5948a55bd35 /webkit | |
parent | 510fbf797525f0389fe9ce4fd2f234922960b206 (diff) | |
download | chromium_src-e1514f400c33e31b42cd6fc6f6dfbe8dd9970a9a.zip chromium_src-e1514f400c33e31b42cd6fc6f6dfbe8dd9970a9a.tar.gz chromium_src-e1514f400c33e31b42cd6fc6f6dfbe8dd9970a9a.tar.bz2 |
Revert 108258 - broke Mac LayoutTests.
Merge FileUtilProxy and FileSystemFileUtilProxy using PostTaskAndReply: CreateOrOpen/Close
Deprecating MessageProxyRelay class and getting rid of duplicated code.
BUG=none
TEST=test_shell_tests:\*FileSystem\*
Review URL: http://codereview.chromium.org/8424006
TBR=kinuko@chromium.org
Review URL: http://codereview.chromium.org/8423041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.cc | 83 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.h | 18 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 41 |
3 files changed, 111 insertions, 31 deletions
diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc index 6c54cdc..01af4b9 100644 --- a/webkit/fileapi/file_system_file_util_proxy.cc +++ b/webkit/fileapi/file_system_file_util_proxy.cc @@ -71,6 +71,51 @@ class MessageLoopRelay fileapi::FileSystemFileUtil* file_util_; }; +class RelayCreateOrOpen : public MessageLoopRelay { + public: + RelayCreateOrOpen( + const fileapi::FileSystemOperationContext& context, + scoped_refptr<base::MessageLoopProxy> message_loop_proxy, + const FilePath& file_path, + int file_flags, + const fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback& callback) + : MessageLoopRelay(context), + message_loop_proxy_(message_loop_proxy), + file_path_(file_path), + file_flags_(file_flags), + callback_(callback), + file_handle_(base::kInvalidPlatformFileValue), + created_(false) { + DCHECK_EQ(false, callback.is_null()); + } + + protected: + virtual ~RelayCreateOrOpen() { + if (file_handle_ != base::kInvalidPlatformFileValue) + fileapi::FileSystemFileUtilProxy::Close( + *context(), message_loop_proxy_, file_handle_, + fileapi::FileSystemFileUtilProxy::StatusCallback()); + } + + virtual void RunWork() { + set_error_code(file_util()->CreateOrOpen( + context(), file_path_, file_flags_, &file_handle_, &created_)); + } + + virtual void RunCallback() { + callback_.Run(error_code(), base::PassPlatformFile(&file_handle_), + created_); + } + + private: + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; + FilePath file_path_; + int file_flags_; + fileapi::FileSystemFileUtilProxy::CreateOrOpenCallback callback_; + base::PlatformFile file_handle_; + bool created_; +}; + class RelayWithStatusCallback : public MessageLoopRelay { public: RelayWithStatusCallback( @@ -92,6 +137,24 @@ class RelayWithStatusCallback : public MessageLoopRelay { fileapi::FileSystemFileUtilProxy::StatusCallback callback_; }; +class RelayClose : public RelayWithStatusCallback { + public: + RelayClose(const fileapi::FileSystemOperationContext& context, + base::PlatformFile file_handle, + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) + : RelayWithStatusCallback(context, callback), + file_handle_(file_handle) { + } + + protected: + virtual void RunWork() { + set_error_code(file_util()->Close(context(), file_handle_)); + } + + private: + base::PlatformFile file_handle_; +}; + class RelayEnsureFileExists : public MessageLoopRelay { public: RelayEnsureFileExists( @@ -362,6 +425,26 @@ bool Start(const tracked_objects::Location& from_here, namespace fileapi { // static +bool FileSystemFileUtilProxy::CreateOrOpen( + const FileSystemOperationContext& context, + scoped_refptr<MessageLoopProxy> message_loop_proxy, + const FilePath& file_path, int file_flags, + const CreateOrOpenCallback& callback) { + return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(context, + message_loop_proxy, file_path, file_flags, callback)); +} + +// static +bool FileSystemFileUtilProxy::Close( + const FileSystemOperationContext& context, + scoped_refptr<MessageLoopProxy> message_loop_proxy, + base::PlatformFile file_handle, + const StatusCallback& callback) { + return Start(FROM_HERE, message_loop_proxy, + new RelayClose(context, file_handle, callback)); +} + +// static bool FileSystemFileUtilProxy::EnsureFileExists( const FileSystemOperationContext& context, scoped_refptr<MessageLoopProxy> message_loop_proxy, diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h index b6a9ada..a3e85e5 100644 --- a/webkit/fileapi/file_system_file_util_proxy.h +++ b/webkit/fileapi/file_system_file_util_proxy.h @@ -36,6 +36,7 @@ class FileSystemFileUtilProxy { typedef base::FileUtilProxy::Entry Entry; typedef base::FileUtilProxy::StatusCallback StatusCallback; + typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback; typedef base::Callback<void(PlatformFileError, bool /* created */ )> EnsureFileExistsCallback; @@ -51,6 +52,23 @@ class FileSystemFileUtilProxy { const FilePath& /* local_path, where possible */ >::Type GetLocalPathCallback; + // Creates or opens a file with the given flags. It is invalid to pass NULL + // for the callback. + // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create + // a new file at the given |file_path| and calls back with + // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. + static bool CreateOrOpen(const FileSystemOperationContext& context, + scoped_refptr<MessageLoopProxy> message_loop_proxy, + const FilePath& file_path, + int file_flags, + const CreateOrOpenCallback& callback); + + // Close the given file handle. + static bool Close(const FileSystemOperationContext& context, + scoped_refptr<MessageLoopProxy> message_loop_proxy, + PlatformFile, + const StatusCallback& callback); + // 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|, diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index 84f66eb..7c504a6 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -71,17 +71,10 @@ FileSystemOperation::FileSystemOperation( } FileSystemOperation::~FileSystemOperation() { - if (file_writer_delegate_.get()) { - FileSystemOperationContext* c = - new FileSystemOperationContext(operation_context_); - base::FileUtilProxy::RelayClose( - proxy_, - base::Bind(&FileSystemFileUtil::Close, - base::Unretained(c->src_file_util()), - base::Owned(c)), - file_writer_delegate_->file(), + if (file_writer_delegate_.get()) + FileSystemFileUtilProxy::Close( + operation_context_, proxy_, file_writer_delegate_->file(), FileSystemFileUtilProxy::StatusCallback()); - } } void FileSystemOperation::OpenFileSystem( @@ -373,19 +366,12 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, operation_context_.src_origin_url(), operation_context_.src_type())); - int file_flags = base::PLATFORM_FILE_OPEN | - base::PLATFORM_FILE_WRITE | - base::PLATFORM_FILE_ASYNC; - - base::FileUtilProxy::RelayCreateOrOpen( + FileSystemFileUtilProxy::CreateOrOpen( + operation_context_, proxy_, - base::Bind(&FileSystemFileUtil::CreateOrOpen, - base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_), - src_virtual_path_, file_flags), - base::Bind(&FileSystemFileUtil::Close, - base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_)), + src_virtual_path_, + base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | + base::PLATFORM_FILE_ASYNC, base::Bind(&FileSystemOperation::OnFileOpenedForWrite, weak_factory_.GetWeakPtr())); } @@ -492,15 +478,8 @@ void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, operation_context_.src_origin_url(), operation_context_.src_type())); - base::FileUtilProxy::RelayCreateOrOpen( - proxy_, - base::Bind(&FileSystemFileUtil::CreateOrOpen, - base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_), - src_virtual_path_, file_flags_), - base::Bind(&FileSystemFileUtil::Close, - base::Unretained(operation_context_.src_file_util()), - base::Unretained(&operation_context_)), + FileSystemFileUtilProxy::CreateOrOpen( + operation_context_, proxy_, src_virtual_path_, file_flags_, base::Bind(&FileSystemOperation::DidOpenFile, weak_factory_.GetWeakPtr())); } |