OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 // longer necessary in the javascript world. | 108 // longer necessary in the javascript world. |
109 // Please see the comment for ShareableFileReference for details. | 109 // Please see the comment for ShareableFileReference for details. |
110 // | 110 // |
111 typedef base::Callback< | 111 typedef base::Callback< |
112 void(base::PlatformFileError result, | 112 void(base::PlatformFileError result, |
113 const base::PlatformFileInfo& file_info, | 113 const base::PlatformFileInfo& file_info, |
114 const base::FilePath& platform_path, | 114 const base::FilePath& platform_path, |
115 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)> | 115 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)> |
116 SnapshotFileCallback; | 116 SnapshotFileCallback; |
117 | 117 |
118 // Used for progress update callback for Copy(). | |
119 // | |
120 // BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both | |
121 // file and directory). | |
122 // The |source_url| is the URL of the source entry. |size| should not be | |
123 // used. | |
124 // | |
125 // END_COPY_ENTRY is fired for each copy creation finishing (for both | |
126 // file and directory). | |
127 // The |source_url| is the URL of the source entry. |size| should not be | |
128 // used. | |
129 // | |
130 // PROGRESS is fired periodically during file copying (not fired for | |
131 // directory copy). | |
132 // The |source_url| is the URL of the source file. |size| is the number | |
133 // of cumulative copied bytes for the currently copied file. | |
134 // Both at beginning and ending of file copying, PROGRESS event should be | |
135 // called. At beginning, |size| should be 0. At ending, |size| should be | |
136 // the size of the file. | |
137 // | |
138 // Here is an example callback sequence of recursive copy. Suppose | |
139 // there are a/b/c.txt (100 bytes) and a/b/d.txt (200 bytes), and trying to | |
140 // copy a to x recursively, then the progress update sequence will be: | |
141 // | |
142 // BEGIN_COPY_ENTRY a (starting create "a" directory in x/). | |
143 // END_COPY_ENTRY a (creating "a" directory in x/ is finished). | |
144 // | |
145 // BEGIN_COPY_ENTRY a/b (starting create "b" directory in x/a). | |
146 // END_COPY_ENTRY a/b (creating "b" directory in x/a/ is finished). | |
147 // | |
148 // BEGIN_COPY_ENTRY a/b/c.txt (starting to copy "c.txt" in x/a/b/). | |
149 // PROGRESS a/b/c.txt 0 (The first PROGRESS's |size| should be 0). | |
150 // PROGRESS a/b/c.txt 10 | |
151 // : | |
152 // PROGRESS a/b/c.txt 90 | |
153 // PROGRESS a/b/c.txt 100 (The last PROGRESS's |size| should be the size of | |
154 // the file). | |
155 // END_COPY_ENTRY a/b/c.txt (copying "c.txt" is finished). | |
156 // | |
157 // BEGIN_COPY_ENTRY a/b/d.txt (starting to copy "d.txt" in x/a/b). | |
158 // PROGRESS a/b/d.txt 0 (The first PROGRESS's |size| should be 0). | |
159 // PROGRESS a/b/d.txt 10 | |
160 // : | |
161 // PROGRESS a/b/d.txt 190 | |
162 // PROGRESS a/b/d.txt 200 (The last PROGRESS's |size| should be the size of | |
163 // the file). | |
164 // END_COPY_ENTRY a/b/d.txt (copy "d.txt" is finished). | |
165 // | |
166 // Note that event sequence of a/b/c.txt and a/b/d.txt can be interlaced, | |
167 // because they can be done in parallel. | |
168 enum CopyProgressType { | |
169 BEGIN_COPY_ENTRY, | |
170 END_COPY_ENTRY, | |
171 PROGRESS, | |
172 }; | |
173 typedef base::Callback<void( | |
174 CopyProgressType type, const FileSystemURL& source_url, int64 size)> | |
175 CopyProgressCallback; | |
176 | |
177 // Used for CopyFileLocal() to report progress update. | |
178 // |size| is the cumulative copied bytes for the copy. | |
179 // At the beginning the progress callback should be called with |size| = 0, | |
180 // and also at the ending the progress callback should be called with |size| | |
181 // set to the copied file size. | |
182 typedef base::Callback<void(int64 size)> CopyFileProgressCallback; | |
kinuko
2013/09/06 09:55:25
Question: how difficult would it be (in terms of c
hidehiko
2013/09/06 10:06:16
IMHO, it's a bit complicated especially for direct
kinuko
2013/09/09 03:46:31
Would it need more effort than adding one more pro
hidehiko
2013/09/09 04:48:15
Added comments about future extension and on error
| |
183 | |
118 // Used for Write(). | 184 // Used for Write(). |
119 typedef base::Callback<void(base::PlatformFileError result, | 185 typedef base::Callback<void(base::PlatformFileError result, |
120 int64 bytes, | 186 int64 bytes, |
121 bool complete)> WriteCallback; | 187 bool complete)> WriteCallback; |
122 | 188 |
123 // Creates a file at |path|. If |exclusive| is true, an error is raised | 189 // Creates a file at |path|. If |exclusive| is true, an error is raised |
124 // in case a file is already present at the URL. | 190 // in case a file is already present at the URL. |
125 virtual void CreateFile(const FileSystemURL& path, | 191 virtual void CreateFile(const FileSystemURL& path, |
126 bool exclusive, | 192 bool exclusive, |
127 const StatusCallback& callback) = 0; | 193 const StatusCallback& callback) = 0; |
128 | 194 |
129 // Creates a directory at |path|. If |exclusive| is true, an error is | 195 // Creates a directory at |path|. If |exclusive| is true, an error is |
130 // raised in case a directory is already present at the URL. If | 196 // raised in case a directory is already present at the URL. If |
131 // |recursive| is true, create parent directories as needed just like | 197 // |recursive| is true, create parent directories as needed just like |
132 // mkdir -p does. | 198 // mkdir -p does. |
133 virtual void CreateDirectory(const FileSystemURL& path, | 199 virtual void CreateDirectory(const FileSystemURL& path, |
134 bool exclusive, | 200 bool exclusive, |
135 bool recursive, | 201 bool recursive, |
136 const StatusCallback& callback) = 0; | 202 const StatusCallback& callback) = 0; |
137 | 203 |
138 // Copies a file or directory from |src_path| to |dest_path|. If | 204 // Copies a file or directory from |src_path| to |dest_path|. If |
139 // |src_path| is a directory, the contents of |src_path| are copied to | 205 // |src_path| is a directory, the contents of |src_path| are copied to |
140 // |dest_path| recursively. A new file or directory is created at | 206 // |dest_path| recursively. A new file or directory is created at |
141 // |dest_path| as needed. | 207 // |dest_path| as needed. |
208 // |progress_callback| is periodically called to report the progress | |
209 // update. See also the comment of CopyProgressCallback. This callback is | |
210 // optional. | |
142 // | 211 // |
143 // For recursive case this internally creates new FileSystemOperations and | 212 // For recursive case this internally creates new FileSystemOperations and |
144 // calls: | 213 // calls: |
145 // - ReadDirectory, CopyFileLocal and CreateDirectory | 214 // - ReadDirectory, CopyFileLocal and CreateDirectory |
146 // for same-filesystem case, or | 215 // for same-filesystem case, or |
147 // - ReadDirectory and CreateSnapshotFile on source filesystem and | 216 // - ReadDirectory and CreateSnapshotFile on source filesystem and |
148 // CopyInForeignFile and CreateDirectory on dest filesystem | 217 // CopyInForeignFile and CreateDirectory on dest filesystem |
149 // for cross-filesystem case. | 218 // for cross-filesystem case. |
150 // | 219 // |
151 virtual void Copy(const FileSystemURL& src_path, | 220 virtual void Copy(const FileSystemURL& src_path, |
152 const FileSystemURL& dest_path, | 221 const FileSystemURL& dest_path, |
222 const CopyProgressCallback& progress_callback, | |
153 const StatusCallback& callback) = 0; | 223 const StatusCallback& callback) = 0; |
154 | 224 |
155 // Moves a file or directory from |src_path| to |dest_path|. A new file | 225 // Moves a file or directory from |src_path| to |dest_path|. A new file |
156 // or directory is created at |dest_path| as needed. | 226 // or directory is created at |dest_path| as needed. |
157 // | 227 // |
158 // For recursive case this internally creates new FileSystemOperations and | 228 // For recursive case this internally creates new FileSystemOperations and |
159 // calls: | 229 // calls: |
160 // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove | 230 // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove |
161 // for same-filesystem case, or | 231 // for same-filesystem case, or |
162 // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and | 232 // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 358 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
289 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. | 359 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. |
290 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. | 360 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. |
291 // | 361 // |
292 virtual void RemoveDirectory(const FileSystemURL& url, | 362 virtual void RemoveDirectory(const FileSystemURL& url, |
293 const StatusCallback& callback) = 0; | 363 const StatusCallback& callback) = 0; |
294 | 364 |
295 // Copies a file from |src_url| to |dest_url|. | 365 // Copies a file from |src_url| to |dest_url|. |
296 // This must be called for files that belong to the same filesystem | 366 // This must be called for files that belong to the same filesystem |
297 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 367 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
368 // |progress_callback| is periodically called to report the progress | |
369 // update. See also the comment of CopyFileProgressCallback. This callback is | |
370 // optional. | |
298 // | 371 // |
299 // This returns: | 372 // This returns: |
300 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 373 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
301 // or the parent directory of |dest_url| does not exist. | 374 // or the parent directory of |dest_url| does not exist. |
302 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 375 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
303 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 376 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
304 // is not a file. | 377 // is not a file. |
305 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 378 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
306 // its parent path is a file. | 379 // its parent path is a file. |
307 // | 380 // |
308 virtual void CopyFileLocal(const FileSystemURL& src_url, | 381 virtual void CopyFileLocal(const FileSystemURL& src_url, |
309 const FileSystemURL& dest_url, | 382 const FileSystemURL& dest_url, |
383 const CopyFileProgressCallback& progress_callback, | |
310 const StatusCallback& callback) = 0; | 384 const StatusCallback& callback) = 0; |
311 | 385 |
312 // Moves a local file from |src_url| to |dest_url|. | 386 // Moves a local file from |src_url| to |dest_url|. |
313 // This must be called for files that belong to the same filesystem | 387 // This must be called for files that belong to the same filesystem |
314 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 388 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
315 // | 389 // |
316 // This returns: | 390 // This returns: |
317 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 391 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
318 // or the parent directory of |dest_url| does not exist. | 392 // or the parent directory of |dest_url| does not exist. |
319 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 393 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 kOperationOpenFile, | 430 kOperationOpenFile, |
357 kOperationCloseFile, | 431 kOperationCloseFile, |
358 kOperationGetLocalPath, | 432 kOperationGetLocalPath, |
359 kOperationCancel, | 433 kOperationCancel, |
360 }; | 434 }; |
361 }; | 435 }; |
362 | 436 |
363 } // namespace fileapi | 437 } // namespace fileapi |
364 | 438 |
365 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 439 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |