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" |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
14 #include "webkit/browser/fileapi/file_system_operation_context.h" | 14 #include "storage/browser/fileapi/file_system_operation_context.h" |
15 #include "webkit/browser/webkit_storage_browser_export.h" | 15 #include "storage/common/storage_export.h" |
16 #include "webkit/common/fileapi/directory_entry.h" | 16 #include "storage/common/fileapi/directory_entry.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class Time; | 19 class Time; |
20 } | 20 } |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 class URLRequest; | 23 class URLRequest; |
24 } | 24 } |
25 | 25 |
26 namespace webkit_blob { | 26 namespace storage { |
27 class ShareableFileReference; | 27 class ShareableFileReference; |
28 } | 28 } |
29 | 29 |
30 class GURL; | 30 class GURL; |
31 | 31 |
32 namespace fileapi { | 32 namespace storage { |
33 | 33 |
34 class FileSystemContext; | 34 class FileSystemContext; |
35 class FileSystemURL; | 35 class FileSystemURL; |
36 class FileWriterDelegate; | 36 class FileWriterDelegate; |
37 | 37 |
38 // The interface class for FileSystemOperation implementations. | 38 // The interface class for FileSystemOperation implementations. |
39 // | 39 // |
40 // This interface defines file system operations required to implement | 40 // This interface defines file system operations required to implement |
41 // "File API: Directories and System" | 41 // "File API: Directories and System" |
42 // http://www.w3.org/TR/file-system-api/ | 42 // http://www.w3.org/TR/file-system-api/ |
43 // | 43 // |
44 // DESIGN NOTES | 44 // DESIGN NOTES |
45 // | 45 // |
46 // This class is designed to | 46 // This class is designed to |
47 // | 47 // |
48 // 1) Serve one-time file system operation per instance. Only one | 48 // 1) Serve one-time file system operation per instance. Only one |
49 // method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, | 49 // method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists, |
50 // GetMetadata, ReadDirectory and Remove) may be called during the | 50 // GetMetadata, ReadDirectory and Remove) may be called during the |
51 // lifetime of this object and it should be called no more than once. | 51 // lifetime of this object and it should be called no more than once. |
52 // | 52 // |
53 // 2) Deliver the results of operations to the client via the callback function | 53 // 2) Deliver the results of operations to the client via the callback function |
54 // passed as the last parameter of the method. | 54 // passed as the last parameter of the method. |
55 // | 55 // |
56 // Note that it is valid to delete an operation while it is running. | 56 // Note that it is valid to delete an operation while it is running. |
57 // The callback will NOT be fired if the operation is deleted before | 57 // The callback will NOT be fired if the operation is deleted before |
58 // it gets called. | 58 // it gets called. |
59 class FileSystemOperation { | 59 class FileSystemOperation { |
60 public: | 60 public: |
61 WEBKIT_STORAGE_BROWSER_EXPORT static FileSystemOperation* Create( | 61 STORAGE_EXPORT static FileSystemOperation* Create( |
62 const FileSystemURL& url, | 62 const FileSystemURL& url, |
63 FileSystemContext* file_system_context, | 63 FileSystemContext* file_system_context, |
64 scoped_ptr<FileSystemOperationContext> operation_context); | 64 scoped_ptr<FileSystemOperationContext> operation_context); |
65 | 65 |
66 virtual ~FileSystemOperation() {} | 66 virtual ~FileSystemOperation() {} |
67 | 67 |
68 // Used for CreateFile(), etc. |result| is the return code of the operation. | 68 // Used for CreateFile(), etc. |result| is the return code of the operation. |
69 typedef base::Callback<void(base::File::Error result)> StatusCallback; | 69 typedef base::Callback<void(base::File::Error result)> StatusCallback; |
70 | 70 |
71 // Used for GetMetadata(). |result| is the return code of the operation, | 71 // Used for GetMetadata(). |result| is the return code of the operation, |
72 // |file_info| is the obtained file info. | 72 // |file_info| is the obtained file info. |
73 typedef base::Callback< | 73 typedef base::Callback< |
74 void(base::File::Error result, | 74 void(base::File::Error result, const base::File::Info& file_info)> |
75 const base::File::Info& file_info)> GetMetadataCallback; | 75 GetMetadataCallback; |
76 | 76 |
77 // Used for OpenFile(). |on_close_callback| will be called after the file is | 77 // Used for OpenFile(). |on_close_callback| will be called after the file is |
78 // closed in the child process. It can be null, if no operation is needed on | 78 // closed in the child process. It can be null, if no operation is needed on |
79 // closing a file. | 79 // closing a file. |
80 typedef base::Callback< | 80 typedef base::Callback< |
81 void(base::File file, | 81 void(base::File file, const base::Closure& on_close_callback)> |
82 const base::Closure& on_close_callback)> OpenFileCallback; | 82 OpenFileCallback; |
83 | 83 |
84 // Used for ReadDirectoryCallback. | 84 // Used for ReadDirectoryCallback. |
85 typedef std::vector<DirectoryEntry> FileEntryList; | 85 typedef std::vector<DirectoryEntry> FileEntryList; |
86 | 86 |
87 // Used for ReadDirectory(). |result| is the return code of the operation, | 87 // Used for ReadDirectory(). |result| is the return code of the operation, |
88 // |file_list| is the list of files read, and |has_more| is true if some files | 88 // |file_list| is the list of files read, and |has_more| is true if some files |
89 // are yet to be read. | 89 // are yet to be read. |
90 typedef base::Callback< | 90 typedef base::Callback<void(base::File::Error result, |
91 void(base::File::Error result, | 91 const FileEntryList& file_list, |
92 const FileEntryList& file_list, | 92 bool has_more)> ReadDirectoryCallback; |
93 bool has_more)> ReadDirectoryCallback; | |
94 | 93 |
95 // Used for CreateSnapshotFile(). (Please see the comment at | 94 // Used for CreateSnapshotFile(). (Please see the comment at |
96 // CreateSnapshotFile() below for how the method is called) | 95 // CreateSnapshotFile() below for how the method is called) |
97 // |result| is the return code of the operation. | 96 // |result| is the return code of the operation. |
98 // |file_info| is the metadata of the snapshot file created. | 97 // |file_info| is the metadata of the snapshot file created. |
99 // |platform_path| is the path to the snapshot file created. | 98 // |platform_path| is the path to the snapshot file created. |
100 // | 99 // |
101 // The snapshot file could simply be of the local file pointed by the given | 100 // The snapshot file could simply be of the local file pointed by the given |
102 // filesystem URL in local filesystem cases; remote filesystems | 101 // filesystem URL in local filesystem cases; remote filesystems |
103 // may want to download the file into a temporary snapshot file and then | 102 // may want to download the file into a temporary snapshot file and then |
104 // return the metadata of the temporary file. | 103 // return the metadata of the temporary file. |
105 // | 104 // |
106 // |file_ref| is used to manage the lifetime of the returned | 105 // |file_ref| is used to manage the lifetime of the returned |
107 // snapshot file. It can be set to let the chromium backend take | 106 // snapshot file. It can be set to let the chromium backend take |
108 // care of the life time of the snapshot file. Otherwise (if the returned | 107 // care of the life time of the snapshot file. Otherwise (if the returned |
109 // file does not require any handling) the implementation can just | 108 // file does not require any handling) the implementation can just |
110 // return NULL. In a more complex case, the implementaiton can manage | 109 // return NULL. In a more complex case, the implementaiton can manage |
111 // the lifetime of the snapshot file on its own (e.g. by its cache system) | 110 // the lifetime of the snapshot file on its own (e.g. by its cache system) |
112 // but also can be notified via the reference when the file becomes no | 111 // but also can be notified via the reference when the file becomes no |
113 // longer necessary in the javascript world. | 112 // longer necessary in the javascript world. |
114 // Please see the comment for ShareableFileReference for details. | 113 // Please see the comment for ShareableFileReference for details. |
115 // | 114 // |
116 typedef base::Callback< | 115 typedef base::Callback< |
117 void(base::File::Error result, | 116 void(base::File::Error result, |
118 const base::File::Info& file_info, | 117 const base::File::Info& file_info, |
119 const base::FilePath& platform_path, | 118 const base::FilePath& platform_path, |
120 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref)> | 119 const scoped_refptr<storage::ShareableFileReference>& file_ref)> |
121 SnapshotFileCallback; | 120 SnapshotFileCallback; |
122 | 121 |
123 // Used for progress update callback for Copy(). | 122 // Used for progress update callback for Copy(). |
124 // | 123 // |
125 // BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both | 124 // BEGIN_COPY_ENTRY is fired for each copy creation beginning (for both |
126 // file and directory). | 125 // file and directory). |
127 // The |source_url| is the URL of the source entry. |size| should not be | 126 // The |source_url| is the URL of the source entry. |size| should not be |
128 // used. | 127 // used. |
129 // | 128 // |
130 // END_COPY_ENTRY is fired for each copy creation finishing (for both | 129 // END_COPY_ENTRY is fired for each copy creation finishing (for both |
131 // file and directory). | 130 // file and directory). |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // these operations should be done quickly (at least much faster than copying | 189 // these operations should be done quickly (at least much faster than copying |
191 // usually). | 190 // usually). |
192 enum CopyProgressType { | 191 enum CopyProgressType { |
193 BEGIN_COPY_ENTRY, | 192 BEGIN_COPY_ENTRY, |
194 END_COPY_ENTRY, | 193 END_COPY_ENTRY, |
195 PROGRESS, | 194 PROGRESS, |
196 }; | 195 }; |
197 typedef base::Callback<void(CopyProgressType type, | 196 typedef base::Callback<void(CopyProgressType type, |
198 const FileSystemURL& source_url, | 197 const FileSystemURL& source_url, |
199 const FileSystemURL& destination_url, | 198 const FileSystemURL& destination_url, |
200 int64 size)> | 199 int64 size)> CopyProgressCallback; |
201 CopyProgressCallback; | |
202 | 200 |
203 // Used for CopyFileLocal() to report progress update. | 201 // Used for CopyFileLocal() to report progress update. |
204 // |size| is the cumulative copied bytes for the copy. | 202 // |size| is the cumulative copied bytes for the copy. |
205 // At the beginning the progress callback should be called with |size| = 0, | 203 // At the beginning the progress callback should be called with |size| = 0, |
206 // and also at the ending the progress callback should be called with |size| | 204 // and also at the ending the progress callback should be called with |size| |
207 // set to the copied file size. | 205 // set to the copied file size. |
208 typedef base::Callback<void(int64 size)> CopyFileProgressCallback; | 206 typedef base::Callback<void(int64 size)> CopyFileProgressCallback; |
209 | 207 |
210 // The option for copy or move operation. | 208 // The option for copy or move operation. |
211 enum CopyOrMoveOption { | 209 enum CopyOrMoveOption { |
212 // No additional operation. | 210 // No additional operation. |
213 OPTION_NONE, | 211 OPTION_NONE, |
214 | 212 |
215 // Preserves last modified time if possible. If the operation to update | 213 // Preserves last modified time if possible. If the operation to update |
216 // last modified time is not supported on the file system for the | 214 // last modified time is not supported on the file system for the |
217 // destination file, this option would be simply ignored (i.e. Copy would | 215 // destination file, this option would be simply ignored (i.e. Copy would |
218 // be successfully done without preserving last modified time). | 216 // be successfully done without preserving last modified time). |
219 OPTION_PRESERVE_LAST_MODIFIED, | 217 OPTION_PRESERVE_LAST_MODIFIED, |
220 }; | 218 }; |
221 | 219 |
222 // Used for Write(). | 220 // Used for Write(). |
223 typedef base::Callback<void(base::File::Error result, | 221 typedef base::Callback< |
224 int64 bytes, | 222 void(base::File::Error result, int64 bytes, bool complete)> WriteCallback; |
225 bool complete)> WriteCallback; | |
226 | 223 |
227 // Creates a file at |path|. If |exclusive| is true, an error is raised | 224 // Creates a file at |path|. If |exclusive| is true, an error is raised |
228 // in case a file is already present at the URL. | 225 // in case a file is already present at the URL. |
229 virtual void CreateFile(const FileSystemURL& path, | 226 virtual void CreateFile(const FileSystemURL& path, |
230 bool exclusive, | 227 bool exclusive, |
231 const StatusCallback& callback) = 0; | 228 const StatusCallback& callback) = 0; |
232 | 229 |
233 // Creates a directory at |path|. If |exclusive| is true, an error is | 230 // Creates a directory at |path|. If |exclusive| is true, an error is |
234 // raised in case a directory is already present at the URL. If | 231 // raised in case a directory is already present at the URL. If |
235 // |recursive| is true, create parent directories as needed just like | 232 // |recursive| is true, create parent directories as needed just like |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // Gets the metadata of a file or directory at |path|. | 289 // Gets the metadata of a file or directory at |path|. |
293 virtual void GetMetadata(const FileSystemURL& path, | 290 virtual void GetMetadata(const FileSystemURL& path, |
294 const GetMetadataCallback& callback) = 0; | 291 const GetMetadataCallback& callback) = 0; |
295 | 292 |
296 // Reads contents of a directory at |path|. | 293 // Reads contents of a directory at |path|. |
297 virtual void ReadDirectory(const FileSystemURL& path, | 294 virtual void ReadDirectory(const FileSystemURL& path, |
298 const ReadDirectoryCallback& callback) = 0; | 295 const ReadDirectoryCallback& callback) = 0; |
299 | 296 |
300 // Removes a file or directory at |path|. If |recursive| is true, remove | 297 // Removes a file or directory at |path|. If |recursive| is true, remove |
301 // all files and directories under the directory at |path| recursively. | 298 // all files and directories under the directory at |path| recursively. |
302 virtual void Remove(const FileSystemURL& path, bool recursive, | 299 virtual void Remove(const FileSystemURL& path, |
| 300 bool recursive, |
303 const StatusCallback& callback) = 0; | 301 const StatusCallback& callback) = 0; |
304 | 302 |
305 // Writes the data read from |blob_request| using |writer_delegate|. | 303 // Writes the data read from |blob_request| using |writer_delegate|. |
306 virtual void Write( | 304 virtual void Write(const FileSystemURL& url, |
307 const FileSystemURL& url, | 305 scoped_ptr<FileWriterDelegate> writer_delegate, |
308 scoped_ptr<FileWriterDelegate> writer_delegate, | 306 scoped_ptr<net::URLRequest> blob_request, |
309 scoped_ptr<net::URLRequest> blob_request, | 307 const WriteCallback& callback) = 0; |
310 const WriteCallback& callback) = 0; | |
311 | 308 |
312 // Truncates a file at |path| to |length|. If |length| is larger than | 309 // Truncates a file at |path| to |length|. If |length| is larger than |
313 // the original file size, the file will be extended, and the extended | 310 // the original file size, the file will be extended, and the extended |
314 // part is filled with null bytes. | 311 // part is filled with null bytes. |
315 virtual void Truncate(const FileSystemURL& path, int64 length, | 312 virtual void Truncate(const FileSystemURL& path, |
| 313 int64 length, |
316 const StatusCallback& callback) = 0; | 314 const StatusCallback& callback) = 0; |
317 | 315 |
318 // Tries to cancel the current operation [we support cancelling write or | 316 // Tries to cancel the current operation [we support cancelling write or |
319 // truncate only]. Reports failure for the current operation, then reports | 317 // truncate only]. Reports failure for the current operation, then reports |
320 // success for the cancel operation itself via the |cancel_dispatcher|. | 318 // success for the cancel operation itself via the |cancel_dispatcher|. |
321 // | 319 // |
322 // E.g. a typical cancel implementation would look like: | 320 // E.g. a typical cancel implementation would look like: |
323 // | 321 // |
324 // virtual void SomeOperationImpl::Cancel( | 322 // virtual void SomeOperationImpl::Cancel( |
325 // const StatusCallback& cancel_callback) { | 323 // const StatusCallback& cancel_callback) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 kOperationWrite, | 471 kOperationWrite, |
474 kOperationTruncate, | 472 kOperationTruncate, |
475 kOperationTouchFile, | 473 kOperationTouchFile, |
476 kOperationOpenFile, | 474 kOperationOpenFile, |
477 kOperationCloseFile, | 475 kOperationCloseFile, |
478 kOperationGetLocalPath, | 476 kOperationGetLocalPath, |
479 kOperationCancel, | 477 kOperationCancel, |
480 }; | 478 }; |
481 }; | 479 }; |
482 | 480 |
483 } // namespace fileapi | 481 } // namespace storage |
484 | 482 |
485 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ | 483 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_H_ |
OLD | NEW |