OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_RUNNER_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "webkit/browser/blob/blob_data_handle.h" | 16 #include "storage/browser/blob/blob_data_handle.h" |
17 #include "webkit/browser/fileapi/file_system_operation.h" | 17 #include "storage/browser/fileapi/file_system_operation.h" |
18 #include "webkit/browser/fileapi/file_system_url.h" | 18 #include "storage/browser/fileapi/file_system_url.h" |
19 #include "webkit/browser/webkit_storage_browser_export.h" | 19 #include "storage/common/storage_export.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class URLRequestContext; | 22 class URLRequestContext; |
23 } | 23 } |
24 | 24 |
25 namespace fileapi { | 25 namespace storage { |
26 | 26 |
27 class FileSystemURL; | 27 class FileSystemURL; |
28 class FileSystemContext; | 28 class FileSystemContext; |
29 | 29 |
30 // A central interface for running FileSystem API operations. | 30 // A central interface for running FileSystem API operations. |
31 // All operation methods take callback and returns OperationID, which is | 31 // All operation methods take callback and returns OperationID, which is |
32 // an integer value which can be used for cancelling an operation. | 32 // an integer value which can be used for cancelling an operation. |
33 // All operation methods return kErrorOperationID if running (posting) an | 33 // All operation methods return kErrorOperationID if running (posting) an |
34 // operation fails, in addition to dispatching the callback with an error | 34 // operation fails, in addition to dispatching the callback with an error |
35 // code (therefore in most cases the caller does not need to check the | 35 // code (therefore in most cases the caller does not need to check the |
36 // returned operation ID). | 36 // returned operation ID). |
37 class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemOperationRunner | 37 class STORAGE_EXPORT FileSystemOperationRunner |
38 : public base::SupportsWeakPtr<FileSystemOperationRunner> { | 38 : public base::SupportsWeakPtr<FileSystemOperationRunner> { |
39 public: | 39 public: |
40 typedef FileSystemOperation::GetMetadataCallback GetMetadataCallback; | 40 typedef FileSystemOperation::GetMetadataCallback GetMetadataCallback; |
41 typedef FileSystemOperation::ReadDirectoryCallback ReadDirectoryCallback; | 41 typedef FileSystemOperation::ReadDirectoryCallback ReadDirectoryCallback; |
42 typedef FileSystemOperation::SnapshotFileCallback SnapshotFileCallback; | 42 typedef FileSystemOperation::SnapshotFileCallback SnapshotFileCallback; |
43 typedef FileSystemOperation::StatusCallback StatusCallback; | 43 typedef FileSystemOperation::StatusCallback StatusCallback; |
44 typedef FileSystemOperation::WriteCallback WriteCallback; | 44 typedef FileSystemOperation::WriteCallback WriteCallback; |
45 typedef FileSystemOperation::OpenFileCallback OpenFileCallback; | 45 typedef FileSystemOperation::OpenFileCallback OpenFileCallback; |
46 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; | 46 typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; |
47 typedef FileSystemOperation::CopyFileProgressCallback | 47 typedef FileSystemOperation::CopyFileProgressCallback |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Gets the metadata of a file or directory at |url|. | 97 // Gets the metadata of a file or directory at |url|. |
98 OperationID GetMetadata(const FileSystemURL& url, | 98 OperationID GetMetadata(const FileSystemURL& url, |
99 const GetMetadataCallback& callback); | 99 const GetMetadataCallback& callback); |
100 | 100 |
101 // Reads contents of a directory at |url|. | 101 // Reads contents of a directory at |url|. |
102 OperationID ReadDirectory(const FileSystemURL& url, | 102 OperationID ReadDirectory(const FileSystemURL& url, |
103 const ReadDirectoryCallback& callback); | 103 const ReadDirectoryCallback& callback); |
104 | 104 |
105 // Removes a file or directory at |url|. If |recursive| is true, remove | 105 // Removes a file or directory at |url|. If |recursive| is true, remove |
106 // all files and directories under the directory at |url| recursively. | 106 // all files and directories under the directory at |url| recursively. |
107 OperationID Remove(const FileSystemURL& url, bool recursive, | 107 OperationID Remove(const FileSystemURL& url, |
| 108 bool recursive, |
108 const StatusCallback& callback); | 109 const StatusCallback& callback); |
109 | 110 |
110 // Writes contents of |blob_url| to |url| at |offset|. | 111 // Writes contents of |blob_url| to |url| at |offset|. |
111 // |url_request_context| is used to read contents in |blob|. | 112 // |url_request_context| is used to read contents in |blob|. |
112 OperationID Write(const net::URLRequestContext* url_request_context, | 113 OperationID Write(const net::URLRequestContext* url_request_context, |
113 const FileSystemURL& url, | 114 const FileSystemURL& url, |
114 scoped_ptr<webkit_blob::BlobDataHandle> blob, | 115 scoped_ptr<storage::BlobDataHandle> blob, |
115 int64 offset, | 116 int64 offset, |
116 const WriteCallback& callback); | 117 const WriteCallback& callback); |
117 | 118 |
118 // Truncates a file at |url| to |length|. If |length| is larger than | 119 // Truncates a file at |url| to |length|. If |length| is larger than |
119 // the original file size, the file will be extended, and the extended | 120 // the original file size, the file will be extended, and the extended |
120 // part is filled with null bytes. | 121 // part is filled with null bytes. |
121 OperationID Truncate(const FileSystemURL& url, int64 length, | 122 OperationID Truncate(const FileSystemURL& url, |
| 123 int64 length, |
122 const StatusCallback& callback); | 124 const StatusCallback& callback); |
123 | 125 |
124 // Tries to cancel the operation |id| [we support cancelling write or | 126 // Tries to cancel the operation |id| [we support cancelling write or |
125 // truncate only]. Reports failure for the current operation, then reports | 127 // truncate only]. Reports failure for the current operation, then reports |
126 // success for the cancel operation itself via the |callback|. | 128 // success for the cancel operation itself via the |callback|. |
127 void Cancel(OperationID id, const StatusCallback& callback); | 129 void Cancel(OperationID id, const StatusCallback& callback); |
128 | 130 |
129 // Modifies timestamps of a file or directory at |url| with | 131 // Modifies timestamps of a file or directory at |url| with |
130 // |last_access_time| and |last_modified_time|. The function DOES NOT | 132 // |last_access_time| and |last_modified_time|. The function DOES NOT |
131 // create a file unlike 'touch' command on Linux. | 133 // create a file unlike 'touch' command on Linux. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 void DidReadDirectory(const OperationHandle& handle, | 263 void DidReadDirectory(const OperationHandle& handle, |
262 const ReadDirectoryCallback& callback, | 264 const ReadDirectoryCallback& callback, |
263 base::File::Error rv, | 265 base::File::Error rv, |
264 const std::vector<DirectoryEntry>& entries, | 266 const std::vector<DirectoryEntry>& entries, |
265 bool has_more); | 267 bool has_more); |
266 void DidWrite(const OperationHandle& handle, | 268 void DidWrite(const OperationHandle& handle, |
267 const WriteCallback& callback, | 269 const WriteCallback& callback, |
268 base::File::Error rv, | 270 base::File::Error rv, |
269 int64 bytes, | 271 int64 bytes, |
270 bool complete); | 272 bool complete); |
271 void DidOpenFile( | 273 void DidOpenFile(const OperationHandle& handle, |
272 const OperationHandle& handle, | 274 const OpenFileCallback& callback, |
273 const OpenFileCallback& callback, | 275 base::File file, |
274 base::File file, | 276 const base::Closure& on_close_callback); |
275 const base::Closure& on_close_callback); | |
276 void DidCreateSnapshot( | 277 void DidCreateSnapshot( |
277 const OperationHandle& handle, | 278 const OperationHandle& handle, |
278 const SnapshotFileCallback& callback, | 279 const SnapshotFileCallback& callback, |
279 base::File::Error rv, | 280 base::File::Error rv, |
280 const base::File::Info& file_info, | 281 const base::File::Info& file_info, |
281 const base::FilePath& platform_path, | 282 const base::FilePath& platform_path, |
282 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 283 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
283 | 284 |
284 void OnCopyProgress( | 285 void OnCopyProgress(const OperationHandle& handle, |
285 const OperationHandle& handle, | 286 const CopyProgressCallback& callback, |
286 const CopyProgressCallback& callback, | 287 FileSystemOperation::CopyProgressType type, |
287 FileSystemOperation::CopyProgressType type, | 288 const FileSystemURL& source_url, |
288 const FileSystemURL& source_url, | 289 const FileSystemURL& dest_url, |
289 const FileSystemURL& dest_url, | 290 int64 size); |
290 int64 size); | |
291 | 291 |
292 void PrepareForWrite(OperationID id, const FileSystemURL& url); | 292 void PrepareForWrite(OperationID id, const FileSystemURL& url); |
293 void PrepareForRead(OperationID id, const FileSystemURL& url); | 293 void PrepareForRead(OperationID id, const FileSystemURL& url); |
294 | 294 |
295 // These must be called at the beginning and end of any async operations. | 295 // These must be called at the beginning and end of any async operations. |
296 OperationHandle BeginOperation(FileSystemOperation* operation, | 296 OperationHandle BeginOperation(FileSystemOperation* operation, |
297 base::WeakPtr<BeginOperationScoper> scope); | 297 base::WeakPtr<BeginOperationScoper> scope); |
298 void FinishOperation(OperationID id); | 298 void FinishOperation(OperationID id); |
299 | 299 |
300 // Not owned; file_system_context owns this. | 300 // Not owned; file_system_context owns this. |
301 FileSystemContext* file_system_context_; | 301 FileSystemContext* file_system_context_; |
302 | 302 |
303 // IDMap<FileSystemOperation, IDMapOwnPointer> operations_; | 303 // IDMap<FileSystemOperation, IDMapOwnPointer> operations_; |
304 IDMap<FileSystemOperation, IDMapOwnPointer> operations_; | 304 IDMap<FileSystemOperation, IDMapOwnPointer> operations_; |
305 | 305 |
306 // We keep track of the file to be modified by each operation so that | 306 // We keep track of the file to be modified by each operation so that |
307 // we can notify observers when we're done. | 307 // we can notify observers when we're done. |
308 typedef std::map<OperationID, FileSystemURLSet> OperationToURLSet; | 308 typedef std::map<OperationID, FileSystemURLSet> OperationToURLSet; |
309 OperationToURLSet write_target_urls_; | 309 OperationToURLSet write_target_urls_; |
310 | 310 |
311 // Operations that are finished but not yet fire their callbacks. | 311 // Operations that are finished but not yet fire their callbacks. |
312 std::set<OperationID> finished_operations_; | 312 std::set<OperationID> finished_operations_; |
313 | 313 |
314 // Callbacks for stray cancels whose target operation is already finished. | 314 // Callbacks for stray cancels whose target operation is already finished. |
315 std::map<OperationID, StatusCallback> stray_cancel_callbacks_; | 315 std::map<OperationID, StatusCallback> stray_cancel_callbacks_; |
316 | 316 |
317 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunner); | 317 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationRunner); |
318 }; | 318 }; |
319 | 319 |
320 } // namespace fileapi | 320 } // namespace storage |
321 | 321 |
322 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ | 322 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_OPERATION_RUNNER_H_ |
OLD | NEW |