OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_FILE_SYSTEM_CONTEXT_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" |
15 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
16 #include "base/sequenced_task_runner_helpers.h" | 17 #include "base/sequenced_task_runner_helpers.h" |
17 #include "webkit/fileapi/file_system_types.h" | 18 #include "webkit/fileapi/file_system_types.h" |
18 #include "webkit/fileapi/file_system_url.h" | 19 #include "webkit/fileapi/file_system_url.h" |
19 #include "webkit/fileapi/task_runner_bound_observer_list.h" | 20 #include "webkit/fileapi/task_runner_bound_observer_list.h" |
20 #include "webkit/storage/webkit_storage_export.h" | 21 #include "webkit/storage/webkit_storage_export.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class FilePath; | 24 class FilePath; |
24 } | 25 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 DefaultContextDeleter> { | 66 DefaultContextDeleter> { |
66 public: | 67 public: |
67 // task_runners->file_task_runner() is used as default TaskRunner. | 68 // task_runners->file_task_runner() is used as default TaskRunner. |
68 // Unless a MountPointProvider is overridden in CreateFileSystemOperation, | 69 // Unless a MountPointProvider is overridden in CreateFileSystemOperation, |
69 // it is used for all file operations and file related meta operations. | 70 // it is used for all file operations and file related meta operations. |
70 // The code assumes that | 71 // The code assumes that |
71 // task_runners->file_task_runner()->RunsTasksOnCurrentThread() | 72 // task_runners->file_task_runner()->RunsTasksOnCurrentThread() |
72 // returns false if the current task is not running on the thread that allows | 73 // returns false if the current task is not running on the thread that allows |
73 // blocking file operations (like SequencedWorkerPool implementation does). | 74 // blocking file operations (like SequencedWorkerPool implementation does). |
74 // | 75 // |
75 // |external_mount_points| contains non-system external mount points available | 76 // |additional_providers| are added to the internal provider map |
76 // in the context. If not NULL, it will be used during URL cracking. On | 77 // to serve filesystem requests for non-regular types. |
77 // ChromeOS, it will be passed to external_mount_point_provider. | 78 // If none is given, this context only handles HTML5 Sandbox FileSystem |
78 // |external_mount_points| may be NULL only on platforms different from | 79 // and Drag-and-drop Isolated FileSystem requests. |
79 // ChromeOS (i.e. platforms that don't use external_mount_point_provider). | 80 // |
| 81 // |additional_mount_points| is used to crack FileSystemURL in |
| 82 // CrackFileSystemURL() (in addition to default system-wide mount points). |
80 FileSystemContext( | 83 FileSystemContext( |
81 scoped_ptr<FileSystemTaskRunners> task_runners, | 84 scoped_ptr<FileSystemTaskRunners> task_runners, |
82 ExternalMountPoints* external_mount_points, | |
83 quota::SpecialStoragePolicy* special_storage_policy, | |
84 quota::QuotaManagerProxy* quota_manager_proxy, | 85 quota::QuotaManagerProxy* quota_manager_proxy, |
| 86 ScopedVector<FileSystemMountPointProvider> additional_providers, |
| 87 const std::vector<MountPoints*>& additional_mount_points, |
85 const base::FilePath& partition_path, | 88 const base::FilePath& partition_path, |
86 const FileSystemOptions& options); | 89 const FileSystemOptions& options); |
87 | 90 |
88 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); | 91 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); |
89 | 92 |
90 quota::QuotaManagerProxy* quota_manager_proxy() const { | 93 quota::QuotaManagerProxy* quota_manager_proxy() const { |
91 return quota_manager_proxy_.get(); | 94 return quota_manager_proxy_.get(); |
92 } | 95 } |
93 | 96 |
94 // Returns a quota util for a given filesystem type. This may | 97 // Returns a quota util for a given filesystem type. This may |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 int64 offset, | 189 int64 offset, |
187 const base::Time& expected_modification_time); | 190 const base::Time& expected_modification_time); |
188 | 191 |
189 // Creates new FileStreamWriter instance to write into a file pointed by | 192 // Creates new FileStreamWriter instance to write into a file pointed by |
190 // |url| from |offset|. | 193 // |url| from |offset|. |
191 scoped_ptr<FileStreamWriter> CreateFileStreamWriter( | 194 scoped_ptr<FileStreamWriter> CreateFileStreamWriter( |
192 const FileSystemURL& url, | 195 const FileSystemURL& url, |
193 int64 offset); | 196 int64 offset); |
194 | 197 |
195 // Register a filesystem provider. The ownership of |provider| is | 198 // Register a filesystem provider. The ownership of |provider| is |
196 // transferred to this instance. | 199 // transferred to this instance. This must be used only for testing. |
197 void RegisterMountPointProvider(FileSystemType type, | 200 void RegisterMountPointProviderForTesting( |
198 FileSystemMountPointProvider* provider); | 201 FileSystemType type, |
| 202 FileSystemMountPointProvider* provider); |
199 | 203 |
200 FileSystemTaskRunners* task_runners() { return task_runners_.get(); } | 204 FileSystemTaskRunners* task_runners() { return task_runners_.get(); } |
201 | 205 |
202 sync_file_system::LocalFileChangeTracker* change_tracker() { | 206 sync_file_system::LocalFileChangeTracker* change_tracker() { |
203 return change_tracker_.get(); | 207 return change_tracker_.get(); |
204 } | 208 } |
205 void SetLocalFileChangeTracker( | 209 void SetLocalFileChangeTracker( |
206 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker); | 210 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker); |
207 | 211 |
208 sync_file_system::LocalFileSyncContext* sync_context() { | 212 sync_file_system::LocalFileSyncContext* sync_context() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // | 257 // |
254 // If the original url does not point to an isolated or external filesystem, | 258 // If the original url does not point to an isolated or external filesystem, |
255 // returns the original url, without attempting to crack it. | 259 // returns the original url, without attempting to crack it. |
256 FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const; | 260 FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const; |
257 | 261 |
258 // Returns the appropriate FileUtil instance for the given |type|. | 262 // Returns the appropriate FileUtil instance for the given |type|. |
259 // This may return NULL if it is given an invalid type or the filesystem | 263 // This may return NULL if it is given an invalid type or the filesystem |
260 // does not support synchronous file operations. | 264 // does not support synchronous file operations. |
261 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; | 265 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; |
262 | 266 |
| 267 // For initial provider_map construction. This must be called only from |
| 268 // the constructor. |
| 269 void RegisterMountPointProvider(FileSystemMountPointProvider* provider); |
| 270 |
263 scoped_ptr<FileSystemTaskRunners> task_runners_; | 271 scoped_ptr<FileSystemTaskRunners> task_runners_; |
264 | 272 |
265 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 273 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
266 | 274 |
267 // Regular mount point providers. | 275 // Regular mount point providers. |
268 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; | 276 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; |
269 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; | 277 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; |
270 scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; | 278 |
| 279 // Additional mount point providers. |
| 280 ScopedVector<FileSystemMountPointProvider> additional_providers_; |
271 | 281 |
272 // Registered mount point providers. | 282 // Registered mount point providers. |
| 283 // The map must be constructed in the constructor (other than for testing) |
| 284 // since it can be accessed on multiple threads. |
| 285 // The ownership of each provider is held by mount_point_providers_. |
273 std::map<FileSystemType, FileSystemMountPointProvider*> provider_map_; | 286 std::map<FileSystemType, FileSystemMountPointProvider*> provider_map_; |
274 | 287 |
275 // External mount points visible in the file system context (excluding system | |
276 // external mount points). | |
277 scoped_refptr<ExternalMountPoints> external_mount_points_; | |
278 | |
279 // MountPoints used to crack FileSystemURLs. The MountPoints are ordered | 288 // MountPoints used to crack FileSystemURLs. The MountPoints are ordered |
280 // in order they should try to crack a FileSystemURL. | 289 // in order they should try to crack a FileSystemURL. |
281 std::vector<MountPoints*> url_crackers_; | 290 std::vector<MountPoints*> url_crackers_; |
282 | 291 |
283 // The base path of the storage partition for this context. | 292 // The base path of the storage partition for this context. |
284 const base::FilePath partition_path_; | 293 const base::FilePath partition_path_; |
285 | 294 |
286 // For syncable file systems. | 295 // For syncable file systems. |
287 scoped_ptr<sync_file_system::LocalFileChangeTracker> change_tracker_; | 296 scoped_ptr<sync_file_system::LocalFileChangeTracker> change_tracker_; |
288 scoped_refptr<sync_file_system::LocalFileSyncContext> sync_context_; | 297 scoped_refptr<sync_file_system::LocalFileSyncContext> sync_context_; |
289 | 298 |
290 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); | 299 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); |
291 }; | 300 }; |
292 | 301 |
293 struct DefaultContextDeleter { | 302 struct DefaultContextDeleter { |
294 static void Destruct(const FileSystemContext* context) { | 303 static void Destruct(const FileSystemContext* context) { |
295 context->DeleteOnCorrectThread(); | 304 context->DeleteOnCorrectThread(); |
296 } | 305 } |
297 }; | 306 }; |
298 | 307 |
299 } // namespace fileapi | 308 } // namespace fileapi |
300 | 309 |
301 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 310 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
OLD | NEW |