| 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_BROWSER_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 6 #define WEBKIT_BROWSER_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> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace webkit_blob { | 42 namespace webkit_blob { |
| 43 class BlobURLRequestJobTest; | 43 class BlobURLRequestJobTest; |
| 44 class FileStreamReader; | 44 class FileStreamReader; |
| 45 } | 45 } |
| 46 | 46 |
| 47 namespace fileapi { | 47 namespace fileapi { |
| 48 | 48 |
| 49 class AsyncFileUtil; | 49 class AsyncFileUtil; |
| 50 class CopyOrMoveFileValidatorFactory; | 50 class CopyOrMoveFileValidatorFactory; |
| 51 class ExternalFileSystemMountPointProvider; | 51 class ExternalFileSystemBackend; |
| 52 class ExternalMountPoints; | 52 class ExternalMountPoints; |
| 53 class FileStreamWriter; | 53 class FileStreamWriter; |
| 54 class FileSystemFileUtil; | 54 class FileSystemFileUtil; |
| 55 class FileSystemMountPointProvider; | 55 class FileSystemBackend; |
| 56 class FileSystemOperation; | 56 class FileSystemOperation; |
| 57 class FileSystemOperationRunner; | 57 class FileSystemOperationRunner; |
| 58 class FileSystemOptions; | 58 class FileSystemOptions; |
| 59 class FileSystemQuotaUtil; | 59 class FileSystemQuotaUtil; |
| 60 class FileSystemTaskRunners; | 60 class FileSystemTaskRunners; |
| 61 class FileSystemURL; | 61 class FileSystemURL; |
| 62 class IsolatedMountPointProvider; | 62 class IsolatedFileSystemBackend; |
| 63 class MountPoints; | 63 class MountPoints; |
| 64 class SandboxMountPointProvider; | 64 class SandboxFileSystemBackend; |
| 65 | 65 |
| 66 struct DefaultContextDeleter; | 66 struct DefaultContextDeleter; |
| 67 | 67 |
| 68 // This class keeps and provides a file system context for FileSystem API. | 68 // This class keeps and provides a file system context for FileSystem API. |
| 69 // An instance of this class is created and owned by profile. | 69 // An instance of this class is created and owned by profile. |
| 70 class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext | 70 class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext |
| 71 : public base::RefCountedThreadSafe<FileSystemContext, | 71 : public base::RefCountedThreadSafe<FileSystemContext, |
| 72 DefaultContextDeleter> { | 72 DefaultContextDeleter> { |
| 73 public: | 73 public: |
| 74 // Returns file permission policy we should apply for the given |type|. | 74 // Returns file permission policy we should apply for the given |type|. |
| 75 // The return value must be bitwise-or'd of FilePermissionPolicy. | 75 // The return value must be bitwise-or'd of FilePermissionPolicy. |
| 76 // | 76 // |
| 77 // Note: if a part of a filesystem is returned via 'Isolated' mount point, | 77 // Note: if a part of a filesystem is returned via 'Isolated' mount point, |
| 78 // its per-filesystem permission overrides the underlying filesystem's | 78 // its per-filesystem permission overrides the underlying filesystem's |
| 79 // permission policy. | 79 // permission policy. |
| 80 static int GetPermissionPolicy(FileSystemType type); | 80 static int GetPermissionPolicy(FileSystemType type); |
| 81 | 81 |
| 82 // task_runners->file_task_runner() is used as default TaskRunner. | 82 // task_runners->file_task_runner() is used as default TaskRunner. |
| 83 // Unless a MountPointProvider is overridden in CreateFileSystemOperation, | 83 // Unless a FileSystemBackend is overridden in CreateFileSystemOperation, |
| 84 // it is used for all file operations and file related meta operations. | 84 // it is used for all file operations and file related meta operations. |
| 85 // The code assumes that | 85 // The code assumes that |
| 86 // task_runners->file_task_runner()->RunsTasksOnCurrentThread() | 86 // task_runners->file_task_runner()->RunsTasksOnCurrentThread() |
| 87 // returns false if the current task is not running on the thread that allows | 87 // returns false if the current task is not running on the thread that allows |
| 88 // blocking file operations (like SequencedWorkerPool implementation does). | 88 // blocking file operations (like SequencedWorkerPool implementation does). |
| 89 // | 89 // |
| 90 // |external_mount_points| contains non-system external mount points available | 90 // |external_mount_points| contains non-system external mount points available |
| 91 // in the context. If not NULL, it will be used during URL cracking. On | 91 // in the context. If not NULL, it will be used during URL cracking. |
| 92 // ChromeOS, it will be passed to external_mount_point_provider. | |
| 93 // |external_mount_points| may be NULL only on platforms different from | 92 // |external_mount_points| may be NULL only on platforms different from |
| 94 // ChromeOS (i.e. platforms that don't use external_mount_point_provider). | 93 // ChromeOS (i.e. platforms that don't use external_mount_point_provider). |
| 95 // | 94 // |
| 96 // |additional_providers| are added to the internal provider map | 95 // |additional_backends| are added to the internal backend map |
| 97 // to serve filesystem requests for non-regular types. | 96 // to serve filesystem requests for non-regular types. |
| 98 // If none is given, this context only handles HTML5 Sandbox FileSystem | 97 // If none is given, this context only handles HTML5 Sandbox FileSystem |
| 99 // and Drag-and-drop Isolated FileSystem requests. | 98 // and Drag-and-drop Isolated FileSystem requests. |
| 100 FileSystemContext( | 99 FileSystemContext( |
| 101 scoped_ptr<FileSystemTaskRunners> task_runners, | 100 scoped_ptr<FileSystemTaskRunners> task_runners, |
| 102 ExternalMountPoints* external_mount_points, | 101 ExternalMountPoints* external_mount_points, |
| 103 quota::SpecialStoragePolicy* special_storage_policy, | 102 quota::SpecialStoragePolicy* special_storage_policy, |
| 104 quota::QuotaManagerProxy* quota_manager_proxy, | 103 quota::QuotaManagerProxy* quota_manager_proxy, |
| 105 ScopedVector<FileSystemMountPointProvider> additional_providers, | 104 ScopedVector<FileSystemBackend> additional_backends, |
| 106 const base::FilePath& partition_path, | 105 const base::FilePath& partition_path, |
| 107 const FileSystemOptions& options); | 106 const FileSystemOptions& options); |
| 108 | 107 |
| 109 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); | 108 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); |
| 110 | 109 |
| 111 quota::QuotaManagerProxy* quota_manager_proxy() const { | 110 quota::QuotaManagerProxy* quota_manager_proxy() const { |
| 112 return quota_manager_proxy_.get(); | 111 return quota_manager_proxy_.get(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 // Returns a quota util for a given filesystem type. This may | 114 // Returns a quota util for a given filesystem type. This may |
| 116 // return NULL if the type does not support the usage tracking or | 115 // return NULL if the type does not support the usage tracking or |
| 117 // it is not a quota-managed storage. | 116 // it is not a quota-managed storage. |
| 118 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; | 117 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; |
| 119 | 118 |
| 120 // Returns the appropriate AsyncFileUtil instance for the given |type|. | 119 // Returns the appropriate AsyncFileUtil instance for the given |type|. |
| 121 AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) const; | 120 AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) const; |
| 122 | 121 |
| 123 // Returns the appropriate FileUtil instance for the given |type|. | 122 // Returns the appropriate FileUtil instance for the given |type|. |
| 124 // This may return NULL if it is given an invalid type or the filesystem | 123 // This may return NULL if it is given an invalid type or the filesystem |
| 125 // does not support synchronous file operations. | 124 // does not support synchronous file operations. |
| 126 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; | 125 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; |
| 127 | 126 |
| 128 // Returns the appropriate CopyOrMoveFileValidatorFactory for the given | 127 // Returns the appropriate CopyOrMoveFileValidatorFactory for the given |
| 129 // |type|. If |error_code| is PLATFORM_FILE_OK and the result is NULL, | 128 // |type|. If |error_code| is PLATFORM_FILE_OK and the result is NULL, |
| 130 // then no validator is required. | 129 // then no validator is required. |
| 131 CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( | 130 CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( |
| 132 FileSystemType type, base::PlatformFileError* error_code) const; | 131 FileSystemType type, base::PlatformFileError* error_code) const; |
| 133 | 132 |
| 134 // Returns the mount point provider instance for the given |type|. | 133 // Returns the file system backend instance for the given |type|. |
| 135 // This may return NULL if it is given an invalid or unsupported filesystem | 134 // This may return NULL if it is given an invalid or unsupported filesystem |
| 136 // type. | 135 // type. |
| 137 FileSystemMountPointProvider* GetMountPointProvider( | 136 FileSystemBackend* GetFileSystemBackend( |
| 138 FileSystemType type) const; | 137 FileSystemType type) const; |
| 139 | 138 |
| 140 // Returns true for sandboxed filesystems. Currently this does | 139 // Returns true for sandboxed filesystems. Currently this does |
| 141 // the same as GetQuotaUtil(type) != NULL. (In an assumption that | 140 // the same as GetQuotaUtil(type) != NULL. (In an assumption that |
| 142 // all sandboxed filesystems must cooperate with QuotaManager so that | 141 // all sandboxed filesystems must cooperate with QuotaManager so that |
| 143 // they can get deleted) | 142 // they can get deleted) |
| 144 bool IsSandboxFileSystem(FileSystemType type) const; | 143 bool IsSandboxFileSystem(FileSystemType type) const; |
| 145 | 144 |
| 146 // Returns observers for the given filesystem type. | 145 // Returns observers for the given filesystem type. |
| 147 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const; | 146 const UpdateObserverList* GetUpdateObservers(FileSystemType type) const; |
| 148 const AccessObserverList* GetAccessObservers(FileSystemType type) const; | 147 const AccessObserverList* GetAccessObservers(FileSystemType type) const; |
| 149 | 148 |
| 150 // Returns all registered filesystem types. | 149 // Returns all registered filesystem types. |
| 151 void GetFileSystemTypes(std::vector<FileSystemType>* types) const; | 150 void GetFileSystemTypes(std::vector<FileSystemType>* types) const; |
| 152 | 151 |
| 153 // Returns a FileSystemMountPointProvider instance for external filesystem | 152 // Returns a FileSystemBackend instance for external filesystem |
| 154 // type, which is used only by chromeos for now. This is equivalent to | 153 // type, which is used only by chromeos for now. This is equivalent to |
| 155 // calling GetMountPointProvider(kFileSystemTypeExternal). | 154 // calling GetFileSystemBackend(kFileSystemTypeExternal). |
| 156 ExternalFileSystemMountPointProvider* external_provider() const; | 155 ExternalFileSystemBackend* external_backend() const; |
| 157 | 156 |
| 158 // Used for OpenFileSystem. | 157 // Used for OpenFileSystem. |
| 159 typedef base::Callback<void(base::PlatformFileError result, | 158 typedef base::Callback<void(base::PlatformFileError result, |
| 160 const std::string& name, | 159 const std::string& name, |
| 161 const GURL& root)> OpenFileSystemCallback; | 160 const GURL& root)> OpenFileSystemCallback; |
| 162 | 161 |
| 163 // Used for DeleteFileSystem. | 162 // Used for DeleteFileSystem. |
| 164 typedef base::Callback<void(base::PlatformFileError result)> | 163 typedef base::Callback<void(base::PlatformFileError result)> |
| 165 DeleteFileSystemCallback; | 164 DeleteFileSystemCallback; |
| 166 | 165 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 182 FileSystemType type, | 181 FileSystemType type, |
| 183 const DeleteFileSystemCallback& callback); | 182 const DeleteFileSystemCallback& callback); |
| 184 | 183 |
| 185 // Creates new FileStreamReader instance to read a file pointed by the given | 184 // Creates new FileStreamReader instance to read a file pointed by the given |
| 186 // filesystem URL |url| starting from |offset|. |expected_modification_time| | 185 // filesystem URL |url| starting from |offset|. |expected_modification_time| |
| 187 // specifies the expected last modification if the value is non-null, the | 186 // specifies the expected last modification if the value is non-null, the |
| 188 // reader will check the underlying file's actual modification time to see if | 187 // reader will check the underlying file's actual modification time to see if |
| 189 // the file has been modified, and if it does any succeeding read operations | 188 // the file has been modified, and if it does any succeeding read operations |
| 190 // should fail with ERR_UPLOAD_FILE_CHANGED error. | 189 // should fail with ERR_UPLOAD_FILE_CHANGED error. |
| 191 // This method internally cracks the |url|, get an appropriate | 190 // This method internally cracks the |url|, get an appropriate |
| 192 // MountPointProvider for the URL and call the provider's CreateFileReader. | 191 // FileSystemBackend for the URL and call the backend's CreateFileReader. |
| 193 // The resolved MountPointProvider could perform further specialization | 192 // The resolved FileSystemBackend could perform further specialization |
| 194 // depending on the filesystem type pointed by the |url|. | 193 // depending on the filesystem type pointed by the |url|. |
| 195 scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( | 194 scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( |
| 196 const FileSystemURL& url, | 195 const FileSystemURL& url, |
| 197 int64 offset, | 196 int64 offset, |
| 198 const base::Time& expected_modification_time); | 197 const base::Time& expected_modification_time); |
| 199 | 198 |
| 200 // Creates new FileStreamWriter instance to write into a file pointed by | 199 // Creates new FileStreamWriter instance to write into a file pointed by |
| 201 // |url| from |offset|. | 200 // |url| from |offset|. |
| 202 scoped_ptr<FileStreamWriter> CreateFileStreamWriter( | 201 scoped_ptr<FileStreamWriter> CreateFileStreamWriter( |
| 203 const FileSystemURL& url, | 202 const FileSystemURL& url, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 FileSystemURL CreateCrackedFileSystemURL(const GURL& origin, | 228 FileSystemURL CreateCrackedFileSystemURL(const GURL& origin, |
| 230 FileSystemType type, | 229 FileSystemType type, |
| 231 const base::FilePath& path) const; | 230 const base::FilePath& path) const; |
| 232 | 231 |
| 233 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | 232 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) |
| 234 // Used only on ChromeOS for now. | 233 // Used only on ChromeOS for now. |
| 235 void EnableTemporaryFileSystemInIncognito(); | 234 void EnableTemporaryFileSystemInIncognito(); |
| 236 #endif | 235 #endif |
| 237 | 236 |
| 238 private: | 237 private: |
| 239 typedef std::map<FileSystemType, FileSystemMountPointProvider*> | 238 typedef std::map<FileSystemType, FileSystemBackend*> |
| 240 MountPointProviderMap; | 239 FileSystemBackendMap; |
| 241 | 240 |
| 242 // For CreateFileSystemOperation. | 241 // For CreateFileSystemOperation. |
| 243 friend class FileSystemOperationRunner; | 242 friend class FileSystemOperationRunner; |
| 244 | 243 |
| 245 // For sandbox_provider(). | 244 // For sandbox_backend(). |
| 246 friend class SandboxFileSystemTestHelper; | 245 friend class SandboxFileSystemTestHelper; |
| 247 | 246 |
| 248 // Deleters. | 247 // Deleters. |
| 249 friend struct DefaultContextDeleter; | 248 friend struct DefaultContextDeleter; |
| 250 friend class base::DeleteHelper<FileSystemContext>; | 249 friend class base::DeleteHelper<FileSystemContext>; |
| 251 friend class base::RefCountedThreadSafe<FileSystemContext, | 250 friend class base::RefCountedThreadSafe<FileSystemContext, |
| 252 DefaultContextDeleter>; | 251 DefaultContextDeleter>; |
| 253 ~FileSystemContext(); | 252 ~FileSystemContext(); |
| 254 | 253 |
| 255 void DeleteOnCorrectThread() const; | 254 void DeleteOnCorrectThread() const; |
| 256 | 255 |
| 257 // Creates a new FileSystemOperation instance by getting an appropriate | 256 // Creates a new FileSystemOperation instance by getting an appropriate |
| 258 // MountPointProvider for |url| and calling the provider's corresponding | 257 // FileSystemBackend for |url| and calling the backend's corresponding |
| 259 // CreateFileSystemOperation method. | 258 // CreateFileSystemOperation method. |
| 260 // The resolved MountPointProvider could perform further specialization | 259 // The resolved FileSystemBackend could perform further specialization |
| 261 // depending on the filesystem type pointed by the |url|. | 260 // depending on the filesystem type pointed by the |url|. |
| 262 // | 261 // |
| 263 // Called by FileSystemOperationRunner. | 262 // Called by FileSystemOperationRunner. |
| 264 FileSystemOperation* CreateFileSystemOperation( | 263 FileSystemOperation* CreateFileSystemOperation( |
| 265 const FileSystemURL& url, | 264 const FileSystemURL& url, |
| 266 base::PlatformFileError* error_code); | 265 base::PlatformFileError* error_code); |
| 267 | 266 |
| 268 // For non-cracked isolated and external mount points, returns a FileSystemURL | 267 // For non-cracked isolated and external mount points, returns a FileSystemURL |
| 269 // created by cracking |url|. The url is cracked using MountPoints registered | 268 // created by cracking |url|. The url is cracked using MountPoints registered |
| 270 // as |url_crackers_|. If the url cannot be cracked, returns invalid | 269 // as |url_crackers_|. If the url cannot be cracked, returns invalid |
| 271 // FileSystemURL. | 270 // FileSystemURL. |
| 272 // | 271 // |
| 273 // If the original url does not point to an isolated or external filesystem, | 272 // If the original url does not point to an isolated or external filesystem, |
| 274 // returns the original url, without attempting to crack it. | 273 // returns the original url, without attempting to crack it. |
| 275 FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const; | 274 FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const; |
| 276 | 275 |
| 277 // For initial provider_map construction. This must be called only from | 276 // For initial backend_map construction. This must be called only from |
| 278 // the constructor. | 277 // the constructor. |
| 279 void RegisterMountPointProvider(FileSystemMountPointProvider* provider); | 278 void RegisterBackend(FileSystemBackend* backend); |
| 280 | 279 |
| 281 // Returns a FileSystemMountPointProvider, used only by test code. | 280 // Returns a FileSystemBackend, used only by test code. |
| 282 SandboxMountPointProvider* sandbox_provider() const { | 281 SandboxFileSystemBackend* sandbox_backend() const { |
| 283 return sandbox_provider_.get(); | 282 return sandbox_backend_.get(); |
| 284 } | 283 } |
| 285 | 284 |
| 286 scoped_ptr<FileSystemTaskRunners> task_runners_; | 285 scoped_ptr<FileSystemTaskRunners> task_runners_; |
| 287 | 286 |
| 288 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 287 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 289 | 288 |
| 290 // Regular mount point providers. | 289 // Regular file system backends. |
| 291 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; | 290 scoped_ptr<SandboxFileSystemBackend> sandbox_backend_; |
| 292 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; | 291 scoped_ptr<IsolatedFileSystemBackend> isolated_backend_; |
| 293 | 292 |
| 294 // Additional mount point providers. | 293 // Additional file system backends. |
| 295 ScopedVector<FileSystemMountPointProvider> additional_providers_; | 294 ScopedVector<FileSystemBackend> additional_backends_; |
| 296 | 295 |
| 297 // Registered mount point providers. | 296 // Registered file system backends. |
| 298 // The map must be constructed in the constructor since it can be accessed | 297 // The map must be constructed in the constructor since it can be accessed |
| 299 // on multiple threads. | 298 // on multiple threads. |
| 300 // This map itself doesn't retain each provider's ownership; ownerships | 299 // This map itself doesn't retain each backend's ownership; ownerships |
| 301 // of the providers are held by additional_providers_ or other scoped_ptr | 300 // of the backends are held by additional_backends_ or other scoped_ptr |
| 302 // provider fields. | 301 // backend fields. |
| 303 MountPointProviderMap provider_map_; | 302 FileSystemBackendMap backend_map_; |
| 304 | 303 |
| 305 // External mount points visible in the file system context (excluding system | 304 // External mount points visible in the file system context (excluding system |
| 306 // external mount points). | 305 // external mount points). |
| 307 scoped_refptr<ExternalMountPoints> external_mount_points_; | 306 scoped_refptr<ExternalMountPoints> external_mount_points_; |
| 308 | 307 |
| 309 // MountPoints used to crack FileSystemURLs. The MountPoints are ordered | 308 // MountPoints used to crack FileSystemURLs. The MountPoints are ordered |
| 310 // in order they should try to crack a FileSystemURL. | 309 // in order they should try to crack a FileSystemURL. |
| 311 std::vector<MountPoints*> url_crackers_; | 310 std::vector<MountPoints*> url_crackers_; |
| 312 | 311 |
| 313 // The base path of the storage partition for this context. | 312 // The base path of the storage partition for this context. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 324 | 323 |
| 325 struct DefaultContextDeleter { | 324 struct DefaultContextDeleter { |
| 326 static void Destruct(const FileSystemContext* context) { | 325 static void Destruct(const FileSystemContext* context) { |
| 327 context->DeleteOnCorrectThread(); | 326 context->DeleteOnCorrectThread(); |
| 328 } | 327 } |
| 329 }; | 328 }; |
| 330 | 329 |
| 331 } // namespace fileapi | 330 } // namespace fileapi |
| 332 | 331 |
| 333 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 332 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
| OLD | NEW |