Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1174)

Side by Side Diff: webkit/browser/fileapi/sandbox_mount_point_provider.h

Issue 18344013: fileapi: Rename FileSystemMountProvider to FileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "url/gurl.h"
18 #include "webkit/browser/fileapi/file_system_mount_point_provider.h"
19 #include "webkit/browser/fileapi/file_system_options.h"
20 #include "webkit/browser/fileapi/file_system_quota_util.h"
21 #include "webkit/browser/fileapi/task_runner_bound_observer_list.h"
22 #include "webkit/browser/quota/special_storage_policy.h"
23 #include "webkit/browser/webkit_storage_browser_export.h"
24
25 namespace base {
26 class SequencedTaskRunner;
27 }
28
29 namespace quota {
30 class QuotaManagerProxy;
31 class SpecialStoragePolicy;
32 }
33
34 namespace sync_file_system {
35 class CannedSyncableFileSystem;
36 class SyncableFileSystemOperation;
37 }
38
39 namespace fileapi {
40
41 class AsyncFileUtilAdapter;
42 class FileSystemUsageCache;
43 class LocalFileSystemOperation;
44 class ObfuscatedFileUtil;
45 class SandboxQuotaObserver;
46
47 // An interface to construct or crack sandboxed filesystem paths for
48 // TEMPORARY or PERSISTENT filesystems, which are placed under the user's
49 // profile directory in a sandboxed way.
50 // This interface also lets one enumerate and remove storage for the origins
51 // that use the filesystem.
52 class WEBKIT_STORAGE_BROWSER_EXPORT SandboxMountPointProvider
53 : public FileSystemMountPointProvider,
54 public FileSystemQuotaUtil {
55 public:
56 // Origin enumerator interface.
57 // An instance of this interface is assumed to be called on the file thread.
58 class OriginEnumerator {
59 public:
60 virtual ~OriginEnumerator() {}
61
62 // Returns the next origin. Returns empty if there are no more origins.
63 virtual GURL Next() = 0;
64
65 // Returns the current origin's information.
66 virtual bool HasFileSystemType(FileSystemType type) const = 0;
67 };
68
69 // The FileSystem directory name.
70 static const base::FilePath::CharType kFileSystemDirectory[];
71
72 // |file_task_runner| is used to validate the root directory and delete the
73 // obfuscated file util.
74 SandboxMountPointProvider(
75 quota::QuotaManagerProxy* quota_manager_proxy,
76 base::SequencedTaskRunner* file_task_runner,
77 const base::FilePath& profile_path,
78 const FileSystemOptions& file_system_options,
79 quota::SpecialStoragePolicy* special_storage_policy);
80 virtual ~SandboxMountPointProvider();
81
82 // FileSystemMountPointProvider overrides.
83 virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
84 virtual void OpenFileSystem(
85 const GURL& origin_url,
86 FileSystemType type,
87 OpenFileSystemMode mode,
88 const OpenFileSystemCallback& callback) OVERRIDE;
89 virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
90 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
91 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
92 FileSystemType type,
93 base::PlatformFileError* error_code) OVERRIDE;
94 virtual FileSystemOperation* CreateFileSystemOperation(
95 const FileSystemURL& url,
96 FileSystemContext* context,
97 base::PlatformFileError* error_code) const OVERRIDE;
98 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
99 const FileSystemURL& url,
100 int64 offset,
101 const base::Time& expected_modification_time,
102 FileSystemContext* context) const OVERRIDE;
103 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter(
104 const FileSystemURL& url,
105 int64 offset,
106 FileSystemContext* context) const OVERRIDE;
107 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
108 virtual void DeleteFileSystem(
109 const GURL& origin_url,
110 FileSystemType type,
111 FileSystemContext* context,
112 const DeleteFileSystemCallback& callback) OVERRIDE;
113
114 // Returns an origin enumerator of this provider.
115 // This method can only be called on the file thread.
116 OriginEnumerator* CreateOriginEnumerator();
117
118 // Gets a base directory path of the sandboxed filesystem that is
119 // specified by |origin_url| and |type|.
120 // (The path is similar to the origin's root path but doesn't contain
121 // the 'unique' part.)
122 // Returns an empty path if the given type is invalid.
123 // This method can only be called on the file thread.
124 base::FilePath GetBaseDirectoryForOriginAndType(
125 const GURL& origin_url,
126 FileSystemType type,
127 bool create);
128
129 // FileSystemQuotaUtil overrides.
130 virtual base::PlatformFileError DeleteOriginDataOnFileThread(
131 FileSystemContext* context,
132 quota::QuotaManagerProxy* proxy,
133 const GURL& origin_url,
134 FileSystemType type) OVERRIDE;
135 virtual void GetOriginsForTypeOnFileThread(
136 FileSystemType type,
137 std::set<GURL>* origins) OVERRIDE;
138 virtual void GetOriginsForHostOnFileThread(
139 FileSystemType type,
140 const std::string& host,
141 std::set<GURL>* origins) OVERRIDE;
142 virtual int64 GetOriginUsageOnFileThread(
143 FileSystemContext* context,
144 const GURL& origin_url,
145 FileSystemType type) OVERRIDE;
146
147 virtual void InvalidateUsageCache(const GURL& origin_url,
148 FileSystemType type) OVERRIDE;
149 virtual void StickyInvalidateUsageCache(const GURL& origin_url,
150 FileSystemType type) OVERRIDE;
151
152 void CollectOpenFileSystemMetrics(base::PlatformFileError error_code);
153
154 // Returns observers for the given type.
155 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
156 const AccessObserverList* GetAccessObservers(FileSystemType type) const;
157
158 void AddFileUpdateObserver(FileSystemType type,
159 FileUpdateObserver* observer,
160 base::SequencedTaskRunner* task_runner);
161 void AddFileChangeObserver(FileSystemType type,
162 FileChangeObserver* observer,
163 base::SequencedTaskRunner* task_runner);
164
165 // Performs API-specific validity checks on the given path |url|.
166 // Returns true if access to |url| is valid in this filesystem.
167 bool IsAccessValid(const FileSystemURL& url) const;
168
169 void set_enable_temporary_file_system_in_incognito(bool enable) {
170 enable_temporary_file_system_in_incognito_ = enable;
171 }
172
173 private:
174 friend class SandboxQuotaObserver;
175 friend class SandboxFileSystemTestHelper;
176 friend class SandboxMountPointProviderMigrationTest;
177 friend class SandboxMountPointProviderOriginEnumeratorTest;
178
179 // Returns a path to the usage cache file.
180 base::FilePath GetUsageCachePathForOriginAndType(
181 const GURL& origin_url,
182 FileSystemType type);
183
184 // Returns a path to the usage cache file (static version).
185 static base::FilePath GetUsageCachePathForOriginAndType(
186 ObfuscatedFileUtil* sandbox_file_util,
187 const GURL& origin_url,
188 FileSystemType type,
189 base::PlatformFileError* error_out);
190
191 // Returns true if the given |url|'s scheme is allowed to access
192 // filesystem.
193 bool IsAllowedScheme(const GURL& url) const;
194
195 ObfuscatedFileUtil* sandbox_sync_file_util();
196
197 FileSystemUsageCache* usage_cache() {
198 return file_system_usage_cache_.get();
199 }
200
201 static void InvalidateUsageCacheOnFileThread(
202 ObfuscatedFileUtil* file_util,
203 const GURL& origin,
204 FileSystemType type,
205 FileSystemUsageCache* usage_cache);
206
207 int64 RecalculateUsage(FileSystemContext* context,
208 const GURL& origin,
209 FileSystemType type);
210
211 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
212
213 const base::FilePath profile_path_;
214
215 FileSystemOptions file_system_options_;
216 bool enable_temporary_file_system_in_incognito_;
217
218 scoped_ptr<AsyncFileUtilAdapter> sandbox_file_util_;
219
220 scoped_ptr<FileSystemUsageCache> file_system_usage_cache_;
221
222 scoped_ptr<SandboxQuotaObserver> quota_observer_;
223
224 // Acccessed only on the file thread.
225 std::set<GURL> visited_origins_;
226
227 // Observers.
228 UpdateObserverList update_observers_;
229 ChangeObserverList change_observers_;
230 AccessObserverList access_observers_;
231
232 // Observers for syncable file systems.
233 UpdateObserverList syncable_update_observers_;
234 ChangeObserverList syncable_change_observers_;
235
236 base::Time next_release_time_for_open_filesystem_stat_;
237
238 std::set<std::pair<GURL, FileSystemType> > sticky_dirty_origins_;
239
240 // Indicates if the usage tracking for FileSystem is enabled or not.
241 // The usage tracking is enabled by default and can be disabled by
242 // a command-line switch (--disable-file-system-usage-tracking).
243 bool enable_usage_tracking_;
244
245 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
246
247 base::WeakPtrFactory<SandboxMountPointProvider> weak_factory_;
248
249 DISALLOW_COPY_AND_ASSIGN(SandboxMountPointProvider);
250 };
251
252 } // namespace fileapi
253
254 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698