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_BROWSER_FILEAPI_ASYNC_FILE_UTIL_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_H_ | 6 #define WEBKIT_BROWSER_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/memory/scoped_ptr.h" |
11 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
12 #include "webkit/common/fileapi/directory_entry.h" | 13 #include "webkit/common/fileapi/directory_entry.h" |
13 #include "webkit/storage/webkit_storage_export.h" | 14 #include "webkit/storage/webkit_storage_export.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class Time; | 17 class Time; |
17 } | 18 } |
18 | 19 |
19 namespace webkit_blob { | 20 namespace webkit_blob { |
20 class ShareableFileReference; | 21 class ShareableFileReference; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create | 69 // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create |
69 // a new file at the given |url| and calls back with | 70 // a new file at the given |url| and calls back with |
70 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. | 71 // PLATFORM_FILE_ERROR_FILE_EXISTS if the |url| already exists. |
71 // | 72 // |
72 // LocalFileSystemOperation::OpenFile calls this. | 73 // LocalFileSystemOperation::OpenFile calls this. |
73 // This is used only by Pepper/NaCL File API. | 74 // This is used only by Pepper/NaCL File API. |
74 // | 75 // |
75 // This returns false if it fails to post an async task. | 76 // This returns false if it fails to post an async task. |
76 // | 77 // |
77 virtual bool CreateOrOpen( | 78 virtual bool CreateOrOpen( |
78 FileSystemOperationContext* context, | 79 scoped_ptr<FileSystemOperationContext> context, |
79 const FileSystemURL& url, | 80 const FileSystemURL& url, |
80 int file_flags, | 81 int file_flags, |
81 const CreateOrOpenCallback& callback) = 0; | 82 const CreateOrOpenCallback& callback) = 0; |
82 | 83 |
83 // Ensures that the given |url| exist. This creates a empty new file | 84 // Ensures that the given |url| exist. This creates a empty new file |
84 // at |url| if the |url| does not exist. | 85 // at |url| if the |url| does not exist. |
85 // | 86 // |
86 // LocalFileSystemOperation::CreateFile calls this. | 87 // LocalFileSystemOperation::CreateFile calls this. |
87 // | 88 // |
88 // This returns false if it fails to post an async task. | 89 // This returns false if it fails to post an async task. |
89 // | 90 // |
90 // This reports following error code via |callback|: | 91 // This reports following error code via |callback|: |
91 // - PLATFORM_FILE_OK and created==true if a file has not existed and | 92 // - PLATFORM_FILE_OK and created==true if a file has not existed and |
92 // is created at |url|. | 93 // is created at |url|. |
93 // - PLATFORM_FILE_OK and created==false if the file already exists. | 94 // - PLATFORM_FILE_OK and created==false if the file already exists. |
94 // - Other error code (with created=false) if a file hasn't existed yet | 95 // - Other error code (with created=false) if a file hasn't existed yet |
95 // and there was an error while creating a new file. | 96 // and there was an error while creating a new file. |
96 // | 97 // |
97 virtual bool EnsureFileExists( | 98 virtual bool EnsureFileExists( |
98 FileSystemOperationContext* context, | 99 scoped_ptr<FileSystemOperationContext> context, |
99 const FileSystemURL& url, | 100 const FileSystemURL& url, |
100 const EnsureFileExistsCallback& callback) = 0; | 101 const EnsureFileExistsCallback& callback) = 0; |
101 | 102 |
102 // Creates directory at given url. | 103 // Creates directory at given url. |
103 // | 104 // |
104 // LocalFileSystemOperation::CreateDirectory calls this. | 105 // LocalFileSystemOperation::CreateDirectory calls this. |
105 // | 106 // |
106 // This returns false if it fails to post an async task. | 107 // This returns false if it fails to post an async task. |
107 // | 108 // |
108 // This reports following error code via |callback|: | 109 // This reports following error code via |callback|: |
109 // - PLATFORM_FILE_ERROR_NOT_FOUND if the |url|'s parent directory | 110 // - PLATFORM_FILE_ERROR_NOT_FOUND if the |url|'s parent directory |
110 // does not exist and |recursive| is false. | 111 // does not exist and |recursive| is false. |
111 // - PLATFORM_FILE_ERROR_EXISTS if a directory already exists at |url| | 112 // - PLATFORM_FILE_ERROR_EXISTS if a directory already exists at |url| |
112 // and |exclusive| is true. | 113 // and |exclusive| is true. |
113 // - PLATFORM_FILE_ERROR_EXISTS if a file already exists at |url| | 114 // - PLATFORM_FILE_ERROR_EXISTS if a file already exists at |url| |
114 // (regardless of |exclusive| value). | 115 // (regardless of |exclusive| value). |
115 // - Other error code if it failed to create a directory. | 116 // - Other error code if it failed to create a directory. |
116 // | 117 // |
117 virtual bool CreateDirectory( | 118 virtual bool CreateDirectory( |
118 FileSystemOperationContext* context, | 119 scoped_ptr<FileSystemOperationContext> context, |
119 const FileSystemURL& url, | 120 const FileSystemURL& url, |
120 bool exclusive, | 121 bool exclusive, |
121 bool recursive, | 122 bool recursive, |
122 const StatusCallback& callback) = 0; | 123 const StatusCallback& callback) = 0; |
123 | 124 |
124 // Retrieves the information about a file. | 125 // Retrieves the information about a file. |
125 // | 126 // |
126 // LocalFileSystemOperation::GetMetadata calls this. | 127 // LocalFileSystemOperation::GetMetadata calls this. |
127 // | 128 // |
128 // This returns false if it fails to post an async task. | 129 // This returns false if it fails to post an async task. |
129 // | 130 // |
130 // This reports following error code via |callback|: | 131 // This reports following error code via |callback|: |
131 // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist. | 132 // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist. |
132 // - Other error code if there was an error while retrieving the file info. | 133 // - Other error code if there was an error while retrieving the file info. |
133 // | 134 // |
134 virtual bool GetFileInfo( | 135 virtual bool GetFileInfo( |
135 FileSystemOperationContext* context, | 136 scoped_ptr<FileSystemOperationContext> context, |
136 const FileSystemURL& url, | 137 const FileSystemURL& url, |
137 const GetFileInfoCallback& callback) = 0; | 138 const GetFileInfoCallback& callback) = 0; |
138 | 139 |
139 // Reads contents of a directory at |path|. | 140 // Reads contents of a directory at |path|. |
140 // | 141 // |
141 // LocalFileSystemOperation::ReadDirectory calls this. | 142 // LocalFileSystemOperation::ReadDirectory calls this. |
142 // | 143 // |
143 // Note that the |name| field of each entry in |file_list| | 144 // Note that the |name| field of each entry in |file_list| |
144 // returned by |callback| should have a base file name | 145 // returned by |callback| should have a base file name |
145 // of the entry relative to the directory, but not an absolute path. | 146 // of the entry relative to the directory, but not an absolute path. |
146 // | 147 // |
147 // (E.g. if ReadDirectory is called for a directory | 148 // (E.g. if ReadDirectory is called for a directory |
148 // 'path/to/dir' and the directory has entries 'a' and 'b', | 149 // 'path/to/dir' and the directory has entries 'a' and 'b', |
149 // the returned |file_list| should include entries whose names | 150 // the returned |file_list| should include entries whose names |
150 // are 'a' and 'b', but not '/path/to/dir/a' and '/path/to/dir/b'.) | 151 // are 'a' and 'b', but not '/path/to/dir/a' and '/path/to/dir/b'.) |
151 // | 152 // |
152 // This returns false if it fails to post an async task. | 153 // This returns false if it fails to post an async task. |
153 // | 154 // |
154 // This reports following error code via |callback|: | 155 // This reports following error code via |callback|: |
155 // - PLATFORM_FILE_ERROR_NOT_FOUND if the target directory doesn't exist. | 156 // - PLATFORM_FILE_ERROR_NOT_FOUND if the target directory doesn't exist. |
156 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if an entry exists at |url| but | 157 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if an entry exists at |url| but |
157 // is a file (not a directory). | 158 // is a file (not a directory). |
158 // | 159 // |
159 virtual bool ReadDirectory( | 160 virtual bool ReadDirectory( |
160 FileSystemOperationContext* context, | 161 scoped_ptr<FileSystemOperationContext> context, |
161 const FileSystemURL& url, | 162 const FileSystemURL& url, |
162 const ReadDirectoryCallback& callback) = 0; | 163 const ReadDirectoryCallback& callback) = 0; |
163 | 164 |
164 // Modifies timestamps of a file or directory at |url| with | 165 // Modifies timestamps of a file or directory at |url| with |
165 // |last_access_time| and |last_modified_time|. The function DOES NOT | 166 // |last_access_time| and |last_modified_time|. The function DOES NOT |
166 // create a file unlike 'touch' command on Linux. | 167 // create a file unlike 'touch' command on Linux. |
167 // | 168 // |
168 // LocalFileSystemOperation::TouchFile calls this. | 169 // LocalFileSystemOperation::TouchFile calls this. |
169 // This is used only by Pepper/NaCL File API. | 170 // This is used only by Pepper/NaCL File API. |
170 // | 171 // |
171 // This returns false if it fails to post an async task. | 172 // This returns false if it fails to post an async task. |
172 virtual bool Touch( | 173 virtual bool Touch( |
173 FileSystemOperationContext* context, | 174 scoped_ptr<FileSystemOperationContext> context, |
174 const FileSystemURL& url, | 175 const FileSystemURL& url, |
175 const base::Time& last_access_time, | 176 const base::Time& last_access_time, |
176 const base::Time& last_modified_time, | 177 const base::Time& last_modified_time, |
177 const StatusCallback& callback) = 0; | 178 const StatusCallback& callback) = 0; |
178 | 179 |
179 // Truncates a file at |path| to |length|. If |length| is larger than | 180 // Truncates a file at |path| to |length|. If |length| is larger than |
180 // the original file size, the file will be extended, and the extended | 181 // the original file size, the file will be extended, and the extended |
181 // part is filled with null bytes. | 182 // part is filled with null bytes. |
182 // | 183 // |
183 // LocalFileSystemOperation::Truncate calls this. | 184 // LocalFileSystemOperation::Truncate calls this. |
184 // | 185 // |
185 // This returns false if it fails to post an async task. | 186 // This returns false if it fails to post an async task. |
186 // | 187 // |
187 // This reports following error code via |callback|: | 188 // This reports following error code via |callback|: |
188 // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist. | 189 // - PLATFORM_FILE_ERROR_NOT_FOUND if the file doesn't exist. |
189 // | 190 // |
190 virtual bool Truncate( | 191 virtual bool Truncate( |
191 FileSystemOperationContext* context, | 192 scoped_ptr<FileSystemOperationContext> context, |
192 const FileSystemURL& url, | 193 const FileSystemURL& url, |
193 int64 length, | 194 int64 length, |
194 const StatusCallback& callback) = 0; | 195 const StatusCallback& callback) = 0; |
195 | 196 |
196 // Copies a file from |src_url| to |dest_url|. | 197 // Copies a file from |src_url| to |dest_url|. |
197 // This must be called for files that belong to the same filesystem | 198 // This must be called for files that belong to the same filesystem |
198 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 199 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
199 // | 200 // |
200 // LocalFileSystemOperation::Copy calls this for same-filesystem copy case. | 201 // LocalFileSystemOperation::Copy calls this for same-filesystem copy case. |
201 // | 202 // |
202 // This returns false if it fails to post an async task. | 203 // This returns false if it fails to post an async task. |
203 // | 204 // |
204 // This reports following error code via |callback|: | 205 // This reports following error code via |callback|: |
205 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 206 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
206 // or the parent directory of |dest_url| does not exist. | 207 // or the parent directory of |dest_url| does not exist. |
207 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 208 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
208 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 209 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
209 // is not a file. | 210 // is not a file. |
210 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 211 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
211 // its parent path is a file. | 212 // its parent path is a file. |
212 // | 213 // |
213 virtual bool CopyFileLocal( | 214 virtual bool CopyFileLocal( |
214 FileSystemOperationContext* context, | 215 scoped_ptr<FileSystemOperationContext> context, |
215 const FileSystemURL& src_url, | 216 const FileSystemURL& src_url, |
216 const FileSystemURL& dest_url, | 217 const FileSystemURL& dest_url, |
217 const StatusCallback& callback) = 0; | 218 const StatusCallback& callback) = 0; |
218 | 219 |
219 // Moves a local file from |src_url| to |dest_url|. | 220 // Moves a local file from |src_url| to |dest_url|. |
220 // This must be called for files that belong to the same filesystem | 221 // This must be called for files that belong to the same filesystem |
221 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). | 222 // (i.e. type() and origin() of the |src_url| and |dest_url| must match). |
222 // | 223 // |
223 // LocalFileSystemOperation::Move calls this for same-filesystem move case. | 224 // LocalFileSystemOperation::Move calls this for same-filesystem move case. |
224 // | 225 // |
225 // This returns false if it fails to post an async task. | 226 // This returns false if it fails to post an async task. |
226 // | 227 // |
227 // This reports following error code via |callback|: | 228 // This reports following error code via |callback|: |
228 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| | 229 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
229 // or the parent directory of |dest_url| does not exist. | 230 // or the parent directory of |dest_url| does not exist. |
230 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. | 231 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
231 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 232 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
232 // is not a file. | 233 // is not a file. |
233 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 234 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
234 // its parent path is a file. | 235 // its parent path is a file. |
235 // | 236 // |
236 virtual bool MoveFileLocal( | 237 virtual bool MoveFileLocal( |
237 FileSystemOperationContext* context, | 238 scoped_ptr<FileSystemOperationContext> context, |
238 const FileSystemURL& src_url, | 239 const FileSystemURL& src_url, |
239 const FileSystemURL& dest_url, | 240 const FileSystemURL& dest_url, |
240 const StatusCallback& callback) = 0; | 241 const StatusCallback& callback) = 0; |
241 | 242 |
242 // Copies in a single file from a different filesystem. | 243 // Copies in a single file from a different filesystem. |
243 // | 244 // |
244 // LocalFileSystemOperation::Copy or Move calls this for cross-filesystem | 245 // LocalFileSystemOperation::Copy or Move calls this for cross-filesystem |
245 // cases. | 246 // cases. |
246 // | 247 // |
247 // This returns false if it fails to post an async task. | 248 // This returns false if it fails to post an async task. |
248 // | 249 // |
249 // This reports following error code via |callback|: | 250 // This reports following error code via |callback|: |
250 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path| | 251 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_file_path| |
251 // or the parent directory of |dest_url| does not exist. | 252 // or the parent directory of |dest_url| does not exist. |
252 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and | 253 // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
253 // is not a file. | 254 // is not a file. |
254 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and | 255 // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
255 // its parent path is a file. | 256 // its parent path is a file. |
256 // | 257 // |
257 virtual bool CopyInForeignFile( | 258 virtual bool CopyInForeignFile( |
258 FileSystemOperationContext* context, | 259 scoped_ptr<FileSystemOperationContext> context, |
259 const base::FilePath& src_file_path, | 260 const base::FilePath& src_file_path, |
260 const FileSystemURL& dest_url, | 261 const FileSystemURL& dest_url, |
261 const StatusCallback& callback) = 0; | 262 const StatusCallback& callback) = 0; |
262 | 263 |
263 // Deletes a single file. | 264 // Deletes a single file. |
264 // | 265 // |
265 // LocalFileSystemOperation::RemoveFile calls this. | 266 // LocalFileSystemOperation::RemoveFile calls this. |
266 // | 267 // |
267 // This returns false if it fails to post an async task. | 268 // This returns false if it fails to post an async task. |
268 // | 269 // |
269 // This reports following error code via |callback|: | 270 // This reports following error code via |callback|: |
270 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 271 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
271 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file. | 272 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| is not a file. |
272 // | 273 // |
273 virtual bool DeleteFile( | 274 virtual bool DeleteFile( |
274 FileSystemOperationContext* context, | 275 scoped_ptr<FileSystemOperationContext> context, |
275 const FileSystemURL& url, | 276 const FileSystemURL& url, |
276 const StatusCallback& callback) = 0; | 277 const StatusCallback& callback) = 0; |
277 | 278 |
278 // Removes a single empty directory. | 279 // Removes a single empty directory. |
279 // | 280 // |
280 // LocalFileSystemOperation::RemoveDirectory calls this. | 281 // LocalFileSystemOperation::RemoveDirectory calls this. |
281 // | 282 // |
282 // This returns false if it fails to post an async task. | 283 // This returns false if it fails to post an async task. |
283 // | 284 // |
284 // This reports following error code via |callback|: | 285 // This reports following error code via |callback|: |
285 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 286 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
286 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. | 287 // - PLATFORM_FILE_ERROR_NOT_A_DIRECTORY if |url| is not a directory. |
287 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. | 288 // - PLATFORM_FILE_ERROR_NOT_EMPTY if |url| is not empty. |
288 // | 289 // |
289 virtual bool DeleteDirectory( | 290 virtual bool DeleteDirectory( |
290 FileSystemOperationContext* context, | 291 scoped_ptr<FileSystemOperationContext> context, |
291 const FileSystemURL& url, | 292 const FileSystemURL& url, |
292 const StatusCallback& callback) = 0; | 293 const StatusCallback& callback) = 0; |
293 | 294 |
294 // Creates a local snapshot file for a given |url| and returns the | 295 // Creates a local snapshot file for a given |url| and returns the |
295 // metadata and platform path of the snapshot file via |callback|. | 296 // metadata and platform path of the snapshot file via |callback|. |
296 // In regular filesystem cases the implementation may simply return | 297 // In regular filesystem cases the implementation may simply return |
297 // the metadata of the file itself (as well as GetMetadata does), | 298 // the metadata of the file itself (as well as GetMetadata does), |
298 // while in non-regular filesystem case the backend may create a | 299 // while in non-regular filesystem case the backend may create a |
299 // temporary snapshot file which holds the file data and return | 300 // temporary snapshot file which holds the file data and return |
300 // the metadata of the temporary file. | 301 // the metadata of the temporary file. |
(...skipping 17 matching lines...) Expand all Loading... |
318 // This returns false if it fails to post an async task. | 319 // This returns false if it fails to post an async task. |
319 // | 320 // |
320 // This reports following error code via |callback|: | 321 // This reports following error code via |callback|: |
321 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. | 322 // - PLATFORM_FILE_ERROR_NOT_FOUND if |url| does not exist. |
322 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| exists but is a directory. | 323 // - PLATFORM_FILE_ERROR_NOT_A_FILE if |url| exists but is a directory. |
323 // | 324 // |
324 // The field values of |file_info| are undefined (implementation | 325 // The field values of |file_info| are undefined (implementation |
325 // dependent) in error cases, and the caller should always | 326 // dependent) in error cases, and the caller should always |
326 // check the return code. | 327 // check the return code. |
327 virtual bool CreateSnapshotFile( | 328 virtual bool CreateSnapshotFile( |
328 FileSystemOperationContext* context, | 329 scoped_ptr<FileSystemOperationContext> context, |
329 const FileSystemURL& url, | 330 const FileSystemURL& url, |
330 const CreateSnapshotFileCallback& callback) = 0; | 331 const CreateSnapshotFileCallback& callback) = 0; |
331 | 332 |
332 private: | 333 private: |
333 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil); | 334 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil); |
334 }; | 335 }; |
335 | 336 |
336 } // namespace fileapi | 337 } // namespace fileapi |
337 | 338 |
338 #endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_H_ | 339 #endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_H_ |
OLD | NEW |