Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: webkit/fileapi/file_system_context.cc

Issue 10197007: Change webkit/{fileapi,quota} code to use TaskRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "webkit/fileapi/file_system_context.h" 5 #include "webkit/fileapi/file_system_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/single_thread_task_runner.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "webkit/fileapi/file_system_file_util.h" 11 #include "webkit/fileapi/file_system_file_util.h"
12 #include "webkit/fileapi/file_system_operation_interface.h" 12 #include "webkit/fileapi/file_system_operation_interface.h"
13 #include "webkit/fileapi/file_system_options.h" 13 #include "webkit/fileapi/file_system_options.h"
14 #include "webkit/fileapi/file_system_quota_client.h" 14 #include "webkit/fileapi/file_system_quota_client.h"
15 #include "webkit/fileapi/file_system_util.h" 15 #include "webkit/fileapi/file_system_util.h"
16 #include "webkit/fileapi/isolated_mount_point_provider.h" 16 #include "webkit/fileapi/isolated_mount_point_provider.h"
17 #include "webkit/fileapi/sandbox_mount_point_provider.h" 17 #include "webkit/fileapi/sandbox_mount_point_provider.h"
18 #include "webkit/quota/quota_manager.h" 18 #include "webkit/quota/quota_manager.h"
19 #include "webkit/quota/special_storage_policy.h" 19 #include "webkit/quota/special_storage_policy.h"
20 20
21 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
22 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" 22 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
23 #endif 23 #endif
24 24
25 using quota::QuotaClient; 25 using quota::QuotaClient;
26 26
27 namespace fileapi { 27 namespace fileapi {
28 28
29 namespace { 29 namespace {
30 30
31 QuotaClient* CreateQuotaClient( 31 QuotaClient* CreateQuotaClient(
32 scoped_refptr<base::MessageLoopProxy> file_message_loop, 32 base::TaskRunner* file_task_runner,
33 FileSystemContext* context, 33 FileSystemContext* context,
34 bool is_incognito) { 34 bool is_incognito) {
35 return new FileSystemQuotaClient(file_message_loop, context, is_incognito); 35 return new FileSystemQuotaClient(file_task_runner, context, is_incognito);
36 } 36 }
37 37
38 void DidOpenFileSystem(FileSystemContext::OpenFileSystemCallback callback, 38 void DidOpenFileSystem(FileSystemContext::OpenFileSystemCallback callback,
39 const GURL& filesystem_root, 39 const GURL& filesystem_root,
40 const std::string& filesystem_name, 40 const std::string& filesystem_name,
41 base::PlatformFileError error) { 41 base::PlatformFileError error) {
42 callback.Run(error, filesystem_name, filesystem_root); 42 callback.Run(error, filesystem_name, filesystem_root);
43 } 43 }
44 44
45 } // anonymous namespace 45 } // anonymous namespace
46 46
47 FileSystemContext::FileSystemContext( 47 FileSystemContext::FileSystemContext(
48 scoped_refptr<base::MessageLoopProxy> file_message_loop, 48 base::SingleThreadTaskRunner* file_task_runner,
49 scoped_refptr<base::MessageLoopProxy> io_message_loop, 49 base::SingleThreadTaskRunner* io_task_runner,
50 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, 50 quota::SpecialStoragePolicy* special_storage_policy,
51 quota::QuotaManagerProxy* quota_manager_proxy, 51 quota::QuotaManagerProxy* quota_manager_proxy,
52 const FilePath& profile_path, 52 const FilePath& profile_path,
53 const FileSystemOptions& options) 53 const FileSystemOptions& options)
54 : file_message_loop_(file_message_loop), 54 : file_task_runner_(file_task_runner),
55 io_message_loop_(io_message_loop), 55 io_task_runner_(io_task_runner),
56 quota_manager_proxy_(quota_manager_proxy), 56 quota_manager_proxy_(quota_manager_proxy),
57 sandbox_provider_( 57 sandbox_provider_(
58 new SandboxMountPointProvider( 58 new SandboxMountPointProvider(
59 file_message_loop, 59 file_task_runner,
60 profile_path, 60 profile_path,
61 options)), 61 options)),
62 isolated_provider_(new IsolatedMountPointProvider) { 62 isolated_provider_(new IsolatedMountPointProvider) {
63 if (quota_manager_proxy) { 63 if (quota_manager_proxy) {
64 quota_manager_proxy->RegisterClient(CreateQuotaClient( 64 quota_manager_proxy->RegisterClient(CreateQuotaClient(
65 file_message_loop, this, options.is_incognito())); 65 file_task_runner, this, options.is_incognito()));
66 } 66 }
67 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
68 external_provider_.reset( 68 external_provider_.reset(
69 new chromeos::CrosMountPointProvider(special_storage_policy)); 69 new chromeos::CrosMountPointProvider(special_storage_policy));
70 #endif 70 #endif
71 } 71 }
72 72
73 FileSystemContext::~FileSystemContext() { 73 FileSystemContext::~FileSystemContext() {
74 } 74 }
75 75
76 bool FileSystemContext::DeleteDataForOriginOnFileThread( 76 bool FileSystemContext::DeleteDataForOriginOnFileThread(
77 const GURL& origin_url) { 77 const GURL& origin_url) {
78 DCHECK(file_message_loop_->BelongsToCurrentThread()); 78 DCHECK(file_task_runner_->BelongsToCurrentThread());
79 DCHECK(sandbox_provider()); 79 DCHECK(sandbox_provider());
80 80
81 // Delete temporary and persistent data. 81 // Delete temporary and persistent data.
82 return 82 return
83 sandbox_provider()->DeleteOriginDataOnFileThread( 83 sandbox_provider()->DeleteOriginDataOnFileThread(
84 quota_manager_proxy(), origin_url, kFileSystemTypeTemporary) && 84 quota_manager_proxy(), origin_url, kFileSystemTypeTemporary) &&
85 sandbox_provider()->DeleteOriginDataOnFileThread( 85 sandbox_provider()->DeleteOriginDataOnFileThread(
86 quota_manager_proxy(), origin_url, kFileSystemTypePersistent); 86 quota_manager_proxy(), origin_url, kFileSystemTypePersistent);
87 } 87 }
88 88
89 bool FileSystemContext::DeleteDataForOriginAndTypeOnFileThread( 89 bool FileSystemContext::DeleteDataForOriginAndTypeOnFileThread(
90 const GURL& origin_url, FileSystemType type) { 90 const GURL& origin_url, FileSystemType type) {
91 DCHECK(file_message_loop_->BelongsToCurrentThread()); 91 DCHECK(file_task_runner_->BelongsToCurrentThread());
92 if (type == fileapi::kFileSystemTypeTemporary || 92 if (type == fileapi::kFileSystemTypeTemporary ||
93 type == fileapi::kFileSystemTypePersistent) { 93 type == fileapi::kFileSystemTypePersistent) {
94 DCHECK(sandbox_provider()); 94 DCHECK(sandbox_provider());
95 return sandbox_provider()->DeleteOriginDataOnFileThread( 95 return sandbox_provider()->DeleteOriginDataOnFileThread(
96 quota_manager_proxy(), origin_url, type); 96 quota_manager_proxy(), origin_url, type);
97 } 97 }
98 return false; 98 return false;
99 } 99 }
100 100
101 FileSystemQuotaUtil* 101 FileSystemQuotaUtil*
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 FileSystemContext::sandbox_provider() const { 138 FileSystemContext::sandbox_provider() const {
139 return sandbox_provider_.get(); 139 return sandbox_provider_.get();
140 } 140 }
141 141
142 ExternalFileSystemMountPointProvider* 142 ExternalFileSystemMountPointProvider*
143 FileSystemContext::external_provider() const { 143 FileSystemContext::external_provider() const {
144 return external_provider_.get(); 144 return external_provider_.get();
145 } 145 }
146 146
147 void FileSystemContext::DeleteOnCorrectThread() const { 147 void FileSystemContext::DeleteOnCorrectThread() const {
148 if (!io_message_loop_->BelongsToCurrentThread() && 148 if (file_task_runner_->BelongsToCurrentThread() &&
michaeln 2012/04/27 01:04:03 Why the change from !IsOnIOThread to IsOnFileThrea
kinuko 2012/04/27 10:10:29 Sorry this change was not intended. Fixed.
149 io_message_loop_->DeleteSoon(FROM_HERE, this)) { 149 io_task_runner_->DeleteSoon(FROM_HERE, this)) {
150 return; 150 return;
151 } 151 }
152 delete this; 152 delete this;
153 } 153 }
154 154
155 void FileSystemContext::OpenFileSystem( 155 void FileSystemContext::OpenFileSystem(
156 const GURL& origin_url, 156 const GURL& origin_url,
157 FileSystemType type, 157 FileSystemType type,
158 bool create, 158 bool create,
159 OpenFileSystemCallback callback) { 159 OpenFileSystemCallback callback) {
160 DCHECK(!callback.is_null()); 160 DCHECK(!callback.is_null());
161 161
162 FileSystemMountPointProvider* mount_point_provider = 162 FileSystemMountPointProvider* mount_point_provider =
163 GetMountPointProvider(type); 163 GetMountPointProvider(type);
164 if (!mount_point_provider) { 164 if (!mount_point_provider) {
165 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); 165 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL());
166 return; 166 return;
167 } 167 }
168 168
169 GURL root_url = GetFileSystemRootURI(origin_url, type); 169 GURL root_url = GetFileSystemRootURI(origin_url, type);
170 std::string name = GetFileSystemName(origin_url, type); 170 std::string name = GetFileSystemName(origin_url, type);
171 171
172 mount_point_provider->ValidateFileSystemRoot( 172 mount_point_provider->ValidateFileSystemRoot(
173 origin_url, type, create, 173 origin_url, type, create,
174 base::Bind(&DidOpenFileSystem, callback, root_url, name)); 174 base::Bind(&DidOpenFileSystem, callback, root_url, name));
175 } 175 }
176 176
177 FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation( 177 FileSystemOperationInterface* FileSystemContext::CreateFileSystemOperation(
178 const GURL& url, 178 const GURL& url,
179 base::MessageLoopProxy* file_proxy) { 179 base::TaskRunner* file_proxy) {
180 GURL origin_url; 180 GURL origin_url;
181 FileSystemType file_system_type = kFileSystemTypeUnknown; 181 FileSystemType file_system_type = kFileSystemTypeUnknown;
182 FilePath file_path; 182 FilePath file_path;
183 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) 183 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path))
184 return NULL; 184 return NULL;
185 FileSystemMountPointProvider* mount_point_provider = 185 FileSystemMountPointProvider* mount_point_provider =
186 GetMountPointProvider(file_system_type); 186 GetMountPointProvider(file_system_type);
187 if (!mount_point_provider) 187 if (!mount_point_provider)
188 return NULL; 188 return NULL;
189 return mount_point_provider->CreateFileSystemOperation( 189 return mount_point_provider->CreateFileSystemOperation(
190 origin_url, file_system_type, file_path, file_proxy, this); 190 origin_url, file_system_type, file_path, file_proxy, this);
191 } 191 }
192 192
193 webkit_blob::FileReader* FileSystemContext::CreateFileReader( 193 webkit_blob::FileReader* FileSystemContext::CreateFileReader(
194 const GURL& url, 194 const GURL& url,
195 int64 offset, 195 int64 offset,
196 base::MessageLoopProxy* file_proxy) { 196 base::TaskRunner* file_proxy) {
197 GURL origin_url; 197 GURL origin_url;
198 FileSystemType file_system_type = kFileSystemTypeUnknown; 198 FileSystemType file_system_type = kFileSystemTypeUnknown;
199 FilePath file_path; 199 FilePath file_path;
200 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path)) 200 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &file_path))
201 return NULL; 201 return NULL;
202 FileSystemMountPointProvider* mount_point_provider = 202 FileSystemMountPointProvider* mount_point_provider =
203 GetMountPointProvider(file_system_type); 203 GetMountPointProvider(file_system_type);
204 if (!mount_point_provider) 204 if (!mount_point_provider)
205 return NULL; 205 return NULL;
206 return mount_point_provider->CreateFileReader(url, offset, file_proxy, this); 206 return mount_point_provider->CreateFileReader(url, offset, file_proxy, this);
207 } 207 }
208 208
209 } // namespace fileapi 209 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698