summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 06:49:56 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 06:49:56 +0000
commitd9543896f8112191cc1e7cd56c0f53e768710940 (patch)
tree8e420b56a9283b3ba4bacf000d70824dc58fa4f6 /webkit/fileapi
parentec8e6cf2037c07e8af073245cfb030857a0a616c (diff)
downloadchromium_src-d9543896f8112191cc1e7cd56c0f53e768710940.zip
chromium_src-d9543896f8112191cc1e7cd56c0f53e768710940.tar.gz
chromium_src-d9543896f8112191cc1e7cd56c0f53e768710940.tar.bz2
Make LocalFileSystemOperation::Write queueable
Split Write into two: GetWriteClosure and closure.Run(); Also making CopyInForeignFile non-virtual (as it's not a override) BUG=148897 TEST=existing tests Review URL: https://chromiumcodereview.appspot.com/11087054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/local_file_system_operation.cc126
-rw-r--r--webkit/fileapi/local_file_system_operation.h20
2 files changed, 88 insertions, 58 deletions
diff --git a/webkit/fileapi/local_file_system_operation.cc b/webkit/fileapi/local_file_system_operation.cc
index e9048f1..3d9498b 100644
--- a/webkit/fileapi/local_file_system_operation.cc
+++ b/webkit/fileapi/local_file_system_operation.cc
@@ -137,28 +137,6 @@ void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
}
-void LocalFileSystemOperation::CopyInForeignFile(
- const FilePath& src_local_disk_file_path,
- const FileSystemURL& dest_url,
- const StatusCallback& callback) {
- DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
-
- base::PlatformFileError result = SetUp(
- dest_url, &dest_util_, SETUP_FOR_CREATE);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result);
- delete this;
- return;
- }
-
- GetUsageAndQuotaThenRunTask(
- dest_url,
- base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile,
- base::Unretained(this), src_local_disk_file_path, dest_url,
- callback),
- base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
-}
-
void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
@@ -288,39 +266,7 @@ void LocalFileSystemOperation::Write(
const GURL& blob_url,
int64 offset,
const WriteCallback& callback) {
- DCHECK(SetPendingOperationType(kOperationWrite));
-
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
- if (result != base::PLATFORM_FILE_OK) {
- callback.Run(result, 0, false);
- delete this;
- return;
- }
-
- FileSystemMountPointProvider* provider = file_system_context()->
- GetMountPointProvider(url.type());
- DCHECK(provider);
- scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter(
- url, offset, file_system_context()));
-
- if (!writer.get()) {
- // Write is not supported.
- callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, false);
- delete this;
- return;
- }
-
- DCHECK(blob_url.is_valid());
- file_writer_delegate_.reset(new FileWriterDelegate(
- base::Bind(&LocalFileSystemOperation::DidWrite,
- weak_factory_.GetWeakPtr(), url),
- writer.Pass()));
-
- set_write_callback(callback);
- scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest(
- blob_url, file_writer_delegate_.get()));
-
- file_writer_delegate_->Start(blob_request.Pass());
+ GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run();
}
void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
@@ -481,6 +427,28 @@ void LocalFileSystemOperation::CreateSnapshotFile(
base::Owned(this), callback));
}
+void LocalFileSystemOperation::CopyInForeignFile(
+ const FilePath& src_local_disk_file_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
+
+ base::PlatformFileError result = SetUp(
+ dest_url, &dest_util_, SETUP_FOR_CREATE);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
+ delete this;
+ return;
+ }
+
+ GetUsageAndQuotaThenRunTask(
+ dest_url,
+ base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile,
+ base::Unretained(this), src_local_disk_file_path, dest_url,
+ callback),
+ base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
+}
+
LocalFileSystemOperation::LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context)
@@ -532,6 +500,54 @@ void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask(
task.Run();
}
+base::Closure LocalFileSystemOperation::GetWriteClosure(
+ const net::URLRequestContext* url_request_context,
+ const FileSystemURL& url,
+ const GURL& blob_url,
+ int64 offset,
+ const WriteCallback& callback) {
+ DCHECK(SetPendingOperationType(kOperationWrite));
+
+ base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ if (result != base::PLATFORM_FILE_OK) {
+ return base::Bind(&LocalFileSystemOperation::DidFailWrite,
+ base::Owned(this), callback, result);
+ }
+
+ FileSystemMountPointProvider* provider = file_system_context()->
+ GetMountPointProvider(url.type());
+ DCHECK(provider);
+ scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter(
+ url, offset, file_system_context()));
+
+ if (!writer.get()) {
+ // Write is not supported.
+ return base::Bind(&LocalFileSystemOperation::DidFailWrite,
+ base::Owned(this), callback,
+ base::PLATFORM_FILE_ERROR_SECURITY);
+ }
+
+ DCHECK(blob_url.is_valid());
+ file_writer_delegate_.reset(new FileWriterDelegate(
+ base::Bind(&LocalFileSystemOperation::DidWrite,
+ weak_factory_.GetWeakPtr(), url),
+ writer.Pass()));
+
+ set_write_callback(callback);
+ scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest(
+ blob_url, file_writer_delegate_.get()));
+
+ return base::Bind(&FileWriterDelegate::Start,
+ base::Unretained(file_writer_delegate_.get()),
+ base::Passed(&blob_request));
+}
+
+void LocalFileSystemOperation::DidFailWrite(
+ const WriteCallback& callback,
+ base::PlatformFileError result) {
+ callback.Run(result, 0, false);
+}
+
void LocalFileSystemOperation::DoCreateFile(
const FileSystemURL& url,
const StatusCallback& callback,
diff --git a/webkit/fileapi/local_file_system_operation.h b/webkit/fileapi/local_file_system_operation.h
index f33f3a1..804e240 100644
--- a/webkit/fileapi/local_file_system_operation.h
+++ b/webkit/fileapi/local_file_system_operation.h
@@ -43,9 +43,6 @@ class FILEAPI_EXPORT LocalFileSystemOperation
virtual void Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) OVERRIDE;
- virtual void CopyInForeignFile(const FilePath& src_local_disk_path,
- const FileSystemURL& dest_url,
- const StatusCallback& callback);
virtual void Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) OVERRIDE;
@@ -81,6 +78,10 @@ class FILEAPI_EXPORT LocalFileSystemOperation
const FileSystemURL& path,
const SnapshotFileCallback& callback) OVERRIDE;
+ void CopyInForeignFile(const FilePath& src_local_disk_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback);
+
// Synchronously gets the platform path for the given |url|.
void SyncGetPlatformPath(const FileSystemURL& url, FilePath* platform_path);
@@ -107,6 +108,8 @@ class FILEAPI_EXPORT LocalFileSystemOperation
friend class FileSystemQuotaTest;
friend class LocalFileSystemTestOriginHelper;
+ friend class SyncableFileSystemOperation;
+
LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context);
@@ -145,6 +148,17 @@ class FILEAPI_EXPORT LocalFileSystemOperation
quota::QuotaStatusCode status,
int64 usage, int64 quota);
+ // returns a closure which actually perform the write operation.
+ base::Closure GetWriteClosure(
+ const net::URLRequestContext* url_request_context,
+ const FileSystemURL& url,
+ const GURL& blob_url,
+ int64 offset,
+ const WriteCallback& callback);
+ void DidFailWrite(
+ const WriteCallback& callback,
+ base::PlatformFileError result);
+
// The 'body' methods that perform the actual work (i.e. posting the
// file task on proxy_) after the quota check.
void DoCreateFile(const FileSystemURL& url,