| Index: webkit/browser/fileapi/file_system_operation_runner.cc
|
| diff --git a/webkit/browser/fileapi/file_system_operation_runner.cc b/webkit/browser/fileapi/file_system_operation_runner.cc
|
| index b899e1b598058191f6af1942e7aaf4ac732727b6..b1e8aa7327f5f0f08c4c97c8b192669c0f78aa2f 100644
|
| --- a/webkit/browser/fileapi/file_system_operation_runner.cc
|
| +++ b/webkit/browser/fileapi/file_system_operation_runner.cc
|
| @@ -17,8 +17,6 @@ namespace fileapi {
|
|
|
| typedef FileSystemOperationRunner::OperationID OperationID;
|
|
|
| -const OperationID FileSystemOperationRunner::kErrorOperationID = -1;
|
| -
|
| FileSystemOperationRunner::~FileSystemOperationRunner() {
|
| }
|
|
|
| @@ -33,16 +31,16 @@ OperationID FileSystemOperationRunner::CreateFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, url);
|
| + operation->CreateFile(
|
| + url, exclusive,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, url);
|
| - operation->CreateFile(
|
| - url, exclusive,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -54,16 +52,16 @@ OperationID FileSystemOperationRunner::CreateDirectory(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, url);
|
| + operation->CreateDirectory(
|
| + url, exclusive, recursive,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, url);
|
| - operation->CreateDirectory(
|
| - url, exclusive, recursive,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -74,17 +72,17 @@ OperationID FileSystemOperationRunner::Copy(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(dest_url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, dest_url);
|
| + PrepareForRead(id, src_url);
|
| + operation->Copy(
|
| + src_url, dest_url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, dest_url);
|
| - PrepareForRead(id, src_url);
|
| - operation->Copy(
|
| - src_url, dest_url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -95,17 +93,17 @@ OperationID FileSystemOperationRunner::Move(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(dest_url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, dest_url);
|
| + PrepareForWrite(id, src_url);
|
| + operation->Move(
|
| + src_url, dest_url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, dest_url);
|
| - PrepareForWrite(id, src_url);
|
| - operation->Move(
|
| - src_url, dest_url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -115,16 +113,16 @@ OperationID FileSystemOperationRunner::DirectoryExists(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForRead(id, url);
|
| + operation->DirectoryExists(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForRead(id, url);
|
| - operation->DirectoryExists(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -134,16 +132,16 @@ OperationID FileSystemOperationRunner::FileExists(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForRead(id, url);
|
| + operation->FileExists(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForRead(id, url);
|
| - operation->FileExists(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -153,16 +151,16 @@ OperationID FileSystemOperationRunner::GetMetadata(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error, base::PlatformFileInfo());
|
| - return kErrorOperationID;
|
| + DidGetMetadata(id, callback, error, base::PlatformFileInfo());
|
| + } else {
|
| + PrepareForRead(id, url);
|
| + operation->GetMetadata(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidGetMetadata, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForRead(id, url);
|
| - operation->GetMetadata(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidGetMetadata, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -172,16 +170,17 @@ OperationID FileSystemOperationRunner::ReadDirectory(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error, std::vector<DirectoryEntry>(), false);
|
| - return kErrorOperationID;
|
| + DidReadDirectory(
|
| + id, callback, error, std::vector<DirectoryEntry>(), false);
|
| + } else {
|
| + PrepareForRead(id, url);
|
| + operation->ReadDirectory(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForRead(id, url);
|
| - operation->ReadDirectory(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -191,16 +190,16 @@ OperationID FileSystemOperationRunner::Remove(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, url);
|
| + operation->Remove(
|
| + url, recursive,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, url);
|
| - operation->Remove(
|
| - url, recursive,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -213,17 +212,19 @@ OperationID FileSystemOperationRunner::Write(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| +
|
| if (!operation) {
|
| - callback.Run(error, 0, true);
|
| - return kErrorOperationID;
|
| + DidWrite(id, callback, error, 0, true);
|
| + return id;
|
| }
|
|
|
| scoped_ptr<FileStreamWriter> writer(
|
| file_system_context_->CreateFileStreamWriter(url, offset));
|
| if (!writer) {
|
| // Write is not supported.
|
| - callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, true);
|
| - return kErrorOperationID;
|
| + DidWrite(id, callback, base::PLATFORM_FILE_ERROR_SECURITY, 0, true);
|
| + return id;
|
| }
|
|
|
| DCHECK(blob_url.is_valid());
|
| @@ -232,7 +233,6 @@ OperationID FileSystemOperationRunner::Write(
|
| scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest(
|
| blob_url, writer_delegate.get()));
|
|
|
| - OperationID id = operations_.Add(operation);
|
| PrepareForWrite(id, url);
|
| operation->Write(
|
| url, writer_delegate.Pass(), blob_request.Pass(),
|
| @@ -247,16 +247,16 @@ OperationID FileSystemOperationRunner::Truncate(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, url);
|
| + operation->Truncate(
|
| + url, length,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, url);
|
| - operation->Truncate(
|
| - url, length,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -280,16 +280,16 @@ OperationID FileSystemOperationRunner::TouchFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + PrepareForWrite(id, url);
|
| + operation->TouchFile(
|
| + url, last_access_time, last_modified_time,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForWrite(id, url);
|
| - operation->TouchFile(
|
| - url, last_access_time, last_modified_time,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -301,12 +301,12 @@ OperationID FileSystemOperationRunner::OpenFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error, base::kInvalidPlatformFileValue,
|
| - base::Closure(), base::ProcessHandle());
|
| - return kErrorOperationID;
|
| + DidOpenFile(id, callback, error, base::kInvalidPlatformFileValue,
|
| + base::Closure(), base::ProcessHandle());
|
| + return id;
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| if (file_flags &
|
| (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS |
|
| base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED |
|
| @@ -330,16 +330,17 @@ OperationID FileSystemOperationRunner::CreateSnapshotFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error, base::PlatformFileInfo(), base::FilePath(), NULL);
|
| - return kErrorOperationID;
|
| + DidCreateSnapshot(
|
| + id, callback, error, base::PlatformFileInfo(), base::FilePath(), NULL);
|
| + } else {
|
| + PrepareForRead(id, url);
|
| + operation->CreateSnapshotFile(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - PrepareForRead(id, url);
|
| - operation->CreateSnapshotFile(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -350,15 +351,15 @@ OperationID FileSystemOperationRunner::CopyInForeignFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(dest_url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + operation->CopyInForeignFile(
|
| + src_local_disk_path, dest_url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - operation->CopyInForeignFile(
|
| - src_local_disk_path, dest_url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -368,15 +369,15 @@ OperationID FileSystemOperationRunner::RemoveFile(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + operation->RemoveFile(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - operation->RemoveFile(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -386,15 +387,15 @@ OperationID FileSystemOperationRunner::RemoveDirectory(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + operation->RemoveDirectory(
|
| + url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - operation->RemoveDirectory(
|
| - url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -405,15 +406,15 @@ OperationID FileSystemOperationRunner::CopyFileLocal(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(src_url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + operation->CopyFileLocal(
|
| + src_url, dest_url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - operation->CopyFileLocal(
|
| - src_url, dest_url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -424,15 +425,15 @@ OperationID FileSystemOperationRunner::MoveFileLocal(
|
| base::PlatformFileError error = base::PLATFORM_FILE_OK;
|
| FileSystemOperation* operation =
|
| file_system_context_->CreateFileSystemOperation(src_url, &error);
|
| + OperationID id = operations_.Add(operation);
|
| if (!operation) {
|
| - callback.Run(error);
|
| - return kErrorOperationID;
|
| + DidFinish(id, callback, error);
|
| + } else {
|
| + operation->MoveFileLocal(
|
| + src_url, dest_url,
|
| + base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| + id, callback));
|
| }
|
| - OperationID id = operations_.Add(operation);
|
| - operation->MoveFileLocal(
|
| - src_url, dest_url,
|
| - base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
|
| - id, callback));
|
| return id;
|
| }
|
|
|
| @@ -455,7 +456,8 @@ void FileSystemOperationRunner::DidFinish(
|
| OperationID id,
|
| const StatusCallback& callback,
|
| base::PlatformFileError rv) {
|
| - callback.Run(rv);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE, base::Bind(callback, rv));
|
| FinishOperation(id);
|
| }
|
|
|
| @@ -464,7 +466,8 @@ void FileSystemOperationRunner::DidGetMetadata(
|
| const GetMetadataCallback& callback,
|
| base::PlatformFileError rv,
|
| const base::PlatformFileInfo& file_info) {
|
| - callback.Run(rv, file_info);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE, base::Bind(callback, rv, file_info));
|
| FinishOperation(id);
|
| }
|
|
|
| @@ -474,7 +477,8 @@ void FileSystemOperationRunner::DidReadDirectory(
|
| base::PlatformFileError rv,
|
| const std::vector<DirectoryEntry>& entries,
|
| bool has_more) {
|
| - callback.Run(rv, entries, has_more);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE, base::Bind(callback, rv, entries, has_more));
|
| if (rv != base::PLATFORM_FILE_OK || !has_more)
|
| FinishOperation(id);
|
| }
|
| @@ -485,7 +489,8 @@ void FileSystemOperationRunner::DidWrite(
|
| base::PlatformFileError rv,
|
| int64 bytes,
|
| bool complete) {
|
| - callback.Run(rv, bytes, complete);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE, base::Bind(callback, rv, bytes, complete));
|
| if (rv != base::PLATFORM_FILE_OK || complete)
|
| FinishOperation(id);
|
| }
|
| @@ -497,7 +502,9 @@ void FileSystemOperationRunner::DidOpenFile(
|
| base::PlatformFile file,
|
| const base::Closure& on_close_callback,
|
| base::ProcessHandle peer_handle) {
|
| - callback.Run(rv, file, on_close_callback, peer_handle);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(callback, rv, file, on_close_callback, peer_handle));
|
| FinishOperation(id);
|
| }
|
|
|
| @@ -508,7 +515,8 @@ void FileSystemOperationRunner::DidCreateSnapshot(
|
| const base::PlatformFileInfo& file_info,
|
| const base::FilePath& platform_path,
|
| const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
|
| - callback.Run(rv, file_info, platform_path, file_ref);
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE, base::Bind(callback, rv, file_info, platform_path, file_ref));
|
| FinishOperation(id);
|
| }
|
|
|
|
|