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