Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: webkit/browser/fileapi/file_system_operation.h

Issue 24030002: Adds callbacks to notify progress into Copy's API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // longer necessary in the javascript world. 115 // longer necessary in the javascript world.
116 // Please see the comment for ShareableFileReference for details. 116 // Please see the comment for ShareableFileReference for details.
117 // 117 //
118 typedef base::Callback< 118 typedef base::Callback<
119 void(base::PlatformFileError result, 119 void(base::PlatformFileError result,
120 const base::PlatformFileInfo& file_info, 120 const base::PlatformFileInfo& file_info,
121 const base::FilePath& platform_path, 121 const base::FilePath& platform_path,
122 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)> 122 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)>
123 SnapshotFileCallback; 123 SnapshotFileCallback;
124 124
125 // Used for progress update callback for Copy().
126 //
127 // BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both
128 // file and directory).
129 // The |source_url| is the URL of the source entry. |size| should not be
130 // used.
131 //
132 // END_COPY_ENTRY is fired for each copy creation finishing (for both
133 // file and directory).
134 // The |source_url| is the URL of the source entry. |size| should not be
135 // used.
136 //
137 // PROGRESS is fired periodically during file copying (not fired for
138 // directory copy).
139 // The |source_url| is the URL of the source file. |size| is the number
140 // of cumulative copied bytes for the currently copied file.
141 // Both at beginning and ending of file copying, PROGRESS event should be
142 // called. At beginning, |size| should be 0. At ending, |size| should be
143 // the size of the file.
144 //
145 // Here is an example callback sequence of recursive copy. Suppose
146 // there are a/b/c.txt (100 bytes) and a/b/d.txt (200 bytes), and trying to
147 // copy a to x recursively, then the progress update sequence will be:
148 //
149 // BEGIN_COPY_ENTRY a (starting create "a" directory in x/).
150 // END_COPY_ENTRY a (creating "a" directory in x/ is finished).
151 //
152 // BEGIN_COPY_ENTRY a/b (starting create "b" directory in x/a).
153 // END_COPY_ENTRY a/b (creating "b" directory in x/a/ is finished).
154 //
155 // BEGIN_COPY_ENTRY a/b/c.txt (starting to copy "c.txt" in x/a/b/).
156 // PROGRESS a/b/c.txt 0 (The first PROGRESS's |size| should be 0).
157 // PROGRESS a/b/c.txt 10
158 // :
159 // PROGRESS a/b/c.txt 90
160 // PROGRESS a/b/c.txt 100 (The last PROGRESS's |size| should be the size of
161 // the file).
162 // END_COPY_ENTRY a/b/c.txt (copying "c.txt" is finished).
163 //
164 // BEGIN_COPY_ENTRY a/b/d.txt (starting to copy "d.txt" in x/a/b).
165 // PROGRESS a/b/d.txt 0 (The first PROGRESS's |size| should be 0).
166 // PROGRESS a/b/d.txt 10
167 // :
168 // PROGRESS a/b/d.txt 190
169 // PROGRESS a/b/d.txt 200 (The last PROGRESS's |size| should be the size of
170 // the file).
171 // END_COPY_ENTRY a/b/d.txt (copy "d.txt" is finished).
172 //
173 // Note that event sequence of a/b/c.txt and a/b/d.txt can be interlaced,
174 // because they can be done in parallel.
175 // All the progress callback invocation should be done before StatusCallback
176 // given to the Copy is called. Especially if an error is found before first
177 // progres callback invocation, the progress callback may NOT invoked for the
178 // copy.
179 //
180 // Note for future extension. Currently this callback is only supported on
181 // Copy(). We can extend this to Move(), because Move() is sometimes
182 // implemented as "copy then delete."
183 // In more precise, Move() usually can be implemented either 1) by updating
184 // the metadata of resource (e.g. root of moving directory tree), or 2) by
185 // copying directory tree and them removing the source tree.
186 // For 1)'s case, we can simply add BEGIN_MOVE_ENTRY and END_MOVE_ENTRY
187 // for root directory.
188 // For 2)'s case, we can add BEGIN_DELETE_ENTRY and END_DELETE_ENTRY for each
189 // entry.
190 // For both cases, we probably won't need to use PROGRESS event because
191 // these operations should be done quickly (at least much faster than copying
192 // usually).
193 enum CopyProgressType {
194 BEGIN_COPY_ENTRY,
195 END_COPY_ENTRY,
196 PROGRESS,
197 };
198 typedef base::Callback<void(
199 CopyProgressType type, const FileSystemURL& source_url, int64 size)>
200 CopyProgressCallback;
201
202 // Used for CopyFileLocal() to report progress update.
203 // |size| is the cumulative copied bytes for the copy.
204 // At the beginning the progress callback should be called with |size| = 0,
205 // and also at the ending the progress callback should be called with |size|
206 // set to the copied file size.
207 typedef base::Callback<void(int64 size)> CopyFileProgressCallback;
208
125 // Used for Write(). 209 // Used for Write().
126 typedef base::Callback<void(base::PlatformFileError result, 210 typedef base::Callback<void(base::PlatformFileError result,
127 int64 bytes, 211 int64 bytes,
128 bool complete)> WriteCallback; 212 bool complete)> WriteCallback;
129 213
130 // Creates a file at |path|. If |exclusive| is true, an error is raised 214 // Creates a file at |path|. If |exclusive| is true, an error is raised
131 // in case a file is already present at the URL. 215 // in case a file is already present at the URL.
132 virtual void CreateFile(const FileSystemURL& path, 216 virtual void CreateFile(const FileSystemURL& path,
133 bool exclusive, 217 bool exclusive,
134 const StatusCallback& callback) = 0; 218 const StatusCallback& callback) = 0;
135 219
136 // Creates a directory at |path|. If |exclusive| is true, an error is 220 // Creates a directory at |path|. If |exclusive| is true, an error is
137 // raised in case a directory is already present at the URL. If 221 // raised in case a directory is already present at the URL. If
138 // |recursive| is true, create parent directories as needed just like 222 // |recursive| is true, create parent directories as needed just like
139 // mkdir -p does. 223 // mkdir -p does.
140 virtual void CreateDirectory(const FileSystemURL& path, 224 virtual void CreateDirectory(const FileSystemURL& path,
141 bool exclusive, 225 bool exclusive,
142 bool recursive, 226 bool recursive,
143 const StatusCallback& callback) = 0; 227 const StatusCallback& callback) = 0;
144 228
145 // Copies a file or directory from |src_path| to |dest_path|. If 229 // Copies a file or directory from |src_path| to |dest_path|. If
146 // |src_path| is a directory, the contents of |src_path| are copied to 230 // |src_path| is a directory, the contents of |src_path| are copied to
147 // |dest_path| recursively. A new file or directory is created at 231 // |dest_path| recursively. A new file or directory is created at
148 // |dest_path| as needed. 232 // |dest_path| as needed.
233 // |progress_callback| is periodically called to report the progress
234 // update. See also the comment of CopyProgressCallback. This callback is
235 // optional.
149 // 236 //
150 // For recursive case this internally creates new FileSystemOperations and 237 // For recursive case this internally creates new FileSystemOperations and
151 // calls: 238 // calls:
152 // - ReadDirectory, CopyFileLocal and CreateDirectory 239 // - ReadDirectory, CopyFileLocal and CreateDirectory
153 // for same-filesystem case, or 240 // for same-filesystem case, or
154 // - ReadDirectory and CreateSnapshotFile on source filesystem and 241 // - ReadDirectory and CreateSnapshotFile on source filesystem and
155 // CopyInForeignFile and CreateDirectory on dest filesystem 242 // CopyInForeignFile and CreateDirectory on dest filesystem
156 // for cross-filesystem case. 243 // for cross-filesystem case.
157 // 244 //
158 virtual void Copy(const FileSystemURL& src_path, 245 virtual void Copy(const FileSystemURL& src_path,
159 const FileSystemURL& dest_path, 246 const FileSystemURL& dest_path,
247 const CopyProgressCallback& progress_callback,
160 const StatusCallback& callback) = 0; 248 const StatusCallback& callback) = 0;
161 249
162 // Moves a file or directory from |src_path| to |dest_path|. A new file 250 // Moves a file or directory from |src_path| to |dest_path|. A new file
163 // or directory is created at |dest_path| as needed. 251 // or directory is created at |dest_path| as needed.
164 // 252 //
165 // For recursive case this internally creates new FileSystemOperations and 253 // For recursive case this internally creates new FileSystemOperations and
166 // calls: 254 // calls:
167 // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove 255 // - ReadDirectory, MoveFileLocal, CreateDirectory and Remove
168 // for same-filesystem case, or 256 // for same-filesystem case, or
169 // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and 257 // - ReadDirectory, CreateSnapshotFile and Remove on source filesystem and
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. 383 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist.
296 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. 384 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory.
297 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. 385 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty.
298 // 386 //
299 virtual void RemoveDirectory(const FileSystemURL& url, 387 virtual void RemoveDirectory(const FileSystemURL& url,
300 const StatusCallback& callback) = 0; 388 const StatusCallback& callback) = 0;
301 389
302 // Copies a file from |src_url| to |dest_url|. 390 // Copies a file from |src_url| to |dest_url|.
303 // This must be called for files that belong to the same filesystem 391 // This must be called for files that belong to the same filesystem
304 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). 392 // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
393 // |progress_callback| is periodically called to report the progress
394 // update. See also the comment of CopyFileProgressCallback. This callback is
395 // optional.
305 // 396 //
306 // This returns: 397 // This returns:
307 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| 398 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
308 // or the parent directory of |dest_url| does not exist. 399 // or the parent directory of |dest_url| does not exist.
309 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. 400 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
310 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and 401 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
311 // is not a file. 402 // is not a file.
312 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and 403 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and
313 // its parent path is a file. 404 // its parent path is a file.
314 // 405 //
315 virtual void CopyFileLocal(const FileSystemURL& src_url, 406 virtual void CopyFileLocal(const FileSystemURL& src_url,
316 const FileSystemURL& dest_url, 407 const FileSystemURL& dest_url,
408 const CopyFileProgressCallback& progress_callback,
317 const StatusCallback& callback) = 0; 409 const StatusCallback& callback) = 0;
318 410
319 // Moves a local file from |src_url| to |dest_url|. 411 // Moves a local file from |src_url| to |dest_url|.
320 // This must be called for files that belong to the same filesystem 412 // This must be called for files that belong to the same filesystem
321 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). 413 // (i.e. type() and origin() of the |src_url| and |dest_url| must match).
322 // 414 //
323 // This returns: 415 // This returns:
324 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| 416 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
325 // or the parent directory of |dest_url| does not exist. 417 // or the parent directory of |dest_url| does not exist.
326 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. 418 // - 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
363 kOperationOpenFile, 455 kOperationOpenFile,
364 kOperationCloseFile, 456 kOperationCloseFile,
365 kOperationGetLocalPath, 457 kOperationGetLocalPath,
366 kOperationCancel, 458 kOperationCancel,
367 }; 459 };
368 }; 460 };
369 461
370 } // namespace fileapi 462 } // namespace fileapi
371 463
372 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ 464 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/copy_or_move_operation_delegate.cc ('k') | webkit/browser/fileapi/file_system_operation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698