diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 08:37:40 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 08:37:40 +0000 |
commit | 24601d60fbb95453389e2aa17f41f05104f83d27 (patch) | |
tree | 1b5b55d3da377af5390288f931006fc9b4b5cf5a /webkit | |
parent | 1841da3770e3318afa3ffb98c3a71607a9100427 (diff) | |
download | chromium_src-24601d60fbb95453389e2aa17f41f05104f83d27.zip chromium_src-24601d60fbb95453389e2aa17f41f05104f83d27.tar.gz chromium_src-24601d60fbb95453389e2aa17f41f05104f83d27.tar.bz2 |
Implement SyncableFileSystemOperation::CopyInForeignFile
The private developer API that writes/reads data to/from SyncFS
via FileSystemOperation layer may directly call
this method, and therefore this operation should also cooperate with
other SyncFS operation scheduling.
BUG=none
TEST=SyncableFileSystemOperationRunner.CopyInForeignFile
Review URL: https://codereview.chromium.org/13910013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
4 files changed, 76 insertions, 3 deletions
diff --git a/webkit/fileapi/local_file_system_operation.h b/webkit/fileapi/local_file_system_operation.h index 1bfa32e..ecae201 100644 --- a/webkit/fileapi/local_file_system_operation.h +++ b/webkit/fileapi/local_file_system_operation.h @@ -97,9 +97,9 @@ class WEBKIT_STORAGE_EXPORT LocalFileSystemOperation // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and // its parent path is a file. // - void CopyInForeignFile(const base::FilePath& src_local_disk_path, - const FileSystemURL& dest_url, - const StatusCallback& callback); + virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, + const FileSystemURL& dest_url, + const StatusCallback& callback); // Removes a single file. // diff --git a/webkit/fileapi/syncable/syncable_file_operation_runner_unittest.cc b/webkit/fileapi/syncable/syncable_file_operation_runner_unittest.cc index 284943a..09dfab8 100644 --- a/webkit/fileapi/syncable/syncable_file_operation_runner_unittest.cc +++ b/webkit/fileapi/syncable/syncable_file_operation_runner_unittest.cc @@ -5,6 +5,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_util.h" #include "base/location.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" @@ -55,6 +56,7 @@ class SyncableFileOperationRunnerTest : public testing::Test { weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} virtual void SetUp() OVERRIDE { + ASSERT_TRUE(dir_.CreateUniqueTempDir()); file_system_.SetUp(); sync_context_ = new LocalFileSyncContext(base::MessageLoopProxy::current(), base::MessageLoopProxy::current()); @@ -119,6 +121,12 @@ class SyncableFileOperationRunnerTest : public testing::Test { ++callback_count_; } + bool CreateTempFile(base::FilePath* path) { + return file_util::CreateTemporaryFileInDir(dir_.path(), path); + } + + base::ScopedTempDir dir_; + MessageLoop message_loop_; CannedSyncableFileSystem file_system_; scoped_refptr<LocalFileSyncContext> sync_context_; @@ -321,4 +329,43 @@ TEST_F(SyncableFileOperationRunnerTest, QueueAndCancel) { EXPECT_EQ(2, callback_count_); } +// Test if CopyInForeignFile runs cooperatively with other Sync operations +// when it is called directly via AsLocalFileSystemOperation. +TEST_F(SyncableFileOperationRunnerTest, CopyInForeignFile) { + const std::string kTestData("test data"); + + base::FilePath temp_path; + ASSERT_TRUE(CreateTempFile(&temp_path)); + ASSERT_EQ(static_cast<int>(kTestData.size()), + file_util::WriteFile( + temp_path, kTestData.data(), kTestData.size())); + + sync_status()->StartSyncing(URL(kFile)); + ASSERT_FALSE(sync_status()->IsWritable(URL(kFile))); + + // The URL is in syncing so CopyIn (which is a write operation) won't run. + ResetCallbackStatus(); + file_system_.NewOperation()->AsLocalFileSystemOperation()->CopyInForeignFile( + temp_path, URL(kFile), + ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK)); + MessageLoop::current()->RunUntilIdle(); + EXPECT_EQ(0, callback_count_); + + // End syncing (to enable write). + sync_status()->EndSyncing(URL(kFile)); + ASSERT_TRUE(sync_status()->IsWritable(URL(kFile))); + + ResetCallbackStatus(); + MessageLoop::current()->RunUntilIdle(); + EXPECT_EQ(1, callback_count_); + + // Now the file must have been created and have the same content as temp_path. + ResetCallbackStatus(); + file_system_.DoVerifyFile( + URL(kFile), kTestData, + ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK)); + MessageLoop::current()->RunUntilIdle(); + EXPECT_EQ(1, callback_count_); +} + } // namespace sync_file_system diff --git a/webkit/fileapi/syncable/syncable_file_system_operation.cc b/webkit/fileapi/syncable/syncable_file_system_operation.cc index eae8091..348aad9 100644 --- a/webkit/fileapi/syncable/syncable_file_system_operation.cc +++ b/webkit/fileapi/syncable/syncable_file_system_operation.cc @@ -327,6 +327,27 @@ void SyncableFileSystemOperation::CreateSnapshotFile( delete this; } +void SyncableFileSystemOperation::CopyInForeignFile( + const base::FilePath& src_local_disk_path, + const FileSystemURL& dest_url, + const StatusCallback& callback) { + DCHECK(CalledOnValidThread()); + if (!operation_runner_) { + AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); + return; + } + DCHECK(operation_runner_.get()); + target_paths_.push_back(dest_url); + completion_callback_ = callback; + scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( + this, + base::Bind(&LocalFileSystemOperation::CopyInForeignFile, + base::Unretained(NewOperation()), + src_local_disk_path, dest_url, + base::Bind(&self::DidFinish, base::Owned(this))))); + operation_runner_->PostOperationTask(task.Pass()); +} + SyncableFileSystemOperation::SyncableFileSystemOperation( fileapi::FileSystemContext* file_system_context, scoped_ptr<FileSystemOperationContext> operation_context) diff --git a/webkit/fileapi/syncable/syncable_file_system_operation.h b/webkit/fileapi/syncable/syncable_file_system_operation.h index 537c61e..2f07b39 100644 --- a/webkit/fileapi/syncable/syncable_file_system_operation.h +++ b/webkit/fileapi/syncable/syncable_file_system_operation.h @@ -77,6 +77,11 @@ class WEBKIT_STORAGE_EXPORT SyncableFileSystemOperation const fileapi::FileSystemURL& path, const SnapshotFileCallback& callback) OVERRIDE; + // LocalFileSystemOperation overrides. + virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, + const fileapi::FileSystemURL& dest_url, + const StatusCallback& callback) OVERRIDE; + private: typedef SyncableFileSystemOperation self; class QueueableTask; |