| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_FILEAPI_ASYNC_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_ |
| 6 #define WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/files/file_util_proxy.h" | 10 #include "base/files/file_util_proxy.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "webkit/fileapi/file_snapshot_policy.h" | |
| 13 #include "webkit/storage/webkit_storage_export.h" | 12 #include "webkit/storage/webkit_storage_export.h" |
| 14 | 13 |
| 15 namespace base { | 14 namespace base { |
| 16 class Time; | 15 class Time; |
| 17 } | 16 } |
| 18 | 17 |
| 18 namespace webkit_blob { |
| 19 class ShareableFileReference; |
| 20 } |
| 21 |
| 19 namespace fileapi { | 22 namespace fileapi { |
| 20 | 23 |
| 21 class FileSystemOperationContext; | 24 class FileSystemOperationContext; |
| 22 class FileSystemURL; | 25 class FileSystemURL; |
| 23 | 26 |
| 24 // An interface which provides filesystem-specific file operations for | 27 // An interface which provides filesystem-specific file operations for |
| 25 // LocalFileSystemOperation. | 28 // LocalFileSystemOperation. |
| 26 // | 29 // |
| 27 // Each filesystem which needs to be dispatched from LocalFileSystemOperation | 30 // Each filesystem which needs to be dispatched from LocalFileSystemOperation |
| 28 // must implement this interface or a synchronous version of interface: | 31 // must implement this interface or a synchronous version of interface: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 typedef std::vector<base::FileUtilProxy::Entry> EntryList; | 51 typedef std::vector<base::FileUtilProxy::Entry> EntryList; |
| 49 typedef base::Callback< | 52 typedef base::Callback< |
| 50 void(base::PlatformFileError result, | 53 void(base::PlatformFileError result, |
| 51 const EntryList& file_list, | 54 const EntryList& file_list, |
| 52 bool has_more)> ReadDirectoryCallback; | 55 bool has_more)> ReadDirectoryCallback; |
| 53 | 56 |
| 54 typedef base::Callback< | 57 typedef base::Callback< |
| 55 void(base::PlatformFileError result, | 58 void(base::PlatformFileError result, |
| 56 const base::PlatformFileInfo& file_info, | 59 const base::PlatformFileInfo& file_info, |
| 57 const base::FilePath& platform_path, | 60 const base::FilePath& platform_path, |
| 58 SnapshotFilePolicy policy)> CreateSnapshotFileCallback; | 61 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref |
| 62 )> CreateSnapshotFileCallback; |
| 59 | 63 |
| 60 AsyncFileUtil() {} | 64 AsyncFileUtil() {} |
| 61 virtual ~AsyncFileUtil() {} | 65 virtual ~AsyncFileUtil() {} |
| 62 | 66 |
| 63 // Creates or opens a file with the given flags. | 67 // Creates or opens a file with the given flags. |
| 64 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 68 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
| 65 // a new file at the given |url| and calls back with | 69 // a new file at the given |url| and calls back with |
| 66 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. | 70 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. |
| 67 // | 71 // |
| 68 // LocalFileSystemOperation::OpenFile calls this. | 72 // LocalFileSystemOperation::OpenFile calls this. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // metadata and platform path of the snapshot file via |callback|. | 286 // metadata and platform path of the snapshot file via |callback|. |
| 283 // In regular filesystem cases the implementation may simply return | 287 // In regular filesystem cases the implementation may simply return |
| 284 // the metadata of the file itself (as well as GetMetadata does), | 288 // the metadata of the file itself (as well as GetMetadata does), |
| 285 // while in non-regular filesystem case the backend may create a | 289 // while in non-regular filesystem case the backend may create a |
| 286 // temporary snapshot file which holds the file data and return | 290 // temporary snapshot file which holds the file data and return |
| 287 // the metadata of the temporary file. | 291 // the metadata of the temporary file. |
| 288 // | 292 // |
| 289 // In the callback, it returns: | 293 // In the callback, it returns: |
| 290 // |file_info| is the metadata of the snapshot file created. | 294 // |file_info| is the metadata of the snapshot file created. |
| 291 // |platform_path| is the path to the snapshot file created. | 295 // |platform_path| is the path to the snapshot file created. |
| 292 // |policy| should indicate the policy how the fileapi backend | 296 // |
| 293 // should handle the returned file. | 297 // If implementors creates a temporary file for snapshotting and wants |
| 298 // FileAPI backend to take care of the lifetime of the file (so that |
| 299 // it won't get deleted while JS layer has any references to the created |
| 300 // File/Blob object), it should return non-empty |file_ref|. |
| 301 // Via the |file_ref| implementors can schedule a file deletion |
| 302 // or arbitrary callbacks when the last reference of File/Blob is dropped. |
| 294 // | 303 // |
| 295 // LocalFileSystemOperation::CreateSnapshotFile calls this. | 304 // LocalFileSystemOperation::CreateSnapshotFile calls this. |
| 296 // | 305 // |
| 297 // This returns false if it fails to post an async task. | 306 // This returns false if it fails to post an async task. |
| 298 // | 307 // |
| 299 // This reports following error code via |callback|: | 308 // This reports following error code via |callback|: |
| 300 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 309 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
| 301 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| exists but is a directory. | 310 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| exists but is a directory. |
| 302 // | 311 // |
| 303 // The field values of |file_info| are undefined (implementation | 312 // The field values of |file_info| are undefined (implementation |
| 304 // dependent) in error cases, and the caller should always | 313 // dependent) in error cases, and the caller should always |
| 305 // check the return code. | 314 // check the return code. |
| 306 virtual bool CreateSnapshotFile( | 315 virtual bool CreateSnapshotFile( |
| 307 FileSystemOperationContext* context, | 316 FileSystemOperationContext* context, |
| 308 const FileSystemURL& url, | 317 const FileSystemURL& url, |
| 309 const CreateSnapshotFileCallback& callback) = 0; | 318 const CreateSnapshotFileCallback& callback) = 0; |
| 310 | 319 |
| 311 private: | 320 private: |
| 312 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil); | 321 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil); |
| 313 }; | 322 }; |
| 314 | 323 |
| 315 } // namespace fileapi | 324 } // namespace fileapi |
| 316 | 325 |
| 317 #endif // WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_ | 326 #endif // WEBKIT_FILEAPI_ASYNC_FILE_UTIL_H_ |
| OLD | NEW |