diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 05:28:57 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 05:28:57 +0000 |
commit | 7a6bd68a12c4c4fb494ee01b6c0f0b7ad42ae32e (patch) | |
tree | 35f8c3f8679118e03bd4839541e33f8887ed6d48 /webkit | |
parent | bcca13f03a7e2895eb4de07e29d4256b04faa67b (diff) | |
download | chromium_src-7a6bd68a12c4c4fb494ee01b6c0f0b7ad42ae32e.zip chromium_src-7a6bd68a12c4c4fb494ee01b6c0f0b7ad42ae32e.tar.gz chromium_src-7a6bd68a12c4c4fb494ee01b6c0f0b7ad42ae32e.tar.bz2 |
Implement RemoteFileSystemOperation::Cancel().
The implementation is almost the exact clone of that in LocalFileSystemOperation.
BUG=132403
Review URL: https://chromiumcodereview.appspot.com/10827412
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/chromeos/fileapi/remote_file_system_operation.cc | 54 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/remote_file_system_operation.h | 6 |
2 files changed, 51 insertions, 9 deletions
diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.cc b/webkit/chromeos/fileapi/remote_file_system_operation.cc index 09c30e2..7f9190b 100644 --- a/webkit/chromeos/fileapi/remote_file_system_operation.cc +++ b/webkit/chromeos/fileapi/remote_file_system_operation.cc @@ -113,13 +113,14 @@ void RemoteFileSystemOperation::Write( int64 offset, const WriteCallback& callback) { DCHECK(SetPendingOperationType(kOperationWrite)); + DCHECK(write_callback_.is_null()); + write_callback_ = callback; file_writer_delegate_.reset( new fileapi::FileWriterDelegate( base::Bind(&RemoteFileSystemOperation::DidWrite, // FileWriterDelegate is owned by |this|. So Unretained. - base::Unretained(this), - callback), + base::Unretained(this)), scoped_ptr<fileapi::FileStreamWriter>( new fileapi::RemoteFileStreamWriter(remote_proxy_, url, @@ -142,8 +143,34 @@ void RemoteFileSystemOperation::Truncate(const FileSystemURL& url, } void RemoteFileSystemOperation::Cancel(const StatusCallback& cancel_callback) { - // TODO(kinaba): crbug.com/132403. implement. - NOTIMPLEMENTED(); + if (file_writer_delegate_.get()) { + DCHECK_EQ(kOperationWrite, pending_operation_); + + // Writes are done without proxying through FileUtilProxy after the initial + // opening of the PlatformFile. All state changes are done on this thread, + // so we're guaranteed to be able to shut down atomically. + const bool delete_now = file_writer_delegate_->Cancel(); + + if (!write_callback_.is_null()) { + // Notify the failure status to the ongoing operation's callback. + write_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT, 0, false); + } + cancel_callback.Run(base::PLATFORM_FILE_OK); + write_callback_.Reset(); + + if (delete_now) { + delete this; + return; + } + } else { + DCHECK_EQ(kOperationTruncate, pending_operation_); + // We're cancelling a truncate operation, but we can't actually stop it + // since it's been proxied to another thread. We need to save the + // cancel_callback so that when the truncate returns, it can see that it's + // been cancelled, report it, and report that the cancel has succeeded. + DCHECK(cancel_callback_.is_null()); + cancel_callback_ = cancel_callback; + } } void RemoteFileSystemOperation::TouchFile(const FileSystemURL& url, @@ -235,11 +262,16 @@ void RemoteFileSystemOperation::DidReadDirectory( } void RemoteFileSystemOperation::DidWrite( - const WriteCallback& callback, base::PlatformFileError rv, int64 bytes, bool complete) { - callback.Run(rv, bytes, complete); + if (write_callback_.is_null()) { + // If cancelled, callback is already invoked and set to null in Cancel(). + // We must not call it twice. Just shut down this operation object. + delete this; + return; + } + write_callback_.Run(rv, bytes, complete); if (rv != base::PLATFORM_FILE_OK || complete) { // Other Did*'s doesn't have "delete this", because it is automatic since // they are base::Owned by the caller of the callback. For DidWrite, the @@ -254,7 +286,15 @@ void RemoteFileSystemOperation::DidWrite( void RemoteFileSystemOperation::DidFinishFileOperation( const StatusCallback& callback, base::PlatformFileError rv) { - callback.Run(rv); + if (!cancel_callback_.is_null()) { + DCHECK_EQ(kOperationTruncate, pending_operation_); + + callback.Run(base::PLATFORM_FILE_ERROR_ABORT); + cancel_callback_.Run(base::PLATFORM_FILE_OK); + cancel_callback_.Reset(); + } else { + callback.Run(rv); + } } void RemoteFileSystemOperation::DidCreateSnapshotFile( diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.h b/webkit/chromeos/fileapi/remote_file_system_operation.h index 2beb830..2ba3611 100644 --- a/webkit/chromeos/fileapi/remote_file_system_operation.h +++ b/webkit/chromeos/fileapi/remote_file_system_operation.h @@ -100,8 +100,7 @@ class RemoteFileSystemOperation : public fileapi::FileSystemOperationInterface { base::PlatformFileError rv, const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more); - void DidWrite(const WriteCallback& callback, - base::PlatformFileError result, + void DidWrite(base::PlatformFileError result, int64 bytes, bool complete); void DidFinishFileOperation(const StatusCallback& callback, @@ -124,6 +123,9 @@ class RemoteFileSystemOperation : public fileapi::FileSystemOperationInterface { OperationType pending_operation_; scoped_ptr<fileapi::FileWriterDelegate> file_writer_delegate_; + WriteCallback write_callback_; + StatusCallback cancel_callback_; + DISALLOW_COPY_AND_ASSIGN(RemoteFileSystemOperation); }; |