Commit af349561 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Adds callbacks to notify progress into Copy's API.

Copy operation will support progress update. This CL adds the callbacks to
report the progress update.

BUG=278038
TEST=Ran unit_tests

Review URL: https://chromiumcodereview.appspot.com/24030002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222024 0039d316-1c4b-4281-b951-d872f2087c98
parent 6e2569a5
...@@ -229,6 +229,7 @@ fileapi::FileSystemOperationRunner::OperationID StartCopyOnIOThread( ...@@ -229,6 +229,7 @@ fileapi::FileSystemOperationRunner::OperationID StartCopyOnIOThread(
new fileapi::FileSystemOperationRunner::OperationID; new fileapi::FileSystemOperationRunner::OperationID;
*operation_id = file_system_context->operation_runner()->Copy( *operation_id = file_system_context->operation_runner()->Copy(
source_url, dest_url, source_url, dest_url,
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&OnCopyCompleted, base::Bind(&OnCopyCompleted,
profile_id, base::Owned(operation_id), dest_url)); profile_id, base::Owned(operation_id), dest_url));
return *operation_id; return *operation_id;
......
...@@ -305,7 +305,9 @@ TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) { ...@@ -305,7 +305,9 @@ TEST_F(NativeMediaFileUtilTest, CopySourceFiltering) {
expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; expectation = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
} }
operation_runner()->Copy( operation_runner()->Copy(
url, dest_url, base::Bind(&ExpectEqHelper, test_name, expectation)); url, dest_url,
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&ExpectEqHelper, test_name, expectation));
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
} }
} }
...@@ -367,7 +369,9 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) { ...@@ -367,7 +369,9 @@ TEST_F(NativeMediaFileUtilTest, CopyDestFiltering) {
} }
} }
operation_runner()->Copy( operation_runner()->Copy(
src_url, url, base::Bind(&ExpectEqHelper, test_name, expectation)); src_url, url,
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&ExpectEqHelper, test_name, expectation));
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
} }
} }
......
...@@ -554,7 +554,9 @@ void CannedSyncableFileSystem::DoCopy( ...@@ -554,7 +554,9 @@ void CannedSyncableFileSystem::DoCopy(
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const StatusCallback& callback) { const StatusCallback& callback) {
EXPECT_TRUE(is_filesystem_opened_); EXPECT_TRUE(is_filesystem_opened_);
operation_runner()->Copy(src_url, dest_url, callback); operation_runner()->Copy(
src_url, dest_url,
fileapi::FileSystemOperationRunner::CopyProgressCallback(), callback);
} }
void CannedSyncableFileSystem::DoMove( void CannedSyncableFileSystem::DoMove(
......
...@@ -240,6 +240,7 @@ TEST_F(SyncableFileOperationRunnerTest, CopyAndMove) { ...@@ -240,6 +240,7 @@ TEST_F(SyncableFileOperationRunnerTest, CopyAndMove) {
ResetCallbackStatus(); ResetCallbackStatus();
file_system_.operation_runner()->Copy( file_system_.operation_runner()->Copy(
URL(kDir), URL("dest-copy"), URL(kDir), URL("dest-copy"),
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK)); ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK));
file_system_.operation_runner()->Move( file_system_.operation_runner()->Move(
URL(kDir), URL("dest-move"), URL(kDir), URL("dest-move"),
...@@ -260,6 +261,7 @@ TEST_F(SyncableFileOperationRunnerTest, CopyAndMove) { ...@@ -260,6 +261,7 @@ TEST_F(SyncableFileOperationRunnerTest, CopyAndMove) {
ResetCallbackStatus(); ResetCallbackStatus();
file_system_.operation_runner()->Copy( file_system_.operation_runner()->Copy(
URL(kDir), URL("dest-copy2"), URL(kDir), URL("dest-copy2"),
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK)); ExpectStatus(FROM_HERE, base::PLATFORM_FILE_OK));
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(0, callback_count_); EXPECT_EQ(0, callback_count_);
......
...@@ -124,6 +124,7 @@ void SyncableFileSystemOperation::CreateDirectory( ...@@ -124,6 +124,7 @@ void SyncableFileSystemOperation::CreateDirectory(
void SyncableFileSystemOperation::Copy( void SyncableFileSystemOperation::Copy(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (!operation_runner_.get()) { if (!operation_runner_.get()) {
...@@ -137,7 +138,7 @@ void SyncableFileSystemOperation::Copy( ...@@ -137,7 +138,7 @@ void SyncableFileSystemOperation::Copy(
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
base::Bind(&FileSystemOperation::Copy, base::Bind(&FileSystemOperation::Copy,
base::Unretained(impl_.get()), base::Unretained(impl_.get()),
src_url, dest_url, src_url, dest_url, progress_callback,
base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr()))));
operation_runner_->PostOperationTask(task.Pass()); operation_runner_->PostOperationTask(task.Pass());
} }
...@@ -328,9 +329,10 @@ void SyncableFileSystemOperation::RemoveDirectory( ...@@ -328,9 +329,10 @@ void SyncableFileSystemOperation::RemoveDirectory(
void SyncableFileSystemOperation::CopyFileLocal( void SyncableFileSystemOperation::CopyFileLocal(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
impl_->CopyFileLocal(src_url, dest_url, callback); impl_->CopyFileLocal(src_url, dest_url, progress_callback, callback);
} }
void SyncableFileSystemOperation::MoveFileLocal( void SyncableFileSystemOperation::MoveFileLocal(
......
...@@ -42,6 +42,7 @@ class SyncableFileSystemOperation ...@@ -42,6 +42,7 @@ class SyncableFileSystemOperation
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void Copy(const fileapi::FileSystemURL& src_url, virtual void Copy(const fileapi::FileSystemURL& src_url,
const fileapi::FileSystemURL& dest_url, const fileapi::FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void Move(const fileapi::FileSystemURL& src_url, virtual void Move(const fileapi::FileSystemURL& src_url,
const fileapi::FileSystemURL& dest_url, const fileapi::FileSystemURL& dest_url,
...@@ -83,6 +84,7 @@ class SyncableFileSystemOperation ...@@ -83,6 +84,7 @@ class SyncableFileSystemOperation
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void CopyFileLocal(const fileapi::FileSystemURL& src_url, virtual void CopyFileLocal(const fileapi::FileSystemURL& src_url,
const fileapi::FileSystemURL& dest_url, const fileapi::FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void MoveFileLocal(const fileapi::FileSystemURL& src_url, virtual void MoveFileLocal(const fileapi::FileSystemURL& src_url,
const fileapi::FileSystemURL& dest_url, const fileapi::FileSystemURL& dest_url,
......
...@@ -285,6 +285,7 @@ void FileAPIMessageFilter::OnCopy( ...@@ -285,6 +285,7 @@ void FileAPIMessageFilter::OnCopy(
operations_[request_id] = operation_runner()->Copy( operations_[request_id] = operation_runner()->Copy(
src_url, dest_url, src_url, dest_url,
fileapi::FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id));
} }
......
...@@ -97,7 +97,8 @@ base::PlatformFileError AsyncFileTestHelper::Copy( ...@@ -97,7 +97,8 @@ base::PlatformFileError AsyncFileTestHelper::Copy(
base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED;
base::RunLoop run_loop; base::RunLoop run_loop;
context->operation_runner()->Copy( context->operation_runner()->Copy(
src, dest, AssignAndQuitCallback(&run_loop, &result)); src, dest, FileSystemOperationRunner::CopyProgressCallback(),
AssignAndQuitCallback(&run_loop, &result));
run_loop.Run(); run_loop.Run();
return result; return result;
} }
......
...@@ -124,7 +124,10 @@ void CopyOrMoveOperationDelegate::CopyOrMoveFile( ...@@ -124,7 +124,10 @@ void CopyOrMoveOperationDelegate::CopyOrMoveFile(
if (operation_type_ == OPERATION_MOVE) { if (operation_type_ == OPERATION_MOVE) {
operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback);
} else { } else {
operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); // TODO(hidehiko): Support progress callback.
operation_runner()->CopyFileLocal(
url_pair.src, url_pair.dest,
FileSystemOperationRunner::CopyFileProgressCallback(), callback);
} }
return; return;
} }
......
...@@ -122,6 +122,90 @@ class FileSystemOperation { ...@@ -122,6 +122,90 @@ class FileSystemOperation {
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)> const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)>
SnapshotFileCallback; SnapshotFileCallback;
// Used for progress update callback for Copy().
//
// BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both
// file and directory).
// The |source_url| is the URL of the source entry. |size| should not be
// used.
//
// END_COPY_ENTRY is fired for each copy creation finishing (for both
// file and directory).
// The |source_url| is the URL of the source entry. |size| should not be
// used.
//
// PROGRESS is fired periodically during file copying (not fired for
// directory copy).
// The |source_url| is the URL of the source file. |size| is the number
// of cumulative copied bytes for the currently copied file.
// Both at beginning and ending of file copying, PROGRESS event should be
// called. At beginning, |size| should be 0. At ending, |size| should be
// the size of the file.
//
// Here is an example callback sequence of recursive copy. Suppose
// there are a/b/c.txt (100 bytes) and a/b/d.txt (200 bytes), and trying to
// copy a to x recursively, then the progress update sequence will be:
//
// BEGIN_COPY_ENTRY a (starting create "a" directory in x/).
// END_COPY_ENTRY a (creating "a" directory in x/ is finished).
//
// BEGIN_COPY_ENTRY a/b (starting create "b" directory in x/a).
// END_COPY_ENTRY a/b (creating "b" directory in x/a/ is finished).
//
// BEGIN_COPY_ENTRY a/b/c.txt (starting to copy "c.txt" in x/a/b/).
// PROGRESS a/b/c.txt 0 (The first PROGRESS's |size| should be 0).
// PROGRESS a/b/c.txt 10
// :
// PROGRESS a/b/c.txt 90
// PROGRESS a/b/c.txt 100 (The last PROGRESS's |size| should be the size of
// the file).
// END_COPY_ENTRY a/b/c.txt (copying "c.txt" is finished).
//
// BEGIN_COPY_ENTRY a/b/d.txt (starting to copy "d.txt" in x/a/b).
// PROGRESS a/b/d.txt 0 (The first PROGRESS's |size| should be 0).
// PROGRESS a/b/d.txt 10
// :
// PROGRESS a/b/d.txt 190
// PROGRESS a/b/d.txt 200 (The last PROGRESS's |size| should be the size of
// the file).
// END_COPY_ENTRY a/b/d.txt (copy "d.txt" is finished).
//
// Note that event sequence of a/b/c.txt and a/b/d.txt can be interlaced,
// because they can be done in parallel.
// All the progress callback invocation should be done before StatusCallback
// given to the Copy is called. Especially if an error is found before first
// progres callback invocation, the progress callback may NOT invoked for the
// copy.
//
// Note for future extension. Currently this callback is only supported on
// Copy(). We can extend this to Move(), because Move() is sometimes
// implemented as "copy then delete."
// In more precise, Move() usually can be implemented either 1) by updating
// the metadata of resource (e.g. root of moving directory tree), or 2) by
// copying directory tree and them removing the source tree.
// For 1)'s case, we can simply add BEGIN_MOVE_ENTRY and END_MOVE_ENTRY
// for root directory.
// For 2)'s case, we can add BEGIN_DELETE_ENTRY and END_DELETE_ENTRY for each
// entry.
// For both cases, we probably won't need to use PROGRESS event because
// these operations should be done quickly (at least much faster than copying
// usually).
enum CopyProgressType {
BEGIN_COPY_ENTRY,
END_COPY_ENTRY,
PROGRESS,
};
typedef base::Callback<void(
CopyProgressType type, const FileSystemURL& source_url, int64 size)>
CopyProgressCallback;
// Used for CopyFileLocal() to report progress update.
// |size| is the cumulative copied bytes for the copy.
// At the beginning the progress callback should be called with |size| = 0,
// and also at the ending the progress callback should be called with |size|
// set to the copied file size.
typedef base::Callback<void(int64 size)> CopyFileProgressCallback;
// Used for Write(). // Used for Write().
typedef base::Callback<void(base::PlatformFileError result, typedef base::Callback<void(base::PlatformFileError result,
int64 bytes, int64 bytes,
...@@ -146,6 +230,9 @@ class FileSystemOperation { ...@@ -146,6 +230,9 @@ class FileSystemOperation {
// |src_path| is a directory, the contents of |src_path| are copied to // |src_path| is a directory, the contents of |src_path| are copied to
// |dest_path| recursively. A new file or directory is created at // |dest_path| recursively. A new file or directory is created at
// |dest_path| as needed. // |dest_path| as needed.
// |progress_callback| is periodically called to report the progress
// update. See also the comment of CopyProgressCallback. This callback is
// optional.
// //
// For recursive case this internally creates new FileSystemOperations and // For recursive case this internally creates new FileSystemOperations and
// calls: // calls:
...@@ -157,6 +244,7 @@ class FileSystemOperation { ...@@ -157,6 +244,7 @@ class FileSystemOperation {
// //
virtual void Copy(const FileSystemURL& src_path, virtual void Copy(const FileSystemURL& src_path,
const FileSystemURL& dest_path, const FileSystemURL& dest_path,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) = 0; const StatusCallback& callback) = 0;
// Moves a file or directory from |src_path| to |dest_path|. A new file // Moves a file or directory from |src_path| to |dest_path|. A new file
...@@ -302,6 +390,9 @@ class FileSystemOperation { ...@@ -302,6 +390,9 @@ class FileSystemOperation {
// Copies a file from |src_url| to |dest_url|. // Copies a file from |src_url| to |dest_url|.
// This must be called for files that belong to the same filesystem // This must be called for files that belong to the same filesystem
// (i.e. type() and origin() of the |src_url| and |dest_url| must match). // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
// |progress_callback| is periodically called to report the progress
// update. See also the comment of CopyFileProgressCallback. This callback is
// optional.
// //
// This returns: // This returns:
// - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
...@@ -314,6 +405,7 @@ class FileSystemOperation { ...@@ -314,6 +405,7 @@ class FileSystemOperation {
// //
virtual void CopyFileLocal(const FileSystemURL& src_url, virtual void CopyFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) = 0; const StatusCallback& callback) = 0;
// Moves a local file from |src_url| to |dest_url|. // Moves a local file from |src_url| to |dest_url|.
......
...@@ -66,11 +66,15 @@ void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, ...@@ -66,11 +66,15 @@ void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url,
base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
} }
void FileSystemOperationImpl::Copy(const FileSystemURL& src_url, void FileSystemOperationImpl::Copy(
const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy)); DCHECK(SetPendingOperationType(kOperationCopy));
DCHECK(!recursive_operation_delegate_); DCHECK(!recursive_operation_delegate_);
// TODO(hidehiko): Support |progress_callback|. (crbug.com/278038).
recursive_operation_delegate_.reset( recursive_operation_delegate_.reset(
new CopyOrMoveOperationDelegate( new CopyOrMoveOperationDelegate(
file_system_context(), file_system_context(),
...@@ -275,9 +279,12 @@ void FileSystemOperationImpl::RemoveDirectory( ...@@ -275,9 +279,12 @@ void FileSystemOperationImpl::RemoveDirectory(
void FileSystemOperationImpl::CopyFileLocal( void FileSystemOperationImpl::CopyFileLocal(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy)); DCHECK(SetPendingOperationType(kOperationCopy));
DCHECK(src_url.IsInSameFileSystem(dest_url)); DCHECK(src_url.IsInSameFileSystem(dest_url));
// TODO(hidehiko): Support progress_callback.
GetUsageAndQuotaThenRunTask( GetUsageAndQuotaThenRunTask(
dest_url, dest_url,
base::Bind(&FileSystemOperationImpl::DoCopyFileLocal, base::Bind(&FileSystemOperationImpl::DoCopyFileLocal,
......
...@@ -40,6 +40,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationImpl ...@@ -40,6 +40,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationImpl
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void Copy(const FileSystemURL& src_url, virtual void Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void Move(const FileSystemURL& src_url, virtual void Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
...@@ -81,6 +82,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationImpl ...@@ -81,6 +82,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationImpl
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void CopyFileLocal(const FileSystemURL& src_url, virtual void CopyFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) OVERRIDE; const StatusCallback& callback) OVERRIDE;
virtual void MoveFileLocal(const FileSystemURL& src_url, virtual void MoveFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
......
...@@ -444,6 +444,7 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { ...@@ -444,6 +444,7 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) {
TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) {
operation_runner()->Copy(URLForPath("a"), URLForPath("b"), operation_runner()->Copy(URLForPath("a"), URLForPath("b"),
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback()); RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
...@@ -454,7 +455,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { ...@@ -454,7 +455,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) {
FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL src_dir(CreateDirectory("src"));
FileSystemURL dest_dir(CreateDirectory("src/dir")); FileSystemURL dest_dir(CreateDirectory("src/dir"));
operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_dir,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
EXPECT_TRUE(change_observer()->HasNoChange()); EXPECT_TRUE(change_observer()->HasNoChange());
...@@ -466,7 +469,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { ...@@ -466,7 +469,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) {
FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_dir(CreateDirectory("dest"));
FileSystemURL dest_file(CreateFile("dest/file")); FileSystemURL dest_file(CreateFile("dest/file"));
operation_runner()->Copy(src_dir, dest_file, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_file,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
EXPECT_TRUE(change_observer()->HasNoChange()); EXPECT_TRUE(change_observer()->HasNoChange());
...@@ -479,7 +484,9 @@ TEST_F(FileSystemOperationImplTest, ...@@ -479,7 +484,9 @@ TEST_F(FileSystemOperationImplTest,
FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_dir(CreateDirectory("dest"));
FileSystemURL dest_file(CreateFile("dest/file")); FileSystemURL dest_file(CreateFile("dest/file"));
operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_dir,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
EXPECT_TRUE(change_observer()->HasNoChange()); EXPECT_TRUE(change_observer()->HasNoChange());
...@@ -490,7 +497,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { ...@@ -490,7 +497,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) {
FileSystemURL src_file(CreateFile("src")); FileSystemURL src_file(CreateFile("src"));
FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_dir(CreateDirectory("dest"));
operation_runner()->Copy(src_file, dest_dir, RecordStatusCallback()); operation_runner()->Copy(src_file, dest_dir,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
EXPECT_TRUE(change_observer()->HasNoChange()); EXPECT_TRUE(change_observer()->HasNoChange());
...@@ -501,6 +510,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { ...@@ -501,6 +510,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) {
FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL src_dir(CreateDirectory("src"));
operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"),
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback()); RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
...@@ -521,7 +531,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { ...@@ -521,7 +531,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) {
GrantQuotaForCurrentUsage(); GrantQuotaForCurrentUsage();
AddQuota(6 + dest_path_cost - 1); AddQuota(6 + dest_path_cost - 1);
operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); operation_runner()->Copy(src_file, dest_file,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
EXPECT_FALSE(FileExists("dest/file")); EXPECT_FALSE(FileExists("dest/file"));
...@@ -531,7 +543,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { ...@@ -531,7 +543,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) {
FileSystemURL src_file(CreateFile("src")); FileSystemURL src_file(CreateFile("src"));
FileSystemURL dest_file(CreateFile("dest")); FileSystemURL dest_file(CreateFile("dest"));
operation_runner()->Copy(src_file, dest_file, RecordStatusCallback()); operation_runner()->Copy(src_file, dest_file,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_OK, status()); EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(FileExists("dest")); EXPECT_TRUE(FileExists("dest"));
...@@ -545,6 +559,7 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { ...@@ -545,6 +559,7 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) {
FileSystemURL src_file(CreateFile("src")); FileSystemURL src_file(CreateFile("src"));
operation_runner()->Copy(src_file, URLForPath("new"), operation_runner()->Copy(src_file, URLForPath("new"),
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback()); RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_OK, status()); EXPECT_EQ(base::PLATFORM_FILE_OK, status());
...@@ -559,7 +574,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { ...@@ -559,7 +574,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) {
FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL src_dir(CreateDirectory("src"));
FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_dir(CreateDirectory("dest"));
operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_dir,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_OK, status()); EXPECT_EQ(base::PLATFORM_FILE_OK, status());
...@@ -577,7 +594,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { ...@@ -577,7 +594,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) {
FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL src_dir(CreateDirectory("src"));
FileSystemURL dest_dir_new(URLForPath("dest")); FileSystemURL dest_dir_new(URLForPath("dest"));
operation_runner()->Copy(src_dir, dest_dir_new, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_dir_new,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_OK, status()); EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(DirectoryExists("dest")); EXPECT_TRUE(DirectoryExists("dest"));
...@@ -594,7 +613,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { ...@@ -594,7 +613,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) {
FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_dir(CreateDirectory("dest"));
operation_runner()->Copy(src_dir, dest_dir, RecordStatusCallback()); operation_runner()->Copy(src_dir, dest_dir,
FileSystemOperationRunner::CopyProgressCallback(),
RecordStatusCallback());
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(base::PLATFORM_FILE_OK, status()); EXPECT_EQ(base::PLATFORM_FILE_OK, status());
...@@ -1159,6 +1180,7 @@ TEST_F(FileSystemOperationImplTest, ...@@ -1159,6 +1180,7 @@ TEST_F(FileSystemOperationImplTest,
// Copy src to dest1. // Copy src to dest1.
operation_runner()->Copy( operation_runner()->Copy(
src, dest1, src, dest1,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEq, FROM_HERE, base::PLATFORM_FILE_OK)); base::Bind(&AssertFileErrorEq, FROM_HERE, base::PLATFORM_FILE_OK));
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
...@@ -1174,6 +1196,7 @@ TEST_F(FileSystemOperationImplTest, ...@@ -1174,6 +1196,7 @@ TEST_F(FileSystemOperationImplTest,
// Copy src/dir to dest2. // Copy src/dir to dest2.
operation_runner()->Copy( operation_runner()->Copy(
child_dir, dest2, child_dir, dest2,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEq, FROM_HERE, base::PLATFORM_FILE_OK)); base::Bind(&AssertFileErrorEq, FROM_HERE, base::PLATFORM_FILE_OK));
base::MessageLoop::current()->RunUntilIdle(); base::MessageLoop::current()->RunUntilIdle();
......
...@@ -86,6 +86,7 @@ OperationID FileSystemOperationRunner::CreateDirectory( ...@@ -86,6 +86,7 @@ OperationID FileSystemOperationRunner::CreateDirectory(
OperationID FileSystemOperationRunner::Copy( OperationID FileSystemOperationRunner::Copy(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
base::PlatformFileError error = base::PLATFORM_FILE_OK; base::PlatformFileError error = base::PLATFORM_FILE_OK;
FileSystemOperation* operation = FileSystemOperation* operation =
...@@ -99,7 +100,7 @@ OperationID FileSystemOperationRunner::Copy( ...@@ -99,7 +100,7 @@ OperationID FileSystemOperationRunner::Copy(
PrepareForWrite(handle.id, dest_url); PrepareForWrite(handle.id, dest_url);
PrepareForRead(handle.id, src_url); PrepareForRead(handle.id, src_url);
operation->Copy( operation->Copy(
src_url, dest_url, src_url, dest_url, progress_callback,
base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
handle, callback)); handle, callback));
return handle.id; return handle.id;
...@@ -439,6 +440,7 @@ OperationID FileSystemOperationRunner::RemoveDirectory( ...@@ -439,6 +440,7 @@ OperationID FileSystemOperationRunner::RemoveDirectory(
OperationID FileSystemOperationRunner::CopyFileLocal( OperationID FileSystemOperationRunner::CopyFileLocal(
const FileSystemURL& src_url, const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) { const StatusCallback& callback) {
base::PlatformFileError error = base::PLATFORM_FILE_OK; base::PlatformFileError error = base::PLATFORM_FILE_OK;
FileSystemOperation* operation = FileSystemOperation* operation =
...@@ -450,7 +452,7 @@ OperationID FileSystemOperationRunner::CopyFileLocal( ...@@ -450,7 +452,7 @@ OperationID FileSystemOperationRunner::CopyFileLocal(
return handle.id; return handle.id;
} }
operation->CopyFileLocal( operation->CopyFileLocal(
src_url, dest_url, src_url, dest_url, progress_callback,
base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
handle, callback)); handle, callback));
return handle.id; return handle.id;
......
...@@ -41,6 +41,9 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner ...@@ -41,6 +41,9 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner
typedef FileSystemOperation::StatusCallback StatusCallback; typedef FileSystemOperation::StatusCallback StatusCallback;
typedef FileSystemOperation::WriteCallback WriteCallback; typedef FileSystemOperation::WriteCallback WriteCallback;
typedef FileSystemOperation::OpenFileCallback OpenFileCallback; typedef FileSystemOperation::OpenFileCallback OpenFileCallback;
typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback;
typedef FileSystemOperation::CopyFileProgressCallback
CopyFileProgressCallback;
typedef int OperationID; typedef int OperationID;
...@@ -64,8 +67,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner ...@@ -64,8 +67,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner
// |src_url| is a directory, the contents of |src_url| are copied to // |src_url| is a directory, the contents of |src_url| are copied to
// |dest_url| recursively. A new file or directory is created at // |dest_url| recursively. A new file or directory is created at
// |dest_url| as needed. // |dest_url| as needed.
// For |progress_callback|, see file_system_operation.h for details.
OperationID Copy(const FileSystemURL& src_url, OperationID Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyProgressCallback& progress_callback,
const StatusCallback& callback); const StatusCallback& callback);
// Moves a file or directory from |src_url| to |dest_url|. A new file // Moves a file or directory from |src_url| to |dest_url|. A new file
...@@ -183,6 +188,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner ...@@ -183,6 +188,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner
// Copies a file from |src_url| to |dest_url|. // Copies a file from |src_url| to |dest_url|.
// This must be called for files that belong to the same filesystem // This must be called for files that belong to the same filesystem
// (i.e. type() and origin() of the |src_url| and |dest_url| must match). // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
// For |progress_callback|, see file_system_operation.h for details.
// //
// This returns: // This returns:
// - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
...@@ -195,6 +201,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner ...@@ -195,6 +201,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner
// //
OperationID CopyFileLocal(const FileSystemURL& src_url, OperationID CopyFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url, const FileSystemURL& dest_url,
const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback); const StatusCallback& callback);
// Moves a local file from |src_url| to |dest_url|. // Moves a local file from |src_url| to |dest_url|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment