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_OBFUSCATED_FILE_UTIL_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util_proxy.h" | 16 #include "base/files/file_util_proxy.h" |
17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/platform_file.h" | |
20 #include "webkit/browser/fileapi/file_system_file_util.h" | 19 #include "webkit/browser/fileapi/file_system_file_util.h" |
21 #include "webkit/browser/fileapi/file_system_url.h" | 20 #include "webkit/browser/fileapi/file_system_url.h" |
22 #include "webkit/browser/fileapi/sandbox_directory_database.h" | 21 #include "webkit/browser/fileapi/sandbox_directory_database.h" |
23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 22 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
24 #include "webkit/browser/webkit_storage_browser_export.h" | 23 #include "webkit/browser/webkit_storage_browser_export.h" |
25 #include "webkit/common/blob/shareable_file_reference.h" | 24 #include "webkit/common/blob/shareable_file_reference.h" |
26 #include "webkit/common/fileapi/file_system_types.h" | 25 #include "webkit/common/fileapi/file_system_types.h" |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 quota::SpecialStoragePolicy* special_storage_policy, | 105 quota::SpecialStoragePolicy* special_storage_policy, |
107 const base::FilePath& file_system_directory, | 106 const base::FilePath& file_system_directory, |
108 leveldb::Env* env_override, | 107 leveldb::Env* env_override, |
109 base::SequencedTaskRunner* file_task_runner, | 108 base::SequencedTaskRunner* file_task_runner, |
110 const GetTypeStringForURLCallback& get_type_string_for_url, | 109 const GetTypeStringForURLCallback& get_type_string_for_url, |
111 const std::set<std::string>& known_type_strings, | 110 const std::set<std::string>& known_type_strings, |
112 SandboxFileSystemBackendDelegate* sandbox_delegate); | 111 SandboxFileSystemBackendDelegate* sandbox_delegate); |
113 virtual ~ObfuscatedFileUtil(); | 112 virtual ~ObfuscatedFileUtil(); |
114 | 113 |
115 // FileSystemFileUtil overrides. | 114 // FileSystemFileUtil overrides. |
116 virtual base::File::Error CreateOrOpen( | 115 virtual base::File CreateOrOpen( |
117 FileSystemOperationContext* context, | 116 FileSystemOperationContext* context, |
118 const FileSystemURL& url, | 117 const FileSystemURL& url, |
119 int file_flags, | 118 int file_flags) OVERRIDE; |
120 base::PlatformFile* file_handle, | |
121 bool* created) OVERRIDE; | |
122 virtual base::File::Error Close( | |
123 FileSystemOperationContext* context, | |
124 base::PlatformFile file) OVERRIDE; | |
125 virtual base::File::Error EnsureFileExists( | 119 virtual base::File::Error EnsureFileExists( |
126 FileSystemOperationContext* context, | 120 FileSystemOperationContext* context, |
127 const FileSystemURL& url, bool* created) OVERRIDE; | 121 const FileSystemURL& url, bool* created) OVERRIDE; |
128 virtual base::File::Error CreateDirectory( | 122 virtual base::File::Error CreateDirectory( |
129 FileSystemOperationContext* context, | 123 FileSystemOperationContext* context, |
130 const FileSystemURL& url, | 124 const FileSystemURL& url, |
131 bool exclusive, | 125 bool exclusive, |
132 bool recursive) OVERRIDE; | 126 bool recursive) OVERRIDE; |
133 virtual base::File::Error GetFileInfo( | 127 virtual base::File::Error GetFileInfo( |
134 FileSystemOperationContext* context, | 128 FileSystemOperationContext* context, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 const FileSystemURL& url, | 256 const FileSystemURL& url, |
263 FileId file_id, | 257 FileId file_id, |
264 FileInfo* local_info, | 258 FileInfo* local_info, |
265 base::File::Info* file_info, | 259 base::File::Info* file_info, |
266 base::FilePath* platform_file_path); | 260 base::FilePath* platform_file_path); |
267 | 261 |
268 // Creates a new file, both the underlying backing file and the entry in the | 262 // Creates a new file, both the underlying backing file and the entry in the |
269 // database. |dest_file_info| is an in-out parameter. Supply the name and | 263 // database. |dest_file_info| is an in-out parameter. Supply the name and |
270 // parent_id; data_path is ignored. On success, data_path will | 264 // parent_id; data_path is ignored. On success, data_path will |
271 // always be set to the relative path [from the root of the type-specific | 265 // always be set to the relative path [from the root of the type-specific |
272 // filesystem directory] of a NEW backing file, and handle, if supplied, will | 266 // filesystem directory] of a NEW backing file. Returns the new file. |
273 // hold open PlatformFile for the backing file, which the caller is | 267 base::File CreateAndOpenFile( |
274 // responsible for closing. If you supply a path in |source_path|, it will be | 268 FileSystemOperationContext* context, |
275 // used as a source from which to COPY data. | 269 const FileSystemURL& dest_url, |
276 // Caveat: do not supply handle if you're also supplying a data path. It was | 270 FileInfo* dest_file_info, |
277 // easier not to support this, and no code has needed it so far, so it will | 271 int file_flags); |
278 // DCHECK and handle will hold base::kInvalidPlatformFileValue. | 272 |
| 273 // The same as CreateAndOpenFile except that a file is not returned and if a |
| 274 // path is provided in |source_path|, it will be used as a source from which |
| 275 // to COPY data. |
279 base::File::Error CreateFile( | 276 base::File::Error CreateFile( |
280 FileSystemOperationContext* context, | 277 FileSystemOperationContext* context, |
281 const base::FilePath& source_file_path, | 278 const base::FilePath& source_file_path, |
282 const FileSystemURL& dest_url, | 279 const FileSystemURL& dest_url, |
283 FileInfo* dest_file_info, | 280 FileInfo* dest_file_info); |
284 int file_flags, | 281 |
285 base::PlatformFile* handle); | 282 // Updates |db| and |dest_file_info| at the end of creating a new file. |
| 283 base::File::Error CommitCreateFile( |
| 284 const base::FilePath& root, |
| 285 const base::FilePath& local_path, |
| 286 SandboxDirectoryDatabase* db, |
| 287 FileInfo* dest_file_info); |
286 | 288 |
287 // This converts from a relative path [as is stored in the FileInfo.data_path | 289 // This converts from a relative path [as is stored in the FileInfo.data_path |
288 // field] to an absolute platform path that can be given to the native | 290 // field] to an absolute platform path that can be given to the native |
289 // filesystem. | 291 // filesystem. |
290 base::FilePath DataPathToLocalPath( | 292 base::FilePath DataPathToLocalPath( |
291 const FileSystemURL& url, | 293 const FileSystemURL& url, |
292 const base::FilePath& data_file_path); | 294 const base::FilePath& data_file_path); |
293 | 295 |
294 std::string GetDirectoryDatabaseKey(const GURL& origin, | 296 std::string GetDirectoryDatabaseKey(const GURL& origin, |
295 const std::string& type_string); | 297 const std::string& type_string); |
(...skipping 18 matching lines...) Expand all Loading... |
314 void DropDatabases(); | 316 void DropDatabases(); |
315 | 317 |
316 // Initializes the origin database. |origin_hint| may be used as a hint | 318 // Initializes the origin database. |origin_hint| may be used as a hint |
317 // for initializing database if it's not empty. | 319 // for initializing database if it's not empty. |
318 bool InitOriginDatabase(const GURL& origin_hint, bool create); | 320 bool InitOriginDatabase(const GURL& origin_hint, bool create); |
319 | 321 |
320 base::File::Error GenerateNewLocalPath( | 322 base::File::Error GenerateNewLocalPath( |
321 SandboxDirectoryDatabase* db, | 323 SandboxDirectoryDatabase* db, |
322 FileSystemOperationContext* context, | 324 FileSystemOperationContext* context, |
323 const FileSystemURL& url, | 325 const FileSystemURL& url, |
| 326 base::FilePath* root, |
324 base::FilePath* local_path); | 327 base::FilePath* local_path); |
325 | 328 |
326 base::File::Error CreateOrOpenInternal( | 329 base::File CreateOrOpenInternal( |
327 FileSystemOperationContext* context, | 330 FileSystemOperationContext* context, |
328 const FileSystemURL& url, | 331 const FileSystemURL& url, |
329 int file_flags, | 332 int file_flags); |
330 base::PlatformFile* file_handle, | |
331 bool* created); | |
332 | 333 |
333 bool HasIsolatedStorage(const GURL& origin); | 334 bool HasIsolatedStorage(const GURL& origin); |
334 | 335 |
335 typedef std::map<std::string, SandboxDirectoryDatabase*> DirectoryMap; | 336 typedef std::map<std::string, SandboxDirectoryDatabase*> DirectoryMap; |
336 DirectoryMap directories_; | 337 DirectoryMap directories_; |
337 scoped_ptr<SandboxOriginDatabaseInterface> origin_database_; | 338 scoped_ptr<SandboxOriginDatabaseInterface> origin_database_; |
338 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 339 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
339 base::FilePath file_system_directory_; | 340 base::FilePath file_system_directory_; |
340 leveldb::Env* env_override_; | 341 leveldb::Env* env_override_; |
341 | 342 |
342 // Used to delete database after a certain period of inactivity. | 343 // Used to delete database after a certain period of inactivity. |
343 int64 db_flush_delay_seconds_; | 344 int64 db_flush_delay_seconds_; |
344 | 345 |
345 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 346 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
346 scoped_ptr<TimedTaskHelper> timer_; | 347 scoped_ptr<TimedTaskHelper> timer_; |
347 | 348 |
348 GetTypeStringForURLCallback get_type_string_for_url_; | 349 GetTypeStringForURLCallback get_type_string_for_url_; |
349 std::set<std::string> known_type_strings_; | 350 std::set<std::string> known_type_strings_; |
350 | 351 |
351 // Not owned. | 352 // Not owned. |
352 SandboxFileSystemBackendDelegate* sandbox_delegate_; | 353 SandboxFileSystemBackendDelegate* sandbox_delegate_; |
353 | 354 |
354 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); | 355 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); |
355 }; | 356 }; |
356 | 357 |
357 } // namespace fileapi | 358 } // namespace fileapi |
358 | 359 |
359 #endif // WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ | 360 #endif // WEBKIT_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
OLD | NEW |