[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 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 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 8 | #include <set> |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 9 | #include <string> |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 11 | |
[email protected] | b7d38af7 | 2012-05-23 02:51:09 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 13 | #include "base/file_path.h" |
[email protected] | b7d38af7 | 2012-05-23 02:51:09 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | 3cfc10f | 2012-05-24 01:20:41 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | d247b84 | 2012-05-08 06:43:36 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 17 | #include "googleurl/src/gurl.h" |
[email protected] | 0b38b4e5 | 2012-05-30 08:14:27 | [diff] [blame] | 18 | #include "webkit/fileapi/fileapi_export.h" |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 19 | #include "webkit/fileapi/file_system_mount_point_provider.h" |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 20 | #include "webkit/fileapi/file_system_options.h" |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 21 | #include "webkit/fileapi/file_system_quota_util.h" |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 22 | #include "webkit/fileapi/task_runner_bound_observer_list.h" |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 23 | |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 24 | namespace base { |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 25 | class SequencedTaskRunner; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 28 | namespace quota { |
| 29 | class QuotaManagerProxy; |
| 30 | } |
| 31 | |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 32 | namespace fileapi { |
| 33 | |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 34 | class ObfuscatedFileUtil; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 35 | class SandboxQuotaObserver; |
[email protected] | e5006b9 | 2011-05-17 11:53:51 | [diff] [blame] | 36 | |
[email protected] | 4f9b143 | 2011-12-20 11:10:16 | [diff] [blame] | 37 | // An interface to construct or crack sandboxed filesystem paths for |
| 38 | // TEMPORARY or PERSISTENT filesystems, which are placed under the user's |
| 39 | // profile directory in a sandboxed way. |
| 40 | // This interface also lets one enumerate and remove storage for the origins |
| 41 | // that use the filesystem. |
[email protected] | 0b38b4e5 | 2012-05-30 08:14:27 | [diff] [blame] | 42 | class FILEAPI_EXPORT SandboxMountPointProvider |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 43 | : public FileSystemMountPointProvider, |
| 44 | public FileSystemQuotaUtil { |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 45 | public: |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 46 | using FileSystemMountPointProvider::ValidateFileSystemCallback; |
| 47 | using FileSystemMountPointProvider::DeleteFileSystemCallback; |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 48 | |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 49 | // Origin enumerator interface. |
| 50 | // An instance of this interface is assumed to be called on the file thread. |
| 51 | class OriginEnumerator { |
| 52 | public: |
| 53 | virtual ~OriginEnumerator() {} |
| 54 | |
| 55 | // Returns the next origin. Returns empty if there are no more origins. |
| 56 | virtual GURL Next() = 0; |
| 57 | |
| 58 | // Returns the current origin's information. |
| 59 | virtual bool HasFileSystemType(FileSystemType type) const = 0; |
| 60 | }; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 61 | |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 62 | // The legacy [pre-obfuscation] FileSystem directory name, kept around for |
| 63 | // migration and migration testing. |
| 64 | static const FilePath::CharType kOldFileSystemDirectory[]; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 65 | // The FileSystem directory name. |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 66 | static const FilePath::CharType kNewFileSystemDirectory[]; |
| 67 | // Where we move the old filesystem directory if migration fails. |
| 68 | static const FilePath::CharType kRenamedOldFileSystemDirectory[]; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 69 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 70 | static bool CanHandleType(FileSystemType type); |
| 71 | |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 72 | // |file_task_runner| is used to validate the root directory and delete the |
| 73 | // obfuscated file util. |
[email protected] | 3c48b53 | 2011-12-20 12:42:44 | [diff] [blame] | 74 | SandboxMountPointProvider( |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 75 | quota::QuotaManagerProxy* quota_manager_proxy, |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 76 | base::SequencedTaskRunner* file_task_runner, |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 77 | const FilePath& profile_path, |
| 78 | const FileSystemOptions& file_system_options); |
[email protected] | 3c48b53 | 2011-12-20 12:42:44 | [diff] [blame] | 79 | virtual ~SandboxMountPointProvider(); |
| 80 | |
| 81 | // FileSystemMountPointProvider overrides. |
[email protected] | 60f60f8 | 2012-01-11 10:26:10 | [diff] [blame] | 82 | virtual void ValidateFileSystemRoot( |
| 83 | const GURL& origin_url, |
| 84 | FileSystemType type, |
| 85 | bool create, |
| 86 | const ValidateFileSystemCallback& callback) OVERRIDE; |
| 87 | virtual FilePath GetFileSystemRootPathOnFileThread( |
| 88 | const GURL& origin_url, |
| 89 | FileSystemType type, |
| 90 | const FilePath& virtual_path, |
| 91 | bool create) OVERRIDE; |
[email protected] | 5aeeb7c6 | 2012-08-27 11:34:13 | [diff] [blame] | 92 | virtual bool IsAccessAllowed(const FileSystemURL& url) OVERRIDE; |
[email protected] | 3c48b53 | 2011-12-20 12:42:44 | [diff] [blame] | 93 | virtual bool IsRestrictedFileName(const FilePath& filename) const OVERRIDE; |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 94 | virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) OVERRIDE; |
[email protected] | 22121e3 | 2012-03-01 05:24:59 | [diff] [blame] | 95 | virtual FilePath GetPathForPermissionsCheck(const FilePath& virtual_path) |
| 96 | const OVERRIDE; |
[email protected] | 8e3bc3e | 2012-08-24 13:12:53 | [diff] [blame] | 97 | virtual FileSystemOperation* CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 98 | const FileSystemURL& url, |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 99 | FileSystemContext* context, |
| 100 | base::PlatformFileError* error_code) const OVERRIDE; |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 101 | virtual webkit_blob::FileStreamReader* CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 102 | const FileSystemURL& url, |
| 103 | int64 offset, |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame^] | 104 | const base::Time& expected_modification_time, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 105 | FileSystemContext* context) const OVERRIDE; |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 106 | virtual FileStreamWriter* CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 107 | const FileSystemURL& url, |
| 108 | int64 offset, |
| 109 | FileSystemContext* context) const OVERRIDE; |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 110 | virtual FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 111 | virtual void DeleteFileSystem( |
| 112 | const GURL& origin_url, |
| 113 | FileSystemType type, |
| 114 | FileSystemContext* context, |
| 115 | const DeleteFileSystemCallback& callback) OVERRIDE; |
[email protected] | 3c48b53 | 2011-12-20 12:42:44 | [diff] [blame] | 116 | |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 117 | FilePath old_base_path() const; |
| 118 | FilePath new_base_path() const; |
| 119 | FilePath renamed_old_base_path() const; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 120 | |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 121 | // Returns an origin enumerator of this provider. |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 122 | // This method can only be called on the file thread. |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 123 | OriginEnumerator* CreateOriginEnumerator() const; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 124 | |
| 125 | // Gets a base directory path of the sandboxed filesystem that is |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 126 | // specified by |origin_url| and |type|. |
| 127 | // (The path is similar to the origin's root path but doesn't contain |
| 128 | // the 'unique' part.) |
| 129 | // Returns an empty path if the given type is invalid. |
[email protected] | fcc2d5f | 2011-05-23 22:06:26 | [diff] [blame] | 130 | // This method can only be called on the file thread. |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 131 | FilePath GetBaseDirectoryForOriginAndType( |
| 132 | const GURL& origin_url, |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 133 | FileSystemType type, |
[email protected] | fcc2d5f | 2011-05-23 22:06:26 | [diff] [blame] | 134 | bool create) const; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 135 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 136 | // Deletes the data on the origin and reports the amount of deleted data |
| 137 | // to the quota manager via |proxy|. |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 138 | base::PlatformFileError DeleteOriginDataOnFileThread( |
[email protected] | 2289452 | 2012-05-23 07:14:58 | [diff] [blame] | 139 | FileSystemContext* context, |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 140 | quota::QuotaManagerProxy* proxy, |
| 141 | const GURL& origin_url, |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 142 | FileSystemType type); |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 143 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 144 | // FileSystemQuotaUtil overrides. |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 145 | virtual void GetOriginsForTypeOnFileThread( |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 146 | FileSystemType type, |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 147 | std::set<GURL>* origins) OVERRIDE; |
| 148 | virtual void GetOriginsForHostOnFileThread( |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 149 | FileSystemType type, |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 150 | const std::string& host, |
| 151 | std::set<GURL>* origins) OVERRIDE; |
| 152 | virtual int64 GetOriginUsageOnFileThread( |
[email protected] | 2289452 | 2012-05-23 07:14:58 | [diff] [blame] | 153 | FileSystemContext* context, |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 154 | const GURL& origin_url, |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 155 | FileSystemType type) OVERRIDE; |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 156 | |
[email protected] | 3458333 | 2011-08-31 08:59:47 | [diff] [blame] | 157 | virtual void InvalidateUsageCache(const GURL& origin_url, |
| 158 | FileSystemType type) OVERRIDE; |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 159 | |
[email protected] | d247b84 | 2012-05-08 06:43:36 | [diff] [blame] | 160 | void CollectOpenFileSystemMetrics(base::PlatformFileError error_code); |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 161 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 162 | // Returns update observers for the given type. |
| 163 | const UpdateObserverList* GetUpdateObservers(FileSystemType type) const; |
| 164 | |
[email protected] | 2ef2e274 | 2012-10-09 14:18:13 | [diff] [blame] | 165 | void AddSyncableFileUpdateObserver(FileUpdateObserver* observer, |
| 166 | base::SequencedTaskRunner* task_runner); |
| 167 | void AddSyncableFileChangeObserver(FileChangeObserver* observer, |
| 168 | base::SequencedTaskRunner* task_runner); |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 169 | |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 170 | private: |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 171 | friend class SandboxQuotaObserver; |
| 172 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 173 | // Returns a path to the usage cache file. |
| 174 | FilePath GetUsageCachePathForOriginAndType( |
| 175 | const GURL& origin_url, |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 176 | FileSystemType type) const; |
| 177 | |
| 178 | FilePath OldCreateFileSystemRootPath( |
| 179 | const GURL& origin_url, FileSystemType type); |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 180 | |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 181 | // Returns true if the given |url|'s scheme is allowed to access |
| 182 | // filesystem. |
| 183 | bool IsAllowedScheme(const GURL& url) const; |
| 184 | |
[email protected] | 02a6054 | 2012-07-24 20:05:33 | [diff] [blame] | 185 | friend class LocalFileSystemTestOriginHelper; |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 186 | friend class SandboxMountPointProviderMigrationTest; |
| 187 | friend class SandboxMountPointProviderOriginEnumeratorTest; |
[email protected] | e5006b9 | 2011-05-17 11:53:51 | [diff] [blame] | 188 | |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 189 | scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 190 | |
[email protected] | 054702d | 2011-05-28 01:12:18 | [diff] [blame] | 191 | const FilePath profile_path_; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 192 | |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 193 | FileSystemOptions file_system_options_; |
| 194 | |
[email protected] | 3cfc10f | 2012-05-24 01:20:41 | [diff] [blame] | 195 | scoped_ptr<ObfuscatedFileUtil> sandbox_file_util_; |
[email protected] | d4905e2e | 2011-05-13 21:56:32 | [diff] [blame] | 196 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 197 | scoped_ptr<SandboxQuotaObserver> quota_observer_; |
| 198 | |
[email protected] | 5caeb20 | 2011-05-17 07:42:07 | [diff] [blame] | 199 | // Acccessed only on the file thread. |
| 200 | std::set<GURL> visited_origins_; |
| 201 | |
[email protected] | caf6670 | 2012-09-07 07:02:20 | [diff] [blame] | 202 | // Observers. |
| 203 | UpdateObserverList update_observers_; |
| 204 | AccessObserverList access_observers_; |
| 205 | |
[email protected] | 2ef2e274 | 2012-10-09 14:18:13 | [diff] [blame] | 206 | // Observers for syncable file systems. |
| 207 | UpdateObserverList syncable_update_observers_; |
| 208 | ChangeObserverList syncable_change_observers_; |
| 209 | |
[email protected] | d247b84 | 2012-05-08 06:43:36 | [diff] [blame] | 210 | base::Time next_release_time_for_open_filesystem_stat_; |
| 211 | |
| 212 | base::WeakPtrFactory<SandboxMountPointProvider> weak_factory_; |
| 213 | |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 214 | DISALLOW_COPY_AND_ASSIGN(SandboxMountPointProvider); |
| 215 | }; |
| 216 | |
| 217 | } // namespace fileapi |
| 218 | |
| 219 | #endif // WEBKIT_FILEAPI_SANDBOX_MOUNT_POINT_PROVIDER_H_ |