OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_SANDBOX_CONTEXT_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_CONTEXT_H_ |
6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_CONTEXT_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_CONTEXT_H_ |
7 | 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 |
8 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "webkit/browser/fileapi/file_system_backend.h" |
| 16 #include "webkit/browser/fileapi/file_system_options.h" |
11 #include "webkit/browser/fileapi/file_system_quota_util.h" | 17 #include "webkit/browser/fileapi/file_system_quota_util.h" |
12 #include "webkit/browser/webkit_storage_browser_export.h" | 18 #include "webkit/browser/webkit_storage_browser_export.h" |
13 | 19 |
14 namespace base { | 20 namespace base { |
15 class SequencedTaskRunner; | 21 class SequencedTaskRunner; |
16 } | 22 } |
17 | 23 |
18 namespace quota { | 24 namespace quota { |
19 class QuotaManagerProxy; | 25 class QuotaManagerProxy; |
20 class SpecialStoragePolicy; | 26 class SpecialStoragePolicy; |
21 } | 27 } |
22 | 28 |
23 namespace fileapi { | 29 namespace fileapi { |
24 | 30 |
25 class AsyncFileUtilAdapter; | 31 class AsyncFileUtilAdapter; |
| 32 class FileSystemURL; |
26 class FileSystemUsageCache; | 33 class FileSystemUsageCache; |
27 class ObfuscatedFileUtil; | 34 class ObfuscatedFileUtil; |
28 class SandboxFileSystemBackend; | 35 class SandboxFileSystemBackend; |
29 class SandboxFileSystemTestHelper; | 36 class SandboxFileSystemTestHelper; |
30 class SandboxQuotaObserver; | 37 class SandboxQuotaObserver; |
31 | 38 |
32 // This class keeps and provides a sandbox file system context. | 39 // This class keeps and provides a sandbox file system context. |
33 // An instance of this class is created and owned by FileSystemContext. | 40 // An instance of this class is created and owned by FileSystemContext. |
34 class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext { | 41 class WEBKIT_STORAGE_BROWSER_EXPORT SandboxContext { |
35 public: | 42 public: |
36 // The FileSystem directory name. | 43 // The FileSystem directory name. |
37 static const base::FilePath::CharType kFileSystemDirectory[]; | 44 static const base::FilePath::CharType kFileSystemDirectory[]; |
38 | 45 |
| 46 // Origin enumerator interface. |
| 47 // An instance of this interface is assumed to be called on the file thread. |
| 48 class OriginEnumerator { |
| 49 public: |
| 50 virtual ~OriginEnumerator() {} |
| 51 |
| 52 // Returns the next origin. Returns empty if there are no more origins. |
| 53 virtual GURL Next() = 0; |
| 54 |
| 55 // Returns the current origin's information. |
| 56 virtual bool HasFileSystemType(FileSystemType type) const = 0; |
| 57 }; |
| 58 |
39 SandboxContext( | 59 SandboxContext( |
40 quota::QuotaManagerProxy* quota_manager_proxy, | 60 quota::QuotaManagerProxy* quota_manager_proxy, |
41 base::SequencedTaskRunner* file_task_runner, | 61 base::SequencedTaskRunner* file_task_runner, |
42 const base::FilePath& profile_path, | 62 const base::FilePath& profile_path, |
43 quota::SpecialStoragePolicy* special_storage_policy); | 63 quota::SpecialStoragePolicy* special_storage_policy, |
| 64 const FileSystemOptions& file_system_options); |
44 | 65 |
45 ~SandboxContext(); | 66 ~SandboxContext(); |
46 | 67 |
| 68 // Performs API-specific validity checks on the given path |url|. |
| 69 // Returns true if access to |url| is valid in this filesystem. |
| 70 bool IsAccessValid(const FileSystemURL& url) const; |
| 71 |
| 72 // Returns true if the given |url|'s scheme is allowed to access |
| 73 // filesystem. |
| 74 bool IsAllowedScheme(const GURL& url) const; |
| 75 |
| 76 // Returns an origin enumerator of sandbox filesystem. |
| 77 // This method can only be called on the file thread. |
| 78 OriginEnumerator* CreateOriginEnumerator(); |
| 79 |
| 80 // Gets a base directory path of the sandboxed filesystem that is |
| 81 // specified by |origin_url| and |type|. |
| 82 // (The path is similar to the origin's root path but doesn't contain |
| 83 // the 'unique' part.) |
| 84 // Returns an empty path if the given type is invalid. |
| 85 // This method can only be called on the file thread. |
| 86 base::FilePath GetBaseDirectoryForOriginAndType( |
| 87 const GURL& origin_url, |
| 88 FileSystemType type, |
| 89 bool create); |
| 90 |
| 91 // FileSystemQuotaUtil helpers. |
| 92 base::PlatformFileError DeleteOriginDataOnFileThread( |
| 93 FileSystemContext* context, |
| 94 quota::QuotaManagerProxy* proxy, |
| 95 const GURL& origin_url, |
| 96 FileSystemType type); |
| 97 void GetOriginsForTypeOnFileThread( |
| 98 FileSystemType type, |
| 99 std::set<GURL>* origins); |
| 100 void GetOriginsForHostOnFileThread( |
| 101 FileSystemType type, |
| 102 const std::string& host, |
| 103 std::set<GURL>* origins); |
| 104 int64 GetOriginUsageOnFileThread( |
| 105 FileSystemContext* context, |
| 106 const GURL& origin_url, |
| 107 FileSystemType type); |
| 108 void InvalidateUsageCache( |
| 109 const GURL& origin_url, |
| 110 FileSystemType type); |
| 111 void StickyInvalidateUsageCache( |
| 112 const GURL& origin_url, |
| 113 FileSystemType type); |
| 114 |
47 base::SequencedTaskRunner* file_task_runner() { | 115 base::SequencedTaskRunner* file_task_runner() { |
48 return file_task_runner_.get(); | 116 return file_task_runner_.get(); |
49 } | 117 } |
50 | 118 |
51 AsyncFileUtilAdapter* file_util() { return sandbox_file_util_.get(); } | 119 AsyncFileUtilAdapter* file_util() { return sandbox_file_util_.get(); } |
52 FileSystemUsageCache* usage_cache() { return file_system_usage_cache_.get(); } | 120 FileSystemUsageCache* usage_cache() { return file_system_usage_cache_.get(); } |
53 SandboxQuotaObserver* quota_observer() { return quota_observer_.get(); }; | 121 SandboxQuotaObserver* quota_observer() { return quota_observer_.get(); }; |
54 | 122 |
55 quota::SpecialStoragePolicy* special_storage_policy() { | 123 quota::SpecialStoragePolicy* special_storage_policy() { |
56 return special_storage_policy_.get(); | 124 return special_storage_policy_.get(); |
57 } | 125 } |
58 | 126 |
| 127 FileSystemOptions file_system_options() { return file_system_options_; } |
| 128 |
59 ObfuscatedFileUtil* sync_file_util(); | 129 ObfuscatedFileUtil* sync_file_util(); |
60 | 130 |
61 private: | 131 private: |
| 132 friend class SandboxQuotaObserver; |
| 133 friend class SandboxFileSystemTestHelper; |
| 134 |
| 135 // Returns a path to the usage cache file. |
| 136 base::FilePath GetUsageCachePathForOriginAndType( |
| 137 const GURL& origin_url, |
| 138 FileSystemType type); |
| 139 |
| 140 // Returns a path to the usage cache file (static version). |
| 141 static base::FilePath GetUsageCachePathForOriginAndType( |
| 142 ObfuscatedFileUtil* sandbox_file_util, |
| 143 const GURL& origin_url, |
| 144 FileSystemType type, |
| 145 base::PlatformFileError* error_out); |
| 146 |
| 147 int64 RecalculateUsage(FileSystemContext* context, |
| 148 const GURL& origin, |
| 149 FileSystemType type); |
| 150 |
62 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 151 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
63 | 152 |
64 scoped_ptr<AsyncFileUtilAdapter> sandbox_file_util_; | 153 scoped_ptr<AsyncFileUtilAdapter> sandbox_file_util_; |
65 scoped_ptr<FileSystemUsageCache> file_system_usage_cache_; | 154 scoped_ptr<FileSystemUsageCache> file_system_usage_cache_; |
66 scoped_ptr<SandboxQuotaObserver> quota_observer_; | 155 scoped_ptr<SandboxQuotaObserver> quota_observer_; |
67 | 156 |
68 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 157 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
69 | 158 |
| 159 FileSystemOptions file_system_options_; |
| 160 |
| 161 // Acccessed only on the file thread. |
| 162 std::set<GURL> visited_origins_; |
| 163 |
| 164 std::set<std::pair<GURL, FileSystemType> > sticky_dirty_origins_; |
| 165 |
70 DISALLOW_COPY_AND_ASSIGN(SandboxContext); | 166 DISALLOW_COPY_AND_ASSIGN(SandboxContext); |
71 }; | 167 }; |
72 | 168 |
73 } // namespace fileapi | 169 } // namespace fileapi |
74 | 170 |
75 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_CONTEXT_H_ | 171 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_CONTEXT_H_ |
OLD | NEW |