OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 5 #ifndef WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 6 #define WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "webkit/fileapi/file_system_directory_database.h" | 16 #include "webkit/fileapi/file_system_directory_database.h" |
17 #include "webkit/fileapi/file_system_file_util.h" | |
18 #include "webkit/fileapi/file_system_origin_database.h" | 17 #include "webkit/fileapi/file_system_origin_database.h" |
19 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
| 19 #include "webkit/fileapi/fileapi_file_util.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 struct PlatformFileInfo; | 22 struct PlatformFileInfo; |
23 class Time; | 23 class Time; |
24 } | 24 } |
25 | 25 |
26 class GURL; | 26 class GURL; |
27 | 27 |
28 namespace fileapi { | 28 namespace fileapi { |
29 | 29 |
30 class FileSystemOperationContext; | 30 class FileSystemOperationContext; |
31 | 31 |
32 // The overall implementation philosophy of this class is that partial failures | 32 // The overall implementation philosophy of this class is that partial failures |
33 // should leave us with an intact database; we'd prefer to leak the occasional | 33 // should leave us with an intact database; we'd prefer to leak the occasional |
34 // backing file than have a database entry whose backing file is missing. When | 34 // backing file than have a database entry whose backing file is missing. When |
35 // doing FSCK operations, if you find a loose backing file with no reference, | 35 // doing FSCK operations, if you find a loose backing file with no reference, |
36 // you may safely delete it. | 36 // you may safely delete it. |
37 // | 37 // |
38 // This class is RefCountedThreadSafe because it may gain a reference on the IO | 38 // This class is RefCountedThreadSafe because it may gain a reference on the IO |
39 // thread, but must be deleted on the FILE thread because that's where | 39 // thread, but must be deleted on the FILE thread because that's where |
40 // DropDatabases needs to be called. References will be held by the | 40 // DropDatabases needs to be called. References will be held by the |
41 // SandboxMountPointProvider [and the task it uses to drop the reference] and | 41 // SandboxMountPointProvider [and the task it uses to drop the reference] and |
42 // SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one, | 42 // SandboxMountPointProvider::GetFileSystemRootPathTask. Without that last one, |
43 // we wouldn't need ref counting. | 43 // we wouldn't need ref counting. |
44 // | 44 // |
45 // TODO(ericu): We don't ever update directory mtimes; which operations should | 45 // TODO(ericu): We don't ever update directory mtimes; which operations should |
46 // do that? | 46 // do that? |
47 class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil, | 47 class ObfuscatedFileUtil : public FileApiFileUtil, |
48 public base::RefCountedThreadSafe<ObfuscatedFileSystemFileUtil> { | 48 public base::RefCountedThreadSafe<ObfuscatedFileUtil> { |
49 public: | 49 public: |
50 // |underlying_file_util| is owned by the instance. It will be deleted by | 50 // |underlying_file_util| is owned by the instance. It will be deleted by |
51 // the owner instance. For example, it can be instanciated as follows: | 51 // the owner instance. For example, it can be instanciated as follows: |
52 // FileSystemFileUtil* file_system_file_util = | 52 // FileApiFileUtil* file_util = new ObfuscatedFileUtil(new NativeFileUtil()); |
53 // new ObfuscatedFileSystemFileUtil(new FileSystemFileUtil()); | 53 ObfuscatedFileUtil(const FilePath& file_system_directory, |
54 ObfuscatedFileSystemFileUtil( | 54 FileApiFileUtil* underlying_file_util); |
55 const FilePath& file_system_directory, | 55 virtual ~ObfuscatedFileUtil(); |
56 FileSystemFileUtil* underlying_file_util); | |
57 virtual ~ObfuscatedFileSystemFileUtil(); | |
58 | 56 |
59 virtual base::PlatformFileError CreateOrOpen( | 57 virtual base::PlatformFileError CreateOrOpen( |
60 FileSystemOperationContext* context, | 58 FileSystemOperationContext* context, |
61 const FilePath& file_path, | 59 const FilePath& file_path, |
62 int file_flags, | 60 int file_flags, |
63 base::PlatformFile* file_handle, | 61 base::PlatformFile* file_handle, |
64 bool* created) OVERRIDE; | 62 bool* created) OVERRIDE; |
65 | 63 |
66 virtual base::PlatformFileError EnsureFileExists( | 64 virtual base::PlatformFileError EnsureFileExists( |
67 FileSystemOperationContext* context, | 65 FileSystemOperationContext* context, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // contain both the filesystem type subdirectories. | 236 // contain both the filesystem type subdirectories. |
239 FilePath GetDirectoryForOrigin(const GURL& origin, bool create); | 237 FilePath GetDirectoryForOrigin(const GURL& origin, bool create); |
240 void MarkUsed(); | 238 void MarkUsed(); |
241 void DropDatabases(); | 239 void DropDatabases(); |
242 bool InitOriginDatabase(bool create); | 240 bool InitOriginDatabase(bool create); |
243 | 241 |
244 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; | 242 typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap; |
245 DirectoryMap directories_; | 243 DirectoryMap directories_; |
246 scoped_ptr<FileSystemOriginDatabase> origin_database_; | 244 scoped_ptr<FileSystemOriginDatabase> origin_database_; |
247 FilePath file_system_directory_; | 245 FilePath file_system_directory_; |
248 base::OneShotTimer<ObfuscatedFileSystemFileUtil> timer_; | 246 base::OneShotTimer<ObfuscatedFileUtil> timer_; |
249 scoped_ptr<FileSystemFileUtil> underlying_file_util_; | |
250 | 247 |
251 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtil); | 248 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil); |
252 }; | 249 }; |
253 | 250 |
254 } // namespace fileapi | 251 } // namespace fileapi |
255 | 252 |
256 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_SYSTEM_FILE_UTIL_H_ | 253 #endif // WEBKIT_FILEAPI_OBFUSCATED_FILE_UTIL_H_ |
OLD | NEW |