| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
| 15 #include "webkit/fileapi/file_system_types.h" | 15 #include "webkit/fileapi/file_system_types.h" |
| 16 #include "webkit/quota/special_storage_policy.h" | 16 #include "webkit/quota/special_storage_policy.h" |
| 17 | 17 |
| 18 class FilePath; | 18 class FilePath; |
| 19 class GURL; | 19 class GURL; |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class MessageLoopProxy; | 22 class SequencedTaskRunner; |
| 23 class SingleThreadTaskRunner; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace quota { | 26 namespace quota { |
| 26 class QuotaManagerProxy; | 27 class QuotaManagerProxy; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace webkit_blob { | 30 namespace webkit_blob { |
| 30 class FileReader; | 31 class FileReader; |
| 31 } | 32 } |
| 32 | 33 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 class SandboxMountPointProvider; | 44 class SandboxMountPointProvider; |
| 44 | 45 |
| 45 struct DefaultContextDeleter; | 46 struct DefaultContextDeleter; |
| 46 | 47 |
| 47 // This class keeps and provides a file system context for FileSystem API. | 48 // This class keeps and provides a file system context for FileSystem API. |
| 48 // An instance of this class is created and owned by profile. | 49 // An instance of this class is created and owned by profile. |
| 49 class FileSystemContext | 50 class FileSystemContext |
| 50 : public base::RefCountedThreadSafe<FileSystemContext, | 51 : public base::RefCountedThreadSafe<FileSystemContext, |
| 51 DefaultContextDeleter> { | 52 DefaultContextDeleter> { |
| 52 public: | 53 public: |
| 54 // |file_task_runner| is used for all file operations and file related |
| 55 // meta operations. |
| 56 // The code assumes that file_task_runner->RunsTasksOnCurrentThread() returns |
| 57 // false if the current task is not running on the thread that allows |
| 58 // blocking file operations (like SequencedWorkerPool implementation does). |
| 53 FileSystemContext( | 59 FileSystemContext( |
| 54 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 60 base::SequencedTaskRunner* file_task_runner, |
| 55 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 61 base::SingleThreadTaskRunner* io_task_runner, |
| 56 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 62 quota::SpecialStoragePolicy* special_storage_policy, |
| 57 quota::QuotaManagerProxy* quota_manager_proxy, | 63 quota::QuotaManagerProxy* quota_manager_proxy, |
| 58 const FilePath& profile_path, | 64 const FilePath& profile_path, |
| 59 const FileSystemOptions& options); | 65 const FileSystemOptions& options); |
| 60 | 66 |
| 61 // This method can be called on any thread. | |
| 62 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); | 67 bool DeleteDataForOriginOnFileThread(const GURL& origin_url); |
| 63 bool DeleteDataForOriginAndTypeOnFileThread(const GURL& origin_url, | 68 bool DeleteDataForOriginAndTypeOnFileThread(const GURL& origin_url, |
| 64 FileSystemType type); | 69 FileSystemType type); |
| 65 | 70 |
| 66 quota::QuotaManagerProxy* quota_manager_proxy() const { | 71 quota::QuotaManagerProxy* quota_manager_proxy() const { |
| 67 return quota_manager_proxy_.get(); | 72 return quota_manager_proxy_.get(); |
| 68 } | 73 } |
| 69 | 74 |
| 75 base::SequencedTaskRunner* file_task_runner() const { |
| 76 return file_task_runner_.get(); |
| 77 } |
| 78 |
| 70 // Returns a quota util for a given filesystem type. This may | 79 // Returns a quota util for a given filesystem type. This may |
| 71 // return NULL if the type does not support the usage tracking or | 80 // return NULL if the type does not support the usage tracking or |
| 72 // it is not a quota-managed storage. | 81 // it is not a quota-managed storage. |
| 73 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; | 82 FileSystemQuotaUtil* GetQuotaUtil(FileSystemType type) const; |
| 74 | 83 |
| 75 // Returns the appropriate FileUtil instance for the given |type|. | 84 // Returns the appropriate FileUtil instance for the given |type|. |
| 76 // This may return NULL if it is given an invalid or unsupported filesystem | 85 // This may return NULL if it is given an invalid or unsupported filesystem |
| 77 // type. | 86 // type. |
| 78 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; | 87 FileSystemFileUtil* GetFileUtil(FileSystemType type) const; |
| 79 | 88 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 107 const GURL& origin_url, | 116 const GURL& origin_url, |
| 108 FileSystemType type, | 117 FileSystemType type, |
| 109 bool create, | 118 bool create, |
| 110 OpenFileSystemCallback callback); | 119 OpenFileSystemCallback callback); |
| 111 | 120 |
| 112 // Creates a new FileSystemOperation instance by cracking | 121 // Creates a new FileSystemOperation instance by cracking |
| 113 // the given filesystem URL |url| to get an appropriate MountPointProvider | 122 // the given filesystem URL |url| to get an appropriate MountPointProvider |
| 114 // and calling the provider's corresponding CreateFileSystemOperation method. | 123 // and calling the provider's corresponding CreateFileSystemOperation method. |
| 115 // The resolved MountPointProvider could perform further specialization | 124 // The resolved MountPointProvider could perform further specialization |
| 116 // depending on the filesystem type pointed by the |url|. | 125 // depending on the filesystem type pointed by the |url|. |
| 117 FileSystemOperationInterface* CreateFileSystemOperation( | 126 FileSystemOperationInterface* CreateFileSystemOperation(const GURL& url); |
| 118 const GURL& url, | |
| 119 base::MessageLoopProxy* file_proxy); | |
| 120 | 127 |
| 121 // Creates new FileReader instance to read a file pointed by the given | 128 // Creates new FileReader instance to read a file pointed by the given |
| 122 // filesystem URL |url| starting from |offset|. | 129 // filesystem URL |url| starting from |offset|. |
| 123 // This method internally cracks the |url|, get an appropriate | 130 // This method internally cracks the |url|, get an appropriate |
| 124 // MountPointProvider for the URL and call the provider's CreateFileReader. | 131 // MountPointProvider for the URL and call the provider's CreateFileReader. |
| 125 // The resolved MountPointProvider could perform further specialization | 132 // The resolved MountPointProvider could perform further specialization |
| 126 // depending on the filesystem type pointed by the |url|. | 133 // depending on the filesystem type pointed by the |url|. |
| 127 webkit_blob::FileReader* CreateFileReader( | 134 webkit_blob::FileReader* CreateFileReader( |
| 128 const GURL& url, | 135 const GURL& url, |
| 129 int64 offset, | 136 int64 offset); |
| 130 base::MessageLoopProxy* file_proxy); | |
| 131 | 137 |
| 132 private: | 138 private: |
| 133 friend struct DefaultContextDeleter; | 139 friend struct DefaultContextDeleter; |
| 134 friend class base::DeleteHelper<FileSystemContext>; | 140 friend class base::DeleteHelper<FileSystemContext>; |
| 135 ~FileSystemContext(); | 141 ~FileSystemContext(); |
| 136 | 142 |
| 137 void DeleteOnCorrectThread() const; | 143 void DeleteOnCorrectThread() const; |
| 138 | 144 |
| 139 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 145 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| 140 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 146 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 141 | 147 |
| 142 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 148 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
| 143 | 149 |
| 144 // Mount point providers. | 150 // Mount point providers. |
| 145 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; | 151 scoped_ptr<SandboxMountPointProvider> sandbox_provider_; |
| 146 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; | 152 scoped_ptr<IsolatedMountPointProvider> isolated_provider_; |
| 147 scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; | 153 scoped_ptr<ExternalFileSystemMountPointProvider> external_provider_; |
| 148 | 154 |
| 149 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); | 155 DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); |
| 150 }; | 156 }; |
| 151 | 157 |
| 152 struct DefaultContextDeleter { | 158 struct DefaultContextDeleter { |
| 153 static void Destruct(const FileSystemContext* context) { | 159 static void Destruct(const FileSystemContext* context) { |
| 154 context->DeleteOnCorrectThread(); | 160 context->DeleteOnCorrectThread(); |
| 155 } | 161 } |
| 156 }; | 162 }; |
| 157 | 163 |
| 158 } // namespace fileapi | 164 } // namespace fileapi |
| 159 | 165 |
| 160 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ | 166 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_CONTEXT_H_ |
| OLD | NEW |