diff options
author | Andras Becsi <andras.becsi@digia.com> | 2013-12-11 21:33:03 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2013-12-13 12:34:07 +0100 |
commit | f2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch) | |
tree | 0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/webkit/browser/fileapi/file_system_operation.h | |
parent | 5362912cdb5eea702b68ebe23702468d17c3017a (diff) | |
download | qtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz |
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/webkit/browser/fileapi/file_system_operation.h')
-rw-r--r-- | chromium/webkit/browser/fileapi/file_system_operation.h | 203 |
1 files changed, 197 insertions, 6 deletions
diff --git a/chromium/webkit/browser/fileapi/file_system_operation.h b/chromium/webkit/browser/fileapi/file_system_operation.h index f1adc191a7e..99d3b3d6a97 100644 --- a/chromium/webkit/browser/fileapi/file_system_operation.h +++ b/chromium/webkit/browser/fileapi/file_system_operation.h @@ -11,6 +11,8 @@ #include "base/files/file_path.h" #include "base/platform_file.h" #include "base/process/process.h" +#include "webkit/browser/fileapi/file_system_operation_context.h" +#include "webkit/browser/webkit_storage_browser_export.h" #include "webkit/common/fileapi/directory_entry.h" namespace base { @@ -29,9 +31,9 @@ class GURL; namespace fileapi { +class FileSystemContext; class FileSystemURL; class FileWriterDelegate; -class FileSystemOperationImpl; // The interface class for FileSystemOperation implementations. // @@ -56,6 +58,11 @@ class FileSystemOperationImpl; // it gets called. class FileSystemOperation { public: + WEBKIT_STORAGE_BROWSER_EXPORT static FileSystemOperation* Create( + const FileSystemURL& url, + FileSystemContext* file_system_context, + scoped_ptr<FileSystemOperationContext> operation_context); + virtual ~FileSystemOperation() {} // Used for CreateFile(), etc. |result| is the return code of the operation. @@ -115,6 +122,93 @@ 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. 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). + // 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 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 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). + // 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 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). + // 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 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, + // so they may not be appeared. + // 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, + const FileSystemURL& destination_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, @@ -139,12 +233,34 @@ 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: + // - ReadDirectory, CopyFileLocal and CreateDirectory + // for same-filesystem case, or + // - ReadDirectory and CreateSnapshotFile on source filesystem and + // CopyInForeignFile and CreateDirectory on dest filesystem + // for cross-filesystem case. + // 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 // or directory is created at |dest_path| as needed. + // + // For recursive case this internally creates new FileSystemOperations and + // calls: + // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove + // for same-filesystem case, or + // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and + // CopyInForeignFile and CreateDirectory on dest filesystem + // for cross-filesystem case. + // virtual void Move(const FileSystemURL& src_path, const FileSystemURL& dest_path, const StatusCallback& callback) = 0; @@ -230,11 +346,6 @@ class FileSystemOperation { base::ProcessHandle peer_handle, const OpenFileCallback& callback) = 0; - // For downcasting to FileSystemOperationImpl. - // TODO(kinuko): this hack should go away once appropriate upload-stream - // handling based on element types is supported. - virtual FileSystemOperationImpl* AsFileSystemOperationImpl() = 0; - // Creates a local snapshot file for a given |path| and returns the // metadata and platform path of the snapshot file via |callback|. // In local filesystem cases the implementation may simply return @@ -246,6 +357,86 @@ class FileSystemOperation { virtual void CreateSnapshotFile(const FileSystemURL& path, const SnapshotFileCallback& callback) = 0; + // Copies in a single file from a different filesystem. + // + // This returns: + // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path| + // or the parent directory of |dest_url| does not exist. + // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and + // is not a file. + // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and + // its parent path is a file. + // + virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, + const FileSystemURL& dest_url, + const StatusCallback& callback) = 0; + + // Removes a single file. + // + // This returns: + // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. + // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file. + // + virtual void RemoveFile(const FileSystemURL& url, + const StatusCallback& callback) = 0; + + // Removes a single empty directory. + // + // This returns: + // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. + // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. + // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. + // + virtual void RemoveDirectory(const FileSystemURL& url, + const StatusCallback& callback) = 0; + + // 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| + // or the parent directory of |dest_url| does not exist. + // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. + // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and + // is not a file. + // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and + // its parent path is a file. + // + 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|. + // 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). + // + // This returns: + // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| + // or the parent directory of |dest_url| does not exist. + // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. + // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and + // is not a file. + // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and + // its parent path is a file. + // + virtual void MoveFileLocal(const FileSystemURL& src_url, + const FileSystemURL& dest_url, + const StatusCallback& callback) = 0; + + // Synchronously gets the platform path for the given |url|. + // This may fail if the given |url|'s filesystem type is neither + // temporary nor persistent. + // In such a case, base::PLATFORM_FILE_ERROR_INVALID_OPERATION will be + // returned. + virtual base::PlatformFileError SyncGetPlatformPath( + const FileSystemURL& url, + base::FilePath* platform_path) = 0; + protected: // Used only for internal assertions. enum OperationType { |