diff options
author | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 11:24:45 +0000 |
---|---|---|
committer | hidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 11:24:45 +0000 |
commit | 9def556baf94bf3ac926299bf53ed10b398ce8c6 (patch) | |
tree | e6c0f22eeda911b22e4fb1bf2c249020488eafb1 /webkit/browser | |
parent | 0ff98da2472ae8651d357e7ba42589195a608cb5 (diff) | |
download | chromium_src-9def556baf94bf3ac926299bf53ed10b398ce8c6.zip chromium_src-9def556baf94bf3ac926299bf53ed10b398ce8c6.tar.gz chromium_src-9def556baf94bf3ac926299bf53ed10b398ce8c6.tar.bz2 |
Adds destinationUrl to onCopyProgress.
To update DirectoryContent on Files.app quickly, Files.app needs to know the
URLs of each created entry, when it is created.
Note that the URL is an alternative object of File System API's Entry,
so it won't be returned until it is actually created. (I.e. it won't be
returned for BEGIN_COPY_ENTRY and PROGRESS events).
BUG=295460
TEST=Ran unit_tests and content_unittests
Review URL: https://chromiumcodereview.appspot.com/24208005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224358 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser')
6 files changed, 61 insertions, 34 deletions
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc index 43470ca..aba17b5 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc @@ -335,8 +335,10 @@ void CopyOrMoveOperationDelegate::RunRecursively() { void CopyOrMoveOperationDelegate::ProcessFile( const FileSystemURL& src_url, const StatusCallback& callback) { - if (!progress_callback_.is_null()) - progress_callback_.Run(FileSystemOperation::BEGIN_COPY_ENTRY, src_url, 0); + if (!progress_callback_.is_null()) { + progress_callback_.Run( + FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); + } FileSystemURL dest_url = CreateDestURL(src_url); CopyOrMoveImpl* impl = NULL; @@ -366,8 +368,9 @@ void CopyOrMoveOperationDelegate::ProcessFile( // Register the running task. running_copy_set_.insert(impl); - impl->Run(base::Bind(&CopyOrMoveOperationDelegate::DidCopyOrMoveFile, - weak_factory_.GetWeakPtr(), src_url, callback, impl)); + impl->Run(base::Bind( + &CopyOrMoveOperationDelegate::DidCopyOrMoveFile, + weak_factory_.GetWeakPtr(), src_url, dest_url, callback, impl)); } void CopyOrMoveOperationDelegate::ProcessDirectory( @@ -386,8 +389,10 @@ void CopyOrMoveOperationDelegate::ProcessDirectory( return; } - if (!progress_callback_.is_null()) - progress_callback_.Run(FileSystemOperation::BEGIN_COPY_ENTRY, src_url, 0); + if (!progress_callback_.is_null()) { + progress_callback_.Run( + FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); + } ProcessDirectoryInternal(src_url, CreateDestURL(src_url), callback); } @@ -412,14 +417,17 @@ void CopyOrMoveOperationDelegate::PostProcessDirectory( void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( const FileSystemURL& src_url, + const FileSystemURL& dest_url, const StatusCallback& callback, CopyOrMoveImpl* impl, base::PlatformFileError error) { running_copy_set_.erase(impl); delete impl; - if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) - progress_callback_.Run(FileSystemOperation::END_COPY_ENTRY, src_url, 0); + if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) { + progress_callback_.Run( + FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); + } callback.Run(error); } @@ -451,15 +459,18 @@ void CopyOrMoveOperationDelegate::ProcessDirectoryInternal( operation_runner()->CreateDirectory( dest_url, false /* exclusive */, false /* recursive */, base::Bind(&CopyOrMoveOperationDelegate::DidCreateDirectory, - weak_factory_.GetWeakPtr(), src_url, callback)); + weak_factory_.GetWeakPtr(), src_url, dest_url, callback)); } void CopyOrMoveOperationDelegate::DidCreateDirectory( const FileSystemURL& src_url, + const FileSystemURL& dest_url, const StatusCallback& callback, base::PlatformFileError error) { - if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) - progress_callback_.Run(FileSystemOperation::END_COPY_ENTRY, src_url, 0); + if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) { + progress_callback_.Run( + FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); + } callback.Run(error); } @@ -474,8 +485,10 @@ void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( void CopyOrMoveOperationDelegate::OnCopyFileProgress( const FileSystemURL& src_url, int64 size) { - if (!progress_callback_.is_null()) - progress_callback_.Run(FileSystemOperation::PROGRESS, src_url, size); + if (!progress_callback_.is_null()) { + progress_callback_.Run( + FileSystemOperation::PROGRESS, src_url, FileSystemURL(), size); + } } FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.h b/webkit/browser/fileapi/copy_or_move_operation_delegate.h index 7b4fb7e..77d1a76 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate.h +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.h @@ -52,6 +52,7 @@ class CopyOrMoveOperationDelegate private: void DidCopyOrMoveFile(const FileSystemURL& src_url, + const FileSystemURL& dest_url, const StatusCallback& callback, CopyOrMoveImpl* impl, base::PlatformFileError error); @@ -61,6 +62,7 @@ class CopyOrMoveOperationDelegate const FileSystemURL& dest_url, const StatusCallback& callback); void DidCreateDirectory(const FileSystemURL& src_url, + const FileSystemURL& dest_url, const StatusCallback& callback, base::PlatformFileError error); void DidRemoveSourceForMove(const StatusCallback& callback, diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc index 64bc5a3..322341d 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate_unittest.cc @@ -96,17 +96,20 @@ class TestValidatorFactory : public CopyOrMoveFileValidatorFactory { // Records CopyProgressCallback invocations. struct ProgressRecord { FileSystemOperation::CopyProgressType type; - FileSystemURL url; + FileSystemURL source_url; + FileSystemURL dest_url; int64 size; }; void RecordProgressCallback(std::vector<ProgressRecord>* records, FileSystemOperation::CopyProgressType type, - const FileSystemURL& url, + const FileSystemURL& source_url, + const FileSystemURL& dest_url, int64 size) { ProgressRecord record; record.type = type; - record.url = url; + record.source_url = source_url; + record.dest_url = dest_url; record.size = size; records->push_back(record); } @@ -614,15 +617,16 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; - FileSystemURL src_url = - helper.SourceURL( - std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe()); + FileSystemURL src_url = helper.SourceURL( + std::string("a/") + base::FilePath(test_case.path).AsUTF8Unsafe()); + FileSystemURL dest_url = helper.DestURL( + std::string("b/") + base::FilePath(test_case.path).AsUTF8Unsafe()); // Find the first and last progress record. size_t begin_index = records.size(); size_t end_index = records.size(); for (size_t j = 0; j < records.size(); ++j) { - if (records[j].url == src_url) { + if (records[j].source_url == src_url) { if (begin_index == records.size()) begin_index = j; end_index = j; @@ -636,7 +640,9 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { EXPECT_EQ(FileSystemOperation::BEGIN_COPY_ENTRY, records[begin_index].type); + EXPECT_FALSE(records[begin_index].dest_url.is_valid()); EXPECT_EQ(FileSystemOperation::END_COPY_ENTRY, records[end_index].type); + EXPECT_EQ(dest_url, records[end_index].dest_url); if (test_case.is_directory) { // For directory copy, the progress shouldn't be interlaced. @@ -645,8 +651,9 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, ProgressCallback) { // PROGRESS event's size should be assending order. int64 current_size = 0; for (size_t j = begin_index + 1; j < end_index; ++j) { - if (records[j].url == src_url) { + if (records[j].source_url == src_url) { EXPECT_EQ(FileSystemOperation::PROGRESS, records[j].type); + EXPECT_FALSE(records[j].dest_url.is_valid()); EXPECT_GE(records[j].size, current_size); current_size = records[j].size; } diff --git a/webkit/browser/fileapi/file_system_operation.h b/webkit/browser/fileapi/file_system_operation.h index 76b5691..99d3b3d 100644 --- a/webkit/browser/fileapi/file_system_operation.h +++ b/webkit/browser/fileapi/file_system_operation.h @@ -131,8 +131,8 @@ class FileSystemOperation { // // 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. + // The |source_url| is the URL of the source entry. The |destination_url| is + // the URL of the destination entry. |size| should not be used. // // PROGRESS is fired periodically during file copying (not fired for // directory copy). @@ -147,10 +147,10 @@ class FileSystemOperation { // 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). + // END_COPY_ENTRY a x/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). + // END_COPY_ENTRY a/b x/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). @@ -159,7 +159,7 @@ class FileSystemOperation { // 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). + // END_COPY_ENTRY a/b/c.txt x/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). @@ -168,7 +168,7 @@ class FileSystemOperation { // 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). + // END_COPY_ENTRY a/b/d.txt x/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. Also PROGRESS events are optional, @@ -196,8 +196,10 @@ class FileSystemOperation { END_COPY_ENTRY, PROGRESS, }; - typedef base::Callback<void( - CopyProgressType type, const FileSystemURL& source_url, int64 size)> + typedef base::Callback<void(CopyProgressType type, + const FileSystemURL& source_url, + const FileSystemURL& destination_url, + int64 size)> CopyProgressCallback; // Used for CopyFileLocal() to report progress update. diff --git a/webkit/browser/fileapi/file_system_operation_runner.cc b/webkit/browser/fileapi/file_system_operation_runner.cc index b10f8ad..5a31ecc 100644 --- a/webkit/browser/fileapi/file_system_operation_runner.cc +++ b/webkit/browser/fileapi/file_system_operation_runner.cc @@ -611,15 +611,17 @@ void FileSystemOperationRunner::OnCopyProgress( const OperationHandle& handle, const CopyProgressCallback& callback, FileSystemOperation::CopyProgressType type, - const FileSystemURL& url, + const FileSystemURL& source_url, + const FileSystemURL& dest_url, int64 size) { if (handle.scope) { base::MessageLoopProxy::current()->PostTask( - FROM_HERE, base::Bind(&FileSystemOperationRunner::OnCopyProgress, - AsWeakPtr(), handle, callback, type, url, size)); + FROM_HERE, base::Bind( + &FileSystemOperationRunner::OnCopyProgress, + AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); return; } - callback.Run(type, url, size); + callback.Run(type, source_url, dest_url, size); } void FileSystemOperationRunner::PrepareForWrite(OperationID id, diff --git a/webkit/browser/fileapi/file_system_operation_runner.h b/webkit/browser/fileapi/file_system_operation_runner.h index f4c4ba9..ea93f38 100644 --- a/webkit/browser/fileapi/file_system_operation_runner.h +++ b/webkit/browser/fileapi/file_system_operation_runner.h @@ -277,7 +277,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner const OperationHandle& handle, const CopyProgressCallback& callback, FileSystemOperation::CopyProgressType type, - const FileSystemURL& url, + const FileSystemURL& source_url, + const FileSystemURL& dest_url, int64 size); void PrepareForWrite(OperationID id, const FileSystemURL& url); |