| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_MEDIA_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_ | |
| 6 #define WEBKIT_FILEAPI_MEDIA_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_ | |
| 7 | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/platform_file.h" | |
| 11 #include "webkit/fileapi/async_file_util.h" | |
| 12 #include "webkit/storage/webkit_storage_export.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class Time; | |
| 16 } | |
| 17 | |
| 18 namespace fileapi { | |
| 19 | |
| 20 class FileSystemOperationContext; | |
| 21 class FileSystemURL; | |
| 22 | |
| 23 class WEBKIT_STORAGE_EXPORT_PRIVATE DeviceMediaAsyncFileUtil | |
| 24 : public AsyncFileUtil { | |
| 25 public: | |
| 26 virtual ~DeviceMediaAsyncFileUtil(); | |
| 27 | |
| 28 // Returns an instance of DeviceMediaAsyncFileUtil. Returns NULL if | |
| 29 // asynchronous operation is not supported. Callers own the returned | |
| 30 // object. | |
| 31 static DeviceMediaAsyncFileUtil* Create(const base::FilePath& profile_path); | |
| 32 | |
| 33 // AsyncFileUtil overrides. | |
| 34 virtual bool CreateOrOpen( | |
| 35 FileSystemOperationContext* context, | |
| 36 const FileSystemURL& url, | |
| 37 int file_flags, | |
| 38 const CreateOrOpenCallback& callback) OVERRIDE; | |
| 39 virtual bool EnsureFileExists( | |
| 40 FileSystemOperationContext* context, | |
| 41 const FileSystemURL& url, | |
| 42 const EnsureFileExistsCallback& callback) OVERRIDE; | |
| 43 virtual bool CreateDirectory( | |
| 44 FileSystemOperationContext* context, | |
| 45 const FileSystemURL& url, | |
| 46 bool exclusive, | |
| 47 bool recursive, | |
| 48 const StatusCallback& callback) OVERRIDE; | |
| 49 virtual bool GetFileInfo( | |
| 50 FileSystemOperationContext* context, | |
| 51 const FileSystemURL& url, | |
| 52 const GetFileInfoCallback& callback) OVERRIDE; | |
| 53 virtual bool ReadDirectory( | |
| 54 FileSystemOperationContext* context, | |
| 55 const FileSystemURL& url, | |
| 56 const ReadDirectoryCallback& callback) OVERRIDE; | |
| 57 virtual bool Touch( | |
| 58 FileSystemOperationContext* context, | |
| 59 const FileSystemURL& url, | |
| 60 const base::Time& last_access_time, | |
| 61 const base::Time& last_modified_time, | |
| 62 const StatusCallback& callback) OVERRIDE; | |
| 63 virtual bool Truncate( | |
| 64 FileSystemOperationContext* context, | |
| 65 const FileSystemURL& url, | |
| 66 int64 length, | |
| 67 const StatusCallback& callback) OVERRIDE; | |
| 68 virtual bool CopyFileLocal( | |
| 69 FileSystemOperationContext* context, | |
| 70 const FileSystemURL& src_url, | |
| 71 const FileSystemURL& dest_url, | |
| 72 const StatusCallback& callback) OVERRIDE; | |
| 73 virtual bool MoveFileLocal( | |
| 74 FileSystemOperationContext* context, | |
| 75 const FileSystemURL& src_url, | |
| 76 const FileSystemURL& dest_url, | |
| 77 const StatusCallback& callback) OVERRIDE; | |
| 78 virtual bool CopyInForeignFile( | |
| 79 FileSystemOperationContext* context, | |
| 80 const base::FilePath& src_file_path, | |
| 81 const FileSystemURL& dest_url, | |
| 82 const StatusCallback& callback) OVERRIDE; | |
| 83 virtual bool DeleteFile( | |
| 84 FileSystemOperationContext* context, | |
| 85 const FileSystemURL& url, | |
| 86 const StatusCallback& callback) OVERRIDE; | |
| 87 virtual bool DeleteDirectory( | |
| 88 FileSystemOperationContext* context, | |
| 89 const FileSystemURL& url, | |
| 90 const StatusCallback& callback) OVERRIDE; | |
| 91 virtual bool CreateSnapshotFile( | |
| 92 FileSystemOperationContext* context, | |
| 93 const FileSystemURL& url, | |
| 94 const CreateSnapshotFileCallback& callback) OVERRIDE; | |
| 95 | |
| 96 private: | |
| 97 // Use Create() to get an instance of DeviceMediaAsyncFileUtil. | |
| 98 explicit DeviceMediaAsyncFileUtil(const base::FilePath& profile_path); | |
| 99 | |
| 100 // Called when GetFileInfo method call succeeds. |file_info| | |
| 101 // contains the |platform_path| file details. |callback| is invoked | |
| 102 // to complete the GetFileInfo request. | |
| 103 void OnDidGetFileInfo( | |
| 104 const AsyncFileUtil::GetFileInfoCallback& callback, | |
| 105 const base::FilePath& platform_path, | |
| 106 const base::PlatformFileInfo& file_info); | |
| 107 | |
| 108 // Called when GetFileInfo method call failed to get the details of file | |
| 109 // specified by the |platform_path|. |callback| is invoked to notify the | |
| 110 // caller about the platform file |error|. | |
| 111 void OnGetFileInfoError( | |
| 112 const AsyncFileUtil::GetFileInfoCallback& callback, | |
| 113 const base::FilePath& platform_path, | |
| 114 base::PlatformFileError error); | |
| 115 | |
| 116 // Called when ReadDirectory method call succeeds. |callback| is invoked to | |
| 117 // complete the ReadDirectory request. | |
| 118 // | |
| 119 // If the contents of the given directory are reported in one batch, then | |
| 120 // |file_list| will have the list of all files/directories in the given | |
| 121 // directory and |has_more| will be false. | |
| 122 // | |
| 123 // If the contents of the given directory are reported in multiple chunks, | |
| 124 // |file_list| will have only a subset of all contents (the subsets reported | |
| 125 // in any two calls are disjoint), and |has_more| will be true, except for | |
| 126 // the last chunk. | |
| 127 void OnDidReadDirectory( | |
| 128 const AsyncFileUtil::ReadDirectoryCallback& callback, | |
| 129 const AsyncFileUtil::EntryList& file_list, | |
| 130 bool has_more); | |
| 131 | |
| 132 // Called when ReadDirectory method call failed to enumerate the directory | |
| 133 // objects. |callback| is invoked to notify the caller about the |error| | |
| 134 // that occured while reading the directory objects. | |
| 135 void OnReadDirectoryError( | |
| 136 const AsyncFileUtil::ReadDirectoryCallback& callback, | |
| 137 base::PlatformFileError error); | |
| 138 | |
| 139 // Called when the snapshot file specified by the |platform_path| is | |
| 140 // successfully created. |file_info| contains the device media file details | |
| 141 // for which the snapshot file is created. |callback| is invoked to complete | |
| 142 // the CreateSnapshotFile request. | |
| 143 void OnDidCreateSnapshotFile( | |
| 144 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 145 const base::PlatformFileInfo& file_info, | |
| 146 const base::FilePath& platform_path); | |
| 147 | |
| 148 // Called when CreateSnapshotFile method call fails. |callback| is invoked to | |
| 149 // notify the caller about the |error|. | |
| 150 void OnCreateSnapshotFileError( | |
| 151 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 152 base::PlatformFileError error); | |
| 153 | |
| 154 // Called when the snapshot file specified by the |snapshot_file_path| is | |
| 155 // created to hold the contents of the |device_file_path|. If the snapshot | |
| 156 // file is successfully created, |snapshot_file_path| will be an non-empty | |
| 157 // file path. In case of failure, |snapshot_file_path| will be an empty file | |
| 158 // path. Forwards the CreateSnapshot request to the delegate to copy the | |
| 159 // contents of |device_file_path| to |snapshot_file_path|. | |
| 160 void OnSnapshotFileCreatedRunTask( | |
| 161 FileSystemOperationContext* context, | |
| 162 const AsyncFileUtil::CreateSnapshotFileCallback& callback, | |
| 163 const base::FilePath& device_file_path, | |
| 164 base::FilePath* snapshot_file_path); | |
| 165 | |
| 166 // Profile path. | |
| 167 const base::FilePath profile_path_; | |
| 168 | |
| 169 // For callbacks that may run after destruction. | |
| 170 base::WeakPtrFactory<DeviceMediaAsyncFileUtil> weak_ptr_factory_; | |
| 171 | |
| 172 DISALLOW_COPY_AND_ASSIGN(DeviceMediaAsyncFileUtil); | |
| 173 }; | |
| 174 | |
| 175 } // namespace fileapi | |
| 176 | |
| 177 #endif // WEBKIT_FILEAPI_MEDIA_DEVICE_MEDIA_ASYNC_FILE_UTIL_H_ | |
| OLD | NEW |