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