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

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

Issue 15442002: Move FileAPI sandboxed filesystem related code from webkit/fileapi to webkit/browser/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 7 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_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
6 #define WEBKIT_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 "googleurl/src/gurl.h"
18 #include "webkit/browser/fileapi/file_system_mount_point_provider.h"
19 #include "webkit/fileapi/file_system_options.h"
20 #include "webkit/fileapi/file_system_quota_util.h"
21 #include "webkit/fileapi/task_runner_bound_observer_list.h"
22 #include "webkit/quota/special_storage_policy.h"
23 #include "webkit/storage/webkit_storage_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_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 static bool IsSandboxType(FileSystemType type);
73
74 // |file_task_runner| is used to validate the root directory and delete the
75 // obfuscated file util.
76 SandboxMountPointProvider(
77 quota::QuotaManagerProxy* quota_manager_proxy,
78 base::SequencedTaskRunner* file_task_runner,
79 const base::FilePath& profile_path,
80 const FileSystemOptions& file_system_options,
81 quota::SpecialStoragePolicy* special_storage_policy);
82 virtual ~SandboxMountPointProvider();
83
84 // FileSystemMountPointProvider overrides.
85 virtual bool CanHandleType(FileSystemType type) const OVERRIDE;
86 virtual void ValidateFileSystemRoot(
87 const GURL& origin_url,
88 FileSystemType type,
89 bool create,
90 const ValidateFileSystemCallback& callback) OVERRIDE;
91 virtual base::FilePath GetFileSystemRootPathOnFileThread(
92 const FileSystemURL& url,
93 bool create) OVERRIDE;
94 virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE;
95 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) OVERRIDE;
96 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory(
97 FileSystemType type,
98 base::PlatformFileError* error_code) OVERRIDE;
99 virtual void InitializeCopyOrMoveFileValidatorFactory(
100 FileSystemType type,
101 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) OVERRIDE;
102 virtual FilePermissionPolicy GetPermissionPolicy(
103 const FileSystemURL& url,
104 int permissions) const OVERRIDE;
105 virtual FileSystemOperation* CreateFileSystemOperation(
106 const FileSystemURL& url,
107 FileSystemContext* context,
108 base::PlatformFileError* error_code) const OVERRIDE;
109 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
110 const FileSystemURL& url,
111 int64 offset,
112 const base::Time& expected_modification_time,
113 FileSystemContext* context) const OVERRIDE;
114 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter(
115 const FileSystemURL& url,
116 int64 offset,
117 FileSystemContext* context) const OVERRIDE;
118 virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE;
119 virtual void DeleteFileSystem(
120 const GURL& origin_url,
121 FileSystemType type,
122 FileSystemContext* context,
123 const DeleteFileSystemCallback& callback) OVERRIDE;
124
125 // Returns an origin enumerator of this provider.
126 // This method can only be called on the file thread.
127 OriginEnumerator* CreateOriginEnumerator();
128
129 // Gets a base directory path of the sandboxed filesystem that is
130 // specified by |origin_url| and |type|.
131 // (The path is similar to the origin's root path but doesn't contain
132 // the 'unique' part.)
133 // Returns an empty path if the given type is invalid.
134 // This method can only be called on the file thread.
135 base::FilePath GetBaseDirectoryForOriginAndType(
136 const GURL& origin_url,
137 FileSystemType type,
138 bool create);
139
140 // Deletes the data on the origin and reports the amount of deleted data
141 // to the quota manager via |proxy|.
142 base::PlatformFileError DeleteOriginDataOnFileThread(
143 FileSystemContext* context,
144 quota::QuotaManagerProxy* proxy,
145 const GURL& origin_url,
146 FileSystemType type);
147
148 // FileSystemQuotaUtil overrides.
149 virtual void GetOriginsForTypeOnFileThread(
150 FileSystemType type,
151 std::set<GURL>* origins) OVERRIDE;
152 virtual void GetOriginsForHostOnFileThread(
153 FileSystemType type,
154 const std::string& host,
155 std::set<GURL>* origins) OVERRIDE;
156 virtual int64 GetOriginUsageOnFileThread(
157 FileSystemContext* context,
158 const GURL& origin_url,
159 FileSystemType type) OVERRIDE;
160
161 virtual void InvalidateUsageCache(const GURL& origin_url,
162 FileSystemType type) OVERRIDE;
163 virtual void StickyInvalidateUsageCache(const GURL& origin_url,
164 FileSystemType type) OVERRIDE;
165
166 void CollectOpenFileSystemMetrics(base::PlatformFileError error_code);
167
168 // Returns update observers for the given type.
169 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
170
171 void AddSyncableFileUpdateObserver(FileUpdateObserver* observer,
172 base::SequencedTaskRunner* task_runner);
173 void AddSyncableFileChangeObserver(FileChangeObserver* observer,
174 base::SequencedTaskRunner* task_runner);
175
176 // Returns a LocalFileSystemOperation that can be used to apply changes
177 // to the syncable filesystem.
178 LocalFileSystemOperation* CreateFileSystemOperationForSync(
179 FileSystemContext* file_system_context);
180
181 void set_enable_temporary_file_system_in_incognito(bool enable) {
182 enable_temporary_file_system_in_incognito_ = enable;
183 }
184
185 private:
186 friend class SandboxQuotaObserver;
187 friend class LocalFileSystemTestOriginHelper;
188 friend class SandboxMountPointProviderMigrationTest;
189 friend class SandboxMountPointProviderOriginEnumeratorTest;
190
191 // Returns a path to the usage cache file.
192 base::FilePath GetUsageCachePathForOriginAndType(
193 const GURL& origin_url,
194 FileSystemType type);
195
196 // Returns a path to the usage cache file (static version).
197 static base::FilePath GetUsageCachePathForOriginAndType(
198 ObfuscatedFileUtil* sandbox_file_util,
199 const GURL& origin_url,
200 FileSystemType type,
201 base::PlatformFileError* error_out);
202
203 // Returns true if the given |url|'s scheme is allowed to access
204 // filesystem.
205 bool IsAllowedScheme(const GURL& url) const;
206
207 ObfuscatedFileUtil* sandbox_sync_file_util();
208
209 FileSystemUsageCache* usage_cache() {
210 return file_system_usage_cache_.get();
211 }
212
213 static void InvalidateUsageCacheOnFileThread(
214 ObfuscatedFileUtil* file_util,
215 const GURL& origin,
216 FileSystemType type,
217 FileSystemUsageCache* usage_cache);
218
219 int64 RecalculateUsage(FileSystemContext* context,
220 const GURL& origin,
221 FileSystemType type);
222
223 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
224
225 const base::FilePath profile_path_;
226
227 FileSystemOptions file_system_options_;
228 bool enable_temporary_file_system_in_incognito_;
229
230 scoped_ptr<AsyncFileUtilAdapter> sandbox_file_util_;
231
232 scoped_ptr<FileSystemUsageCache> file_system_usage_cache_;
233
234 scoped_ptr<SandboxQuotaObserver> quota_observer_;
235
236 // Acccessed only on the file thread.
237 std::set<GURL> visited_origins_;
238
239 // Observers.
240 UpdateObserverList update_observers_;
241 AccessObserverList access_observers_;
242
243 // Observers for syncable file systems.
244 UpdateObserverList syncable_update_observers_;
245 ChangeObserverList syncable_change_observers_;
246
247 base::Time next_release_time_for_open_filesystem_stat_;
248
249 std::set<std::pair<GURL, FileSystemType> > sticky_dirty_origins_;
250
251 // Indicates if the usage tracking for FileSystem is enabled or not.
252 // The usage tracking is enabled by default and can be disabled by
253 // a command-line switch (--disable-file-system-usage-tracking).
254 bool enable_usage_tracking_;
255
256 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
257
258 base::WeakPtrFactory<SandboxMountPointProvider> weak_factory_;
259
260 DISALLOW_COPY_AND_ASSIGN(SandboxMountPointProvider);
261 };
262
263 } // namespace fileapi
264
265 #endif // WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/sandbox_file_stream_writer.cc ('k') | webkit/fileapi/sandbox_mount_point_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698