| 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 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/sequenced_task_runner_helpers.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 15 #include "base/sequenced_task_runner_helpers.h" | |
| 16 #include "webkit/fileapi/fileapi_export.h" | 16 #include "webkit/fileapi/fileapi_export.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/quota/special_storage_policy.h" | 18 #include "webkit/quota/special_storage_policy.h" |
| 19 | 19 |
| 20 class FilePath; | 20 class FilePath; |
| 21 | 21 |
| 22 namespace base { | |
| 23 class SequencedTaskRunner; | |
| 24 class SingleThreadTaskRunner; | |
| 25 } | |
| 26 | |
| 27 namespace quota { | 22 namespace quota { |
| 28 class QuotaManagerProxy; | 23 class QuotaManagerProxy; |
| 29 } | 24 } |
| 30 | 25 |
| 31 namespace webkit_blob { | 26 namespace webkit_blob { |
| 32 class FileStreamReader; | 27 class FileStreamReader; |
| 33 } | 28 } |
| 34 | 29 |
| 35 namespace fileapi { | 30 namespace fileapi { |
| 36 | 31 |
| 37 class ExternalFileSystemMountPointProvider; | 32 class ExternalFileSystemMountPointProvider; |
| 38 class FileSystemFileUtil; | 33 class FileSystemFileUtil; |
| 39 class FileSystemMountPointProvider; | 34 class FileSystemMountPointProvider; |
| 40 class FileSystemOperationInterface; | 35 class FileSystemOperationInterface; |
| 41 class FileSystemOptions; | 36 class FileSystemOptions; |
| 42 class FileSystemQuotaUtil; | 37 class FileSystemQuotaUtil; |
| 38 class FileSystemTaskRunners; |
| 43 class FileSystemURL; | 39 class FileSystemURL; |
| 44 class IsolatedMountPointProvider; | 40 class IsolatedMountPointProvider; |
| 45 class SandboxMountPointProvider; | 41 class SandboxMountPointProvider; |
| 46 | 42 |
| 47 struct DefaultContextDeleter; | 43 struct DefaultContextDeleter; |
| 48 | 44 |
| 49 // This class keeps and provides a file system context for FileSystem API. | 45 // This class keeps and provides a file system context for FileSystem API. |
| 50 // An instance of this class is created and owned by profile. | 46 // An instance of this class is created and owned by profile. |
| 51 class FILEAPI_EXPORT FileSystemContext | 47 class FILEAPI_EXPORT FileSystemContext |
| 52 : public base::RefCountedThreadSafe<FileSystemContext, | 48 : public base::RefCountedThreadSafe<FileSystemContext, |
| 53 DefaultContextDeleter> { | 49 DefaultContextDeleter> { |
| 54 public: | 50 public: |
| 55 // |file_task_runner| is used for all file operations and file related | 51 // task_runners->file_task_runner() is used as default TaskRunner. |
| 56 // meta operations. | 52 // Unless a MountPointProvired is override in CreateFileSystemOperation, |
| 57 // The code assumes that file_task_runner->RunsTasksOnCurrentThread() returns | 53 // it is used for all file operations and file related meta operations. |
| 58 // false if the current task is not running on the thread that allows | 54 // The code assumes that |
| 55 // task_runners->file_task_runner()->RunsTasksOnCurrentThread() |
| 56 // returns false if the current task is not running on the thread that allows |
| 59 // blocking file operations (like SequencedWorkerPool implementation does). | 57 // blocking file operations (like SequencedWorkerPool implementation does). |
| 60 FileSystemContext( | 58 FileSystemContext( |
| 61 base::SequencedTaskRunner* file_task_runner, | 59 scoped_ptr<FileSystemTaskRunners> task_runners, |
| 62 base::SingleThreadTaskRunner* io_task_runner, | |
| 63 quota::SpecialStoragePolicy* special_storage_policy, | 60 quota::SpecialStoragePolicy* special_storage_policy, |
| 64 quota::QuotaManagerProxy* quota_manager_proxy, | 61 quota::QuotaManagerProxy* quota_manager_proxy, |
| 65 const FilePath& profile_path, | 62 const FilePath& profile_path, |
| 66 const FileSystemOptions& options); | 63 const FileSystemOptions& options); |
| 67 | 64 |
| 68 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); | 65 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); |
| 69 | 66 |
| 70 quota::QuotaManagerProxy* quota_manager_proxy() const { | 67 quota::QuotaManagerProxy* quota_manager_proxy() const { |
| 71 return quota_manager_proxy_.get(); | 68 return quota_manager_proxy_.get(); |
| 72 } | 69 } |
| 73 | 70 |
| 74 base::SequencedTaskRunner* file_task_runner() const { | |
| 75 return file_task_runner_.get(); | |
| 76 } | |
| 77 | |
| 78 // Returns a quota util for a given filesystem type. This may | 71 // Returns a quota util for a given filesystem type. This may |
| 79 // return NULL if the type does not support the usage tracking or | 72 // return NULL if the type does not support the usage tracking or |
| 80 // it is not a quota-managed storage. | 73 // it is not a quota-managed storage. |
| 81 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; | 74 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; |
| 82 | 75 |
| 83 // Returns the appropriate FileUtil instance for the given |type|. | 76 // Returns the appropriate FileUtil instance for the given |type|. |
| 84 // This may return NULL if it is given an invalid or unsupported filesystem | 77 // This may return NULL if it is given an invalid or unsupported filesystem |
| 85 // type. | 78 // type. |
| 86 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; | 79 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; |
| 87 | 80 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // depending on the filesystem type pointed by the |url|. | 136 // depending on the filesystem type pointed by the |url|. |
| 144 webkit_blob::FileStreamReader* CreateFileStreamReader( | 137 webkit_blob::FileStreamReader* CreateFileStreamReader( |
| 145 const FileSystemURL& url, | 138 const FileSystemURL& url, |
| 146 int64 offset); | 139 int64 offset); |
| 147 | 140 |
| 148 // Register a filesystem provider. The ownership of |provider| is | 141 // Register a filesystem provider. The ownership of |provider| is |
| 149 // transferred to this instance. | 142 // transferred to this instance. |
| 150 void RegisterMountPointProvider(FileSystemType type, | 143 void RegisterMountPointProvider(FileSystemType type, |
| 151 FileSystemMountPointProvider* provider); | 144 FileSystemMountPointProvider* provider); |
| 152 | 145 |
| 146 FileSystemTaskRunners* task_runners() { return task_runners_.get(); } |
| 147 |
| 153 private: | 148 private: |
| 154 friend struct DefaultContextDeleter; | 149 friend struct DefaultContextDeleter; |
| 155 friend class base::DeleteHelper<FileSystemContext>; | 150 friend class base::DeleteHelper<FileSystemContext>; |
| 156 friend class base::RefCountedThreadSafe<FileSystemContext, | 151 friend class base::RefCountedThreadSafe<FileSystemContext, |
| 157 DefaultContextDeleter>; | 152 DefaultContextDeleter>; |
| 158 ~FileSystemContext(); | 153 ~FileSystemContext(); |
| 159 | 154 |
| 160 void DeleteOnCorrectThread() const; | 155 void DeleteOnCorrectThread() const; |
| 161 | 156 |
| 162 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 157 scoped_ptr<FileSystemTaskRunners> task_runners_; |
| 163 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 164 | 158 |
| 165 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 159 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 166 | 160 |
| 167 // Regular mount point providers. | 161 // Regular mount point providers. |
| 168 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; | 162 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; |
| 169 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; | 163 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; |
| 170 scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; | 164 scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; |
| 171 | 165 |
| 172 // Registered mount point providers. | 166 // Registered mount point providers. |
| 173 std::map<FileSystemType, FileSystemMountPointProvider*> provider_map_; | 167 std::map<FileSystemType, FileSystemMountPointProvider*> provider_map_; |
| 174 | 168 |
| 175 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); | 169 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); |
| 176 }; | 170 }; |
| 177 | 171 |
| 178 struct DefaultContextDeleter { | 172 struct DefaultContextDeleter { |
| 179 static void Destruct(const FileSystemContext* context) { | 173 static void Destruct(const FileSystemContext* context) { |
| 180 context->DeleteOnCorrectThread(); | 174 context->DeleteOnCorrectThread(); |
| 181 } | 175 } |
| 182 }; | 176 }; |
| 183 | 177 |
| 184 } // namespace fileapi | 178 } // namespace fileapi |
| 185 | 179 |
| 186 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 180 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
| OLD | NEW |