diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 21:33:35 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 21:33:35 +0000 |
commit | aa0b33eda7f49c544a973b5acd8f9f0611d7e765 (patch) | |
tree | 98a598e8732046d497b3795287dc8d2dd389577f /webkit/fileapi | |
parent | 28f3c9251dace27b202d71203756fecbbe3cbc15 (diff) | |
download | chromium_src-aa0b33eda7f49c544a973b5acd8f9f0611d7e765.zip chromium_src-aa0b33eda7f49c544a973b5acd8f9f0611d7e765.tar.gz chromium_src-aa0b33eda7f49c544a973b5acd8f9f0611d7e765.tar.bz2 |
base::Bind: Convert FileUtilProxy::StatusCallback.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8318025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.cc | 59 | ||||
-rw-r--r-- | webkit/fileapi/file_system_file_util_proxy.h | 14 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 45 |
3 files changed, 57 insertions, 61 deletions
diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc index 40b5980..ad3e14c 100644 --- a/webkit/fileapi/file_system_file_util_proxy.cc +++ b/webkit/fileapi/file_system_file_util_proxy.cc @@ -93,8 +93,9 @@ class RelayCreateOrOpen : public MessageLoopRelay { protected: virtual ~RelayCreateOrOpen() { if (file_handle_ != base::kInvalidPlatformFileValue) - fileapi::FileSystemFileUtilProxy::Close(*context(), - message_loop_proxy_, file_handle_, NULL); + fileapi::FileSystemFileUtilProxy::Close( + *context(), message_loop_proxy_, file_handle_, + fileapi::FileSystemFileUtilProxy::StatusCallback()); } virtual void RunWork() { @@ -120,7 +121,7 @@ class RelayWithStatusCallback : public MessageLoopRelay { public: RelayWithStatusCallback( const fileapi::FileSystemOperationContext& context, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : MessageLoopRelay(context), callback_(callback) { // It is OK for callback to be NULL. @@ -129,21 +130,19 @@ class RelayWithStatusCallback : public MessageLoopRelay { protected: virtual void RunCallback() { // The caller may not have been interested in the result. - if (callback_) { - callback_->Run(error_code()); - delete callback_; - } + if (!callback_.is_null()) + callback_.Run(error_code()); } private: - fileapi::FileSystemFileUtilProxy::StatusCallback* callback_; + fileapi::FileSystemFileUtilProxy::StatusCallback callback_; }; class RelayClose : public RelayWithStatusCallback { public: RelayClose(const fileapi::FileSystemOperationContext& context, base::PlatformFile file_handle, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : RelayWithStatusCallback(context, callback), file_handle_(file_handle) { } @@ -283,7 +282,7 @@ class RelayCreateDirectory : public RelayWithStatusCallback { const FilePath& file_path, bool exclusive, bool recursive, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : RelayWithStatusCallback(context, callback), file_path_(file_path), exclusive_(exclusive), @@ -307,7 +306,7 @@ class RelayCopy : public RelayWithStatusCallback { RelayCopy(const fileapi::FileSystemOperationContext& context, const FilePath& src_file_path, const FilePath& dest_file_path, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : RelayWithStatusCallback(context, callback), src_file_path_(src_file_path), dest_file_path_(dest_file_path) { @@ -329,7 +328,7 @@ class RelayMove : public RelayWithStatusCallback { RelayMove(const fileapi::FileSystemOperationContext& context, const FilePath& src_file_path, const FilePath& dest_file_path, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : RelayWithStatusCallback(context, callback), src_file_path_(src_file_path), dest_file_path_(dest_file_path) { @@ -351,7 +350,7 @@ class RelayDelete : public RelayWithStatusCallback { RelayDelete(const fileapi::FileSystemOperationContext& context, const FilePath& file_path, bool recursive, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + const fileapi::FileSystemFileUtilProxy::StatusCallback& callback) : RelayWithStatusCallback(context, callback), file_path_(file_path), recursive_(recursive) { @@ -369,11 +368,12 @@ class RelayDelete : public RelayWithStatusCallback { 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, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + 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), @@ -394,10 +394,11 @@ class RelayTouchFilePath : public RelayWithStatusCallback { class RelayTruncate : public RelayWithStatusCallback { public: - RelayTruncate(const fileapi::FileSystemOperationContext& context, - const FilePath& file_path, - int64 length, - fileapi::FileSystemFileUtilProxy::StatusCallback* callback) + 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) { @@ -438,7 +439,7 @@ bool FileSystemFileUtilProxy::Close( const FileSystemOperationContext& context, scoped_refptr<MessageLoopProxy> message_loop_proxy, base::PlatformFile file_handle, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayClose(context, file_handle, callback)); } @@ -490,7 +491,7 @@ bool FileSystemFileUtilProxy::CreateDirectory( const FilePath& file_path, bool exclusive, bool recursive, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( context, file_path, exclusive, recursive, callback)); } @@ -501,7 +502,7 @@ bool FileSystemFileUtilProxy::Copy( scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& src_file_path, const FilePath& dest_file_path, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayCopy(context, src_file_path, dest_file_path, callback)); @@ -513,7 +514,7 @@ bool FileSystemFileUtilProxy::Move( scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& src_file_path, const FilePath& dest_file_path, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayMove(context, src_file_path, dest_file_path, callback)); @@ -525,7 +526,7 @@ bool FileSystemFileUtilProxy::Delete( scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& file_path, bool recursive, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayDelete(context, file_path, recursive, callback)); } @@ -537,7 +538,7 @@ bool FileSystemFileUtilProxy::Touch( const FilePath& file_path, const base::Time& last_access_time, const base::Time& last_modified_time, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayTouchFilePath(context, file_path, last_access_time, last_modified_time, callback)); @@ -549,7 +550,7 @@ bool FileSystemFileUtilProxy::Truncate( scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& path, int64 length, - StatusCallback* callback) { + const StatusCallback& callback) { return Start(FROM_HERE, message_loop_proxy, new RelayTruncate(context, path, length, callback)); } diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h index 099d6d3..8fdf03b 100644 --- a/webkit/fileapi/file_system_file_util_proxy.h +++ b/webkit/fileapi/file_system_file_util_proxy.h @@ -62,7 +62,7 @@ class FileSystemFileUtilProxy { static bool Close(const FileSystemOperationContext& context, scoped_refptr<MessageLoopProxy> message_loop_proxy, PlatformFile, - StatusCallback* callback); + 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. @@ -107,7 +107,7 @@ class FileSystemFileUtilProxy { const FilePath& file_path, bool exclusive, bool recursive, - StatusCallback* callback); + const StatusCallback& callback); // Copies a file or a directory from |src_file_path| to |dest_file_path| // Error cases: @@ -121,7 +121,7 @@ class FileSystemFileUtilProxy { scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& src_file_path, const FilePath& dest_file_path, - StatusCallback* callback); + 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. @@ -130,7 +130,7 @@ class FileSystemFileUtilProxy { scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& src_file_path, const FilePath& dest_file_path, - StatusCallback* callback); + const StatusCallback& callback); // Deletes a file or a directory. // It is an error to delete a non-empty directory with recursive=false. @@ -138,7 +138,7 @@ class FileSystemFileUtilProxy { scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& file_path, bool recursive, - StatusCallback* callback); + const StatusCallback& callback); // Touches a file. The callback can be NULL. static bool Touch( @@ -147,7 +147,7 @@ class FileSystemFileUtilProxy { const FilePath& file_path, const base::Time& last_access_time, const base::Time& last_modified_time, - StatusCallback* callback); + 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. @@ -157,7 +157,7 @@ class FileSystemFileUtilProxy { scoped_refptr<MessageLoopProxy> message_loop_proxy, const FilePath& path, int64 length, - StatusCallback* callback); + 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 8ccc52d..b89fda2 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -76,8 +76,8 @@ FileSystemOperation::FileSystemOperation( FileSystemOperation::~FileSystemOperation() { if (file_writer_delegate_.get()) FileSystemFileUtilProxy::Close( - file_system_operation_context_, - proxy_, file_writer_delegate_->file(), NULL); + file_system_operation_context_, proxy_, file_writer_delegate_->file(), + FileSystemFileUtilProxy::StatusCallback()); } void FileSystemOperation::OpenFileSystem( @@ -184,8 +184,8 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota( FileSystemFileUtilProxy::CreateDirectory( file_system_operation_context_, proxy_, src_virtual_path_, exclusive_, recursive_, - callback_factory_.NewCallback( - &FileSystemOperation::DidFinishFileOperation)); + base::Bind(&FileSystemOperation::DidFinishFileOperation, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::Copy(const GURL& src_path, @@ -231,12 +231,10 @@ void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, file_system_operation_context_.dest_type())); FileSystemFileUtilProxy::Copy( - file_system_operation_context_, - proxy_, - src_virtual_path_, + file_system_operation_context_, proxy_, src_virtual_path_, dest_virtual_path_, - callback_factory_.NewCallback( - &FileSystemOperation::DidFinishFileOperation)); + base::Bind(&FileSystemOperation::DidFinishFileOperation, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::Move(const GURL& src_path, @@ -282,12 +280,10 @@ void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, file_system_operation_context_.dest_type())); FileSystemFileUtilProxy::Move( - file_system_operation_context_, - proxy_, - src_virtual_path_, + file_system_operation_context_, proxy_, src_virtual_path_, dest_virtual_path_, - callback_factory_.NewCallback( - &FileSystemOperation::DidFinishFileOperation)); + base::Bind(&FileSystemOperation::DidFinishFileOperation, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::DirectoryExists(const GURL& path) { @@ -410,9 +406,9 @@ void FileSystemOperation::Remove(const GURL& path, bool recursive) { if (!file_system_operation_context_.src_file_util()) file_system_operation_context_.set_src_file_util(file_util); FileSystemFileUtilProxy::Delete( - file_system_operation_context_, - proxy_, virtual_path, recursive, callback_factory_.NewCallback( - &FileSystemOperation::DidFinishFileOperation)); + file_system_operation_context_, proxy_, virtual_path, recursive, + base::Bind(&FileSystemOperation::DidFinishFileOperation, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::Write( @@ -498,11 +494,9 @@ void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, file_system_operation_context_.src_type())); FileSystemFileUtilProxy::Truncate( - file_system_operation_context_, - proxy_, - src_virtual_path_, - length_, callback_factory_.NewCallback( - &FileSystemOperation::DidFinishFileOperation)); + file_system_operation_context_, proxy_, src_virtual_path_, length_, + base::Bind(&FileSystemOperation::DidFinishFileOperation, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::TouchFile(const GURL& path, @@ -527,9 +521,10 @@ void FileSystemOperation::TouchFile(const GURL& path, if (!file_system_operation_context_.src_file_util()) file_system_operation_context_.set_src_file_util(file_util); FileSystemFileUtilProxy::Touch( - file_system_operation_context_, - proxy_, virtual_path, last_access_time, last_modified_time, - callback_factory_.NewCallback(&FileSystemOperation::DidTouchFile)); + file_system_operation_context_, proxy_, virtual_path, last_access_time, + last_modified_time, + base::Bind(&FileSystemOperation::DidTouchFile, + weak_factory_.GetWeakPtr())); } void FileSystemOperation::OpenFile(const GURL& path, |