summaryrefslogtreecommitdiffstats
path: root/webkit/browser/fileapi/file_system_operation.h
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-09 14:18:53 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-09 14:18:53 +0000
commitaf3495612a53ae01ad3cea9d1f4e3f3f727c6cf5 (patch)
tree284ced35e987fd832253cdd913f1770d03d75222 /webkit/browser/fileapi/file_system_operation.h
parent6e2569a515137c65ebc96bc993c93f4fed0004d6 (diff)
downloadchromium_src-af3495612a53ae01ad3cea9d1f4e3f3f727c6cf5.zip
chromium_src-af3495612a53ae01ad3cea9d1f4e3f3f727c6cf5.tar.gz
chromium_src-af3495612a53ae01ad3cea9d1f4e3f3f727c6cf5.tar.bz2
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
Diffstat (limited to 'webkit/browser/fileapi/file_system_operation.h')
-rw-r--r--webkit/browser/fileapi/file_system_operation.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/webkit/browser/fileapi/file_system_operation.h b/webkit/browser/fileapi/file_system_operation.h
index 6782269..151c3a2 100644
--- a/webkit/browser/fileapi/file_system_operation.h
+++ b/webkit/browser/fileapi/file_system_operation.h
@@ -122,6 +122,90 @@ class FileSystemOperation {
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)>
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().
typedef base::Callback<void(base::PlatformFileError result,
int64 bytes,
@@ -146,6 +230,9 @@ class FileSystemOperation {
// |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| 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
// calls:
@@ -157,6 +244,7 @@ class FileSystemOperation {
//
virtual void Copy(const FileSystemURL& src_path,
const FileSystemURL& dest_path,
+ const CopyProgressCallback& progress_callback,
const StatusCallback& callback) = 0;
// Moves a file or directory from |src_path| to |dest_path|. A new file
@@ -302,6 +390,9 @@ class FileSystemOperation {
// Copies a file from |src_url| to |dest_url|.
// 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).
+ // |progress_callback| is periodically called to report the progress
+ // update. See also the comment of CopyFileProgressCallback. This callback is
+ // optional.
//
// This returns:
// - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
@@ -314,6 +405,7 @@ class FileSystemOperation {
//
virtual void CopyFileLocal(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
+ const CopyFileProgressCallback& progress_callback,
const StatusCallback& callback) = 0;
// Moves a local file from |src_url| to |dest_url|.