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

Side by Side Diff: storage/browser/fileapi/file_system_context.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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/browser/fileapi/file_system_context.h" 5 #include "storage/browser/fileapi/file_system_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
11 #include "net/url_request/url_request.h" 11 #include "net/url_request/url_request.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 #include "webkit/browser/blob/file_stream_reader.h" 13 #include "storage/browser/blob/file_stream_reader.h"
14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 14 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
15 #include "webkit/browser/fileapi/external_mount_points.h" 15 #include "storage/browser/fileapi/external_mount_points.h"
16 #include "webkit/browser/fileapi/file_permission_policy.h" 16 #include "storage/browser/fileapi/file_permission_policy.h"
17 #include "webkit/browser/fileapi/file_stream_writer.h" 17 #include "storage/browser/fileapi/file_stream_writer.h"
18 #include "webkit/browser/fileapi/file_system_file_util.h" 18 #include "storage/browser/fileapi/file_system_file_util.h"
19 #include "webkit/browser/fileapi/file_system_operation.h" 19 #include "storage/browser/fileapi/file_system_operation.h"
20 #include "webkit/browser/fileapi/file_system_operation_runner.h" 20 #include "storage/browser/fileapi/file_system_operation_runner.h"
21 #include "webkit/browser/fileapi/file_system_options.h" 21 #include "storage/browser/fileapi/file_system_options.h"
22 #include "webkit/browser/fileapi/file_system_quota_client.h" 22 #include "storage/browser/fileapi/file_system_quota_client.h"
23 #include "webkit/browser/fileapi/file_system_url.h" 23 #include "storage/browser/fileapi/file_system_url.h"
24 #include "webkit/browser/fileapi/isolated_context.h" 24 #include "storage/browser/fileapi/isolated_context.h"
25 #include "webkit/browser/fileapi/isolated_file_system_backend.h" 25 #include "storage/browser/fileapi/isolated_file_system_backend.h"
26 #include "webkit/browser/fileapi/mount_points.h" 26 #include "storage/browser/fileapi/mount_points.h"
27 #include "webkit/browser/fileapi/quota/quota_reservation.h" 27 #include "storage/browser/fileapi/quota/quota_reservation.h"
28 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 28 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
29 #include "webkit/browser/quota/quota_manager_proxy.h" 29 #include "storage/browser/quota/quota_manager_proxy.h"
30 #include "webkit/browser/quota/special_storage_policy.h" 30 #include "storage/browser/quota/special_storage_policy.h"
31 #include "webkit/common/fileapi/file_system_info.h" 31 #include "storage/common/fileapi/file_system_info.h"
32 #include "webkit/common/fileapi/file_system_util.h" 32 #include "storage/common/fileapi/file_system_util.h"
33 33
34 using quota::QuotaClient; 34 using quota::QuotaClient;
35 35
36 namespace fileapi { 36 namespace storage {
37 37
38 namespace { 38 namespace {
39 39
40 QuotaClient* CreateQuotaClient( 40 QuotaClient* CreateQuotaClient(FileSystemContext* context, bool is_incognito) {
41 FileSystemContext* context,
42 bool is_incognito) {
43 return new FileSystemQuotaClient(context, is_incognito); 41 return new FileSystemQuotaClient(context, is_incognito);
44 } 42 }
45 43
46
47 void DidGetMetadataForResolveURL( 44 void DidGetMetadataForResolveURL(
48 const base::FilePath& path, 45 const base::FilePath& path,
49 const FileSystemContext::ResolveURLCallback& callback, 46 const FileSystemContext::ResolveURLCallback& callback,
50 const FileSystemInfo& info, 47 const FileSystemInfo& info,
51 base::File::Error error, 48 base::File::Error error,
52 const base::File::Info& file_info) { 49 const base::File::Info& file_info) {
53 if (error != base::File::FILE_OK) { 50 if (error != base::File::FILE_OK) {
54 if (error == base::File::FILE_ERROR_NOT_FOUND) { 51 if (error == base::File::FILE_ERROR_NOT_FOUND) {
55 callback.Run(base::File::FILE_OK, info, path, 52 callback.Run(base::File::FILE_OK,
53 info,
54 path,
56 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND); 55 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
57 } else { 56 } else {
58 callback.Run(error, FileSystemInfo(), base::FilePath(), 57 callback.Run(error,
58 FileSystemInfo(),
59 base::FilePath(),
59 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND); 60 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
60 } 61 }
61 return; 62 return;
62 } 63 }
63 callback.Run(error, info, path, file_info.is_directory ? 64 callback.Run(error,
64 FileSystemContext::RESOLVED_ENTRY_DIRECTORY : 65 info,
65 FileSystemContext::RESOLVED_ENTRY_FILE); 66 path,
67 file_info.is_directory
68 ? FileSystemContext::RESOLVED_ENTRY_DIRECTORY
69 : FileSystemContext::RESOLVED_ENTRY_FILE);
66 } 70 }
67 71
68 void RelayResolveURLCallback( 72 void RelayResolveURLCallback(
69 scoped_refptr<base::MessageLoopProxy> message_loop, 73 scoped_refptr<base::MessageLoopProxy> message_loop,
70 const FileSystemContext::ResolveURLCallback& callback, 74 const FileSystemContext::ResolveURLCallback& callback,
71 base::File::Error result, 75 base::File::Error result,
72 const FileSystemInfo& info, 76 const FileSystemInfo& info,
73 const base::FilePath& file_path, 77 const base::FilePath& file_path,
74 FileSystemContext::ResolvedEntryType type) { 78 FileSystemContext::ResolvedEntryType type) {
75 message_loop->PostTask( 79 message_loop->PostTask(FROM_HERE,
76 FROM_HERE, base::Bind(callback, result, info, file_path, type)); 80 base::Bind(callback, result, info, file_path, type));
77 } 81 }
78 82
79 } // namespace 83 } // namespace
80 84
81 // static 85 // static
82 int FileSystemContext::GetPermissionPolicy(FileSystemType type) { 86 int FileSystemContext::GetPermissionPolicy(FileSystemType type) {
83 switch (type) { 87 switch (type) {
84 case kFileSystemTypeTemporary: 88 case kFileSystemTypeTemporary:
85 case kFileSystemTypePersistent: 89 case kFileSystemTypePersistent:
86 case kFileSystemTypeSyncable: 90 case kFileSystemTypeSyncable:
87 return FILE_PERMISSION_SANDBOX; 91 return FILE_PERMISSION_SANDBOX;
88 92
89 case kFileSystemTypeDrive: 93 case kFileSystemTypeDrive:
90 case kFileSystemTypeNativeForPlatformApp: 94 case kFileSystemTypeNativeForPlatformApp:
91 case kFileSystemTypeNativeLocal: 95 case kFileSystemTypeNativeLocal:
92 case kFileSystemTypeCloudDevice: 96 case kFileSystemTypeCloudDevice:
93 case kFileSystemTypeProvided: 97 case kFileSystemTypeProvided:
94 case kFileSystemTypeDeviceMediaAsFileStorage: 98 case kFileSystemTypeDeviceMediaAsFileStorage:
95 return FILE_PERMISSION_USE_FILE_PERMISSION; 99 return FILE_PERMISSION_USE_FILE_PERMISSION;
96 100
97 case kFileSystemTypeRestrictedNativeLocal: 101 case kFileSystemTypeRestrictedNativeLocal:
98 return FILE_PERMISSION_READ_ONLY | 102 return FILE_PERMISSION_READ_ONLY | FILE_PERMISSION_USE_FILE_PERMISSION;
99 FILE_PERMISSION_USE_FILE_PERMISSION;
100 103
101 case kFileSystemTypeDeviceMedia: 104 case kFileSystemTypeDeviceMedia:
102 case kFileSystemTypeIphoto: 105 case kFileSystemTypeIphoto:
103 case kFileSystemTypeItunes: 106 case kFileSystemTypeItunes:
104 case kFileSystemTypeNativeMedia: 107 case kFileSystemTypeNativeMedia:
105 case kFileSystemTypePicasa: 108 case kFileSystemTypePicasa:
106 return FILE_PERMISSION_USE_FILE_PERMISSION; 109 return FILE_PERMISSION_USE_FILE_PERMISSION;
107 110
108 // Following types are only accessed via IsolatedFileSystem, and 111 // Following types are only accessed via IsolatedFileSystem, and
109 // don't have their own permission policies. 112 // don't have their own permission policies.
(...skipping 26 matching lines...) Expand all
136 ExternalMountPoints* external_mount_points, 139 ExternalMountPoints* external_mount_points,
137 quota::SpecialStoragePolicy* special_storage_policy, 140 quota::SpecialStoragePolicy* special_storage_policy,
138 quota::QuotaManagerProxy* quota_manager_proxy, 141 quota::QuotaManagerProxy* quota_manager_proxy,
139 ScopedVector<FileSystemBackend> additional_backends, 142 ScopedVector<FileSystemBackend> additional_backends,
140 const std::vector<URLRequestAutoMountHandler>& auto_mount_handlers, 143 const std::vector<URLRequestAutoMountHandler>& auto_mount_handlers,
141 const base::FilePath& partition_path, 144 const base::FilePath& partition_path,
142 const FileSystemOptions& options) 145 const FileSystemOptions& options)
143 : io_task_runner_(io_task_runner), 146 : io_task_runner_(io_task_runner),
144 default_file_task_runner_(file_task_runner), 147 default_file_task_runner_(file_task_runner),
145 quota_manager_proxy_(quota_manager_proxy), 148 quota_manager_proxy_(quota_manager_proxy),
146 sandbox_delegate_(new SandboxFileSystemBackendDelegate( 149 sandbox_delegate_(
147 quota_manager_proxy, 150 new SandboxFileSystemBackendDelegate(quota_manager_proxy,
148 file_task_runner, 151 file_task_runner,
149 partition_path, 152 partition_path,
150 special_storage_policy, 153 special_storage_policy,
151 options)), 154 options)),
152 sandbox_backend_(new SandboxFileSystemBackend( 155 sandbox_backend_(new SandboxFileSystemBackend(sandbox_delegate_.get())),
153 sandbox_delegate_.get())),
154 isolated_backend_(new IsolatedFileSystemBackend()), 156 isolated_backend_(new IsolatedFileSystemBackend()),
155 plugin_private_backend_(new PluginPrivateFileSystemBackend( 157 plugin_private_backend_(
156 file_task_runner, 158 new PluginPrivateFileSystemBackend(file_task_runner,
157 partition_path, 159 partition_path,
158 special_storage_policy, 160 special_storage_policy,
159 options)), 161 options)),
160 additional_backends_(additional_backends.Pass()), 162 additional_backends_(additional_backends.Pass()),
161 auto_mount_handlers_(auto_mount_handlers), 163 auto_mount_handlers_(auto_mount_handlers),
162 external_mount_points_(external_mount_points), 164 external_mount_points_(external_mount_points),
163 partition_path_(partition_path), 165 partition_path_(partition_path),
164 is_incognito_(options.is_incognito()), 166 is_incognito_(options.is_incognito()),
165 operation_runner_(new FileSystemOperationRunner(this)) { 167 operation_runner_(new FileSystemOperationRunner(this)) {
166 RegisterBackend(sandbox_backend_.get()); 168 RegisterBackend(sandbox_backend_.get());
167 RegisterBackend(isolated_backend_.get()); 169 RegisterBackend(isolated_backend_.get());
168 RegisterBackend(plugin_private_backend_.get()); 170 RegisterBackend(plugin_private_backend_.get());
169 171
170 for (ScopedVector<FileSystemBackend>::const_iterator iter = 172 for (ScopedVector<FileSystemBackend>::const_iterator iter =
171 additional_backends_.begin(); 173 additional_backends_.begin();
172 iter != additional_backends_.end(); ++iter) { 174 iter != additional_backends_.end();
175 ++iter) {
173 RegisterBackend(*iter); 176 RegisterBackend(*iter);
174 } 177 }
175 178
176 if (quota_manager_proxy) { 179 if (quota_manager_proxy) {
177 // Quota client assumes all backends have registered. 180 // Quota client assumes all backends have registered.
178 quota_manager_proxy->RegisterClient(CreateQuotaClient( 181 quota_manager_proxy->RegisterClient(
179 this, options.is_incognito())); 182 CreateQuotaClient(this, options.is_incognito()));
180 } 183 }
181 184
182 sandbox_backend_->Initialize(this); 185 sandbox_backend_->Initialize(this);
183 isolated_backend_->Initialize(this); 186 isolated_backend_->Initialize(this);
184 plugin_private_backend_->Initialize(this); 187 plugin_private_backend_->Initialize(this);
185 for (ScopedVector<FileSystemBackend>::const_iterator iter = 188 for (ScopedVector<FileSystemBackend>::const_iterator iter =
186 additional_backends_.begin(); 189 additional_backends_.begin();
187 iter != additional_backends_.end(); ++iter) { 190 iter != additional_backends_.end();
191 ++iter) {
188 (*iter)->Initialize(this); 192 (*iter)->Initialize(this);
189 } 193 }
190 194
191 // Additional mount points must be added before regular system-wide 195 // Additional mount points must be added before regular system-wide
192 // mount points. 196 // mount points.
193 if (external_mount_points) 197 if (external_mount_points)
194 url_crackers_.push_back(external_mount_points); 198 url_crackers_.push_back(external_mount_points);
195 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); 199 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance());
196 url_crackers_.push_back(IsolatedContext::GetInstance()); 200 url_crackers_.push_back(IsolatedContext::GetInstance());
197 } 201 }
198 202
199 bool FileSystemContext::DeleteDataForOriginOnFileTaskRunner( 203 bool FileSystemContext::DeleteDataForOriginOnFileTaskRunner(
200 const GURL& origin_url) { 204 const GURL& origin_url) {
201 DCHECK(default_file_task_runner()->RunsTasksOnCurrentThread()); 205 DCHECK(default_file_task_runner()->RunsTasksOnCurrentThread());
202 DCHECK(origin_url == origin_url.GetOrigin()); 206 DCHECK(origin_url == origin_url.GetOrigin());
203 207
204 bool success = true; 208 bool success = true;
205 for (FileSystemBackendMap::iterator iter = backend_map_.begin(); 209 for (FileSystemBackendMap::iterator iter = backend_map_.begin();
206 iter != backend_map_.end(); 210 iter != backend_map_.end();
207 ++iter) { 211 ++iter) {
208 FileSystemBackend* backend = iter->second; 212 FileSystemBackend* backend = iter->second;
209 if (!backend->GetQuotaUtil()) 213 if (!backend->GetQuotaUtil())
210 continue; 214 continue;
211 if (backend->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner( 215 if (backend->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner(
212 this, quota_manager_proxy(), origin_url, iter->first) 216 this, quota_manager_proxy(), origin_url, iter->first) !=
213 != base::File::FILE_OK) { 217 base::File::FILE_OK) {
214 // Continue the loop, but record the failure. 218 // Continue the loop, but record the failure.
215 success = false; 219 success = false;
216 } 220 }
217 } 221 }
218 222
219 return success; 223 return success;
220 } 224 }
221 225
222 scoped_refptr<QuotaReservation> 226 scoped_refptr<QuotaReservation>
223 FileSystemContext::CreateQuotaReservationOnFileTaskRunner( 227 FileSystemContext::CreateQuotaReservationOnFileTaskRunner(
224 const GURL& origin_url, 228 const GURL& origin_url,
225 FileSystemType type) { 229 FileSystemType type) {
226 DCHECK(default_file_task_runner()->RunsTasksOnCurrentThread()); 230 DCHECK(default_file_task_runner()->RunsTasksOnCurrentThread());
227 FileSystemBackend* backend = GetFileSystemBackend(type); 231 FileSystemBackend* backend = GetFileSystemBackend(type);
228 if (!backend || !backend->GetQuotaUtil()) 232 if (!backend || !backend->GetQuotaUtil())
229 return scoped_refptr<QuotaReservation>(); 233 return scoped_refptr<QuotaReservation>();
230 return backend->GetQuotaUtil()->CreateQuotaReservationOnFileTaskRunner( 234 return backend->GetQuotaUtil()->CreateQuotaReservationOnFileTaskRunner(
231 origin_url, type); 235 origin_url, type);
232 } 236 }
233 237
234 void FileSystemContext::Shutdown() { 238 void FileSystemContext::Shutdown() {
235 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 239 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
236 io_task_runner_->PostTask( 240 io_task_runner_->PostTask(
237 FROM_HERE, base::Bind(&FileSystemContext::Shutdown, 241 FROM_HERE,
238 make_scoped_refptr(this))); 242 base::Bind(&FileSystemContext::Shutdown, make_scoped_refptr(this)));
239 return; 243 return;
240 } 244 }
241 operation_runner_->Shutdown(); 245 operation_runner_->Shutdown();
242 } 246 }
243 247
244 FileSystemQuotaUtil* 248 FileSystemQuotaUtil* FileSystemContext::GetQuotaUtil(
245 FileSystemContext::GetQuotaUtil(FileSystemType type) const { 249 FileSystemType type) const {
246 FileSystemBackend* backend = GetFileSystemBackend(type); 250 FileSystemBackend* backend = GetFileSystemBackend(type);
247 if (!backend) 251 if (!backend)
248 return NULL; 252 return NULL;
249 return backend->GetQuotaUtil(); 253 return backend->GetQuotaUtil();
250 } 254 }
251 255
252 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil( 256 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil(FileSystemType type) const {
253 FileSystemType type) const {
254 FileSystemBackend* backend = GetFileSystemBackend(type); 257 FileSystemBackend* backend = GetFileSystemBackend(type);
255 if (!backend) 258 if (!backend)
256 return NULL; 259 return NULL;
257 return backend->GetAsyncFileUtil(type); 260 return backend->GetAsyncFileUtil(type);
258 } 261 }
259 262
260 CopyOrMoveFileValidatorFactory* 263 CopyOrMoveFileValidatorFactory*
261 FileSystemContext::GetCopyOrMoveFileValidatorFactory( 264 FileSystemContext::GetCopyOrMoveFileValidatorFactory(
262 FileSystemType type, base::File::Error* error_code) const { 265 FileSystemType type,
266 base::File::Error* error_code) const {
263 DCHECK(error_code); 267 DCHECK(error_code);
264 *error_code = base::File::FILE_OK; 268 *error_code = base::File::FILE_OK;
265 FileSystemBackend* backend = GetFileSystemBackend(type); 269 FileSystemBackend* backend = GetFileSystemBackend(type);
266 if (!backend) 270 if (!backend)
267 return NULL; 271 return NULL;
268 return backend->GetCopyOrMoveFileValidatorFactory( 272 return backend->GetCopyOrMoveFileValidatorFactory(type, error_code);
269 type, error_code);
270 } 273 }
271 274
272 FileSystemBackend* FileSystemContext::GetFileSystemBackend( 275 FileSystemBackend* FileSystemContext::GetFileSystemBackend(
273 FileSystemType type) const { 276 FileSystemType type) const {
274 FileSystemBackendMap::const_iterator found = backend_map_.find(type); 277 FileSystemBackendMap::const_iterator found = backend_map_.find(type);
275 if (found != backend_map_.end()) 278 if (found != backend_map_.end())
276 return found->second; 279 return found->second;
277 NOTREACHED() << "Unknown filesystem type: " << type; 280 NOTREACHED() << "Unknown filesystem type: " << type;
278 return NULL; 281 return NULL;
279 } 282 }
(...skipping 16 matching lines...) Expand all
296 FileSystemBackend* backend = GetFileSystemBackend(type); 299 FileSystemBackend* backend = GetFileSystemBackend(type);
297 if (backend->GetQuotaUtil()) 300 if (backend->GetQuotaUtil())
298 return backend->GetQuotaUtil()->GetAccessObservers(type); 301 return backend->GetQuotaUtil()->GetAccessObservers(type);
299 return NULL; 302 return NULL;
300 } 303 }
301 304
302 void FileSystemContext::GetFileSystemTypes( 305 void FileSystemContext::GetFileSystemTypes(
303 std::vector<FileSystemType>* types) const { 306 std::vector<FileSystemType>* types) const {
304 types->clear(); 307 types->clear();
305 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); 308 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin();
306 iter != backend_map_.end(); ++iter) 309 iter != backend_map_.end();
310 ++iter)
307 types->push_back(iter->first); 311 types->push_back(iter->first);
308 } 312 }
309 313
310 ExternalFileSystemBackend* 314 ExternalFileSystemBackend* FileSystemContext::external_backend() const {
311 FileSystemContext::external_backend() const {
312 return static_cast<ExternalFileSystemBackend*>( 315 return static_cast<ExternalFileSystemBackend*>(
313 GetFileSystemBackend(kFileSystemTypeExternal)); 316 GetFileSystemBackend(kFileSystemTypeExternal));
314 } 317 }
315 318
316 void FileSystemContext::OpenFileSystem( 319 void FileSystemContext::OpenFileSystem(const GURL& origin_url,
317 const GURL& origin_url, 320 FileSystemType type,
318 FileSystemType type, 321 OpenFileSystemMode mode,
319 OpenFileSystemMode mode, 322 const OpenFileSystemCallback& callback) {
320 const OpenFileSystemCallback& callback) {
321 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 323 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
322 DCHECK(!callback.is_null()); 324 DCHECK(!callback.is_null());
323 325
324 if (!FileSystemContext::IsSandboxFileSystem(type)) { 326 if (!FileSystemContext::IsSandboxFileSystem(type)) {
325 // Disallow opening a non-sandboxed filesystem. 327 // Disallow opening a non-sandboxed filesystem.
326 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY); 328 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
327 return; 329 return;
328 } 330 }
329 331
330 FileSystemBackend* backend = GetFileSystemBackend(type); 332 FileSystemBackend* backend = GetFileSystemBackend(type);
331 if (!backend) { 333 if (!backend) {
332 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY); 334 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY);
333 return; 335 return;
334 } 336 }
335 337
336 backend->ResolveURL( 338 backend->ResolveURL(
337 CreateCrackedFileSystemURL(origin_url, type, base::FilePath()), 339 CreateCrackedFileSystemURL(origin_url, type, base::FilePath()),
338 mode, 340 mode,
339 callback); 341 callback);
340 } 342 }
341 343
342 void FileSystemContext::ResolveURL( 344 void FileSystemContext::ResolveURL(const FileSystemURL& url,
343 const FileSystemURL& url, 345 const ResolveURLCallback& callback) {
344 const ResolveURLCallback& callback) {
345 DCHECK(!callback.is_null()); 346 DCHECK(!callback.is_null());
346 347
347 // If not on IO thread, forward before passing the task to the backend. 348 // If not on IO thread, forward before passing the task to the backend.
348 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 349 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
349 ResolveURLCallback relay_callback = 350 ResolveURLCallback relay_callback = base::Bind(
350 base::Bind(&RelayResolveURLCallback, 351 &RelayResolveURLCallback, base::MessageLoopProxy::current(), callback);
351 base::MessageLoopProxy::current(), callback);
352 io_task_runner_->PostTask( 352 io_task_runner_->PostTask(
353 FROM_HERE, 353 FROM_HERE,
354 base::Bind(&FileSystemContext::ResolveURL, this, url, relay_callback)); 354 base::Bind(&FileSystemContext::ResolveURL, this, url, relay_callback));
355 return; 355 return;
356 } 356 }
357 357
358 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 358 FileSystemBackend* backend = GetFileSystemBackend(url.type());
359 if (!backend) { 359 if (!backend) {
360 callback.Run(base::File::FILE_ERROR_SECURITY, 360 callback.Run(base::File::FILE_ERROR_SECURITY,
361 FileSystemInfo(), base::FilePath(), 361 FileSystemInfo(),
362 base::FilePath(),
362 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND); 363 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
363 return; 364 return;
364 } 365 }
365 366
366 backend->ResolveURL( 367 backend->ResolveURL(
367 url, 368 url,
368 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 369 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
369 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL, 370 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL,
370 this, 371 this,
371 url, 372 url,
372 callback)); 373 callback));
373 } 374 }
374 375
375 void FileSystemContext::AttemptAutoMountForURLRequest( 376 void FileSystemContext::AttemptAutoMountForURLRequest(
376 const net::URLRequest* url_request, 377 const net::URLRequest* url_request,
377 const std::string& storage_domain, 378 const std::string& storage_domain,
378 const StatusCallback& callback) { 379 const StatusCallback& callback) {
379 FileSystemURL filesystem_url(url_request->url()); 380 FileSystemURL filesystem_url(url_request->url());
380 if (filesystem_url.type() == kFileSystemTypeExternal) { 381 if (filesystem_url.type() == kFileSystemTypeExternal) {
381 for (size_t i = 0; i < auto_mount_handlers_.size(); i++) { 382 for (size_t i = 0; i < auto_mount_handlers_.size(); i++) {
382 if (auto_mount_handlers_[i].Run(url_request, filesystem_url, 383 if (auto_mount_handlers_[i].Run(
383 storage_domain, callback)) { 384 url_request, filesystem_url, storage_domain, callback)) {
384 return; 385 return;
385 } 386 }
386 } 387 }
387 } 388 }
388 callback.Run(base::File::FILE_ERROR_NOT_FOUND); 389 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
389 } 390 }
390 391
391 void FileSystemContext::DeleteFileSystem( 392 void FileSystemContext::DeleteFileSystem(const GURL& origin_url,
392 const GURL& origin_url, 393 FileSystemType type,
393 FileSystemType type, 394 const StatusCallback& callback) {
394 const StatusCallback& callback) {
395 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 395 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
396 DCHECK(origin_url == origin_url.GetOrigin()); 396 DCHECK(origin_url == origin_url.GetOrigin());
397 DCHECK(!callback.is_null()); 397 DCHECK(!callback.is_null());
398 398
399 FileSystemBackend* backend = GetFileSystemBackend(type); 399 FileSystemBackend* backend = GetFileSystemBackend(type);
400 if (!backend) { 400 if (!backend) {
401 callback.Run(base::File::FILE_ERROR_SECURITY); 401 callback.Run(base::File::FILE_ERROR_SECURITY);
402 return; 402 return;
403 } 403 }
404 if (!backend->GetQuotaUtil()) { 404 if (!backend->GetQuotaUtil()) {
405 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); 405 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
406 return; 406 return;
407 } 407 }
408 408
409 base::PostTaskAndReplyWithResult( 409 base::PostTaskAndReplyWithResult(
410 default_file_task_runner(), 410 default_file_task_runner(),
411 FROM_HERE, 411 FROM_HERE,
412 // It is safe to pass Unretained(quota_util) since context owns it. 412 // It is safe to pass Unretained(quota_util) since context owns it.
413 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileTaskRunner, 413 base::Bind(&FileSystemQuotaUtil::DeleteOriginDataOnFileTaskRunner,
414 base::Unretained(backend->GetQuotaUtil()), 414 base::Unretained(backend->GetQuotaUtil()),
415 make_scoped_refptr(this), 415 make_scoped_refptr(this),
416 base::Unretained(quota_manager_proxy()), 416 base::Unretained(quota_manager_proxy()),
417 origin_url, 417 origin_url,
418 type), 418 type),
419 callback); 419 callback);
420 } 420 }
421 421
422 scoped_ptr<webkit_blob::FileStreamReader> 422 scoped_ptr<storage::FileStreamReader> FileSystemContext::CreateFileStreamReader(
423 FileSystemContext::CreateFileStreamReader(
424 const FileSystemURL& url, 423 const FileSystemURL& url,
425 int64 offset, 424 int64 offset,
426 const base::Time& expected_modification_time) { 425 const base::Time& expected_modification_time) {
427 if (!url.is_valid()) 426 if (!url.is_valid())
428 return scoped_ptr<webkit_blob::FileStreamReader>(); 427 return scoped_ptr<storage::FileStreamReader>();
429 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 428 FileSystemBackend* backend = GetFileSystemBackend(url.type());
430 if (!backend) 429 if (!backend)
431 return scoped_ptr<webkit_blob::FileStreamReader>(); 430 return scoped_ptr<storage::FileStreamReader>();
432 return backend->CreateFileStreamReader( 431 return backend->CreateFileStreamReader(
433 url, offset, expected_modification_time, this); 432 url, offset, expected_modification_time, this);
434 } 433 }
435 434
436 scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter( 435 scoped_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter(
437 const FileSystemURL& url, 436 const FileSystemURL& url,
438 int64 offset) { 437 int64 offset) {
439 if (!url.is_valid()) 438 if (!url.is_valid())
440 return scoped_ptr<FileStreamWriter>(); 439 return scoped_ptr<FileStreamWriter>();
441 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 440 FileSystemBackend* backend = GetFileSystemBackend(url.type());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 509
511 void FileSystemContext::DeleteOnCorrectThread() const { 510 void FileSystemContext::DeleteOnCorrectThread() const {
512 if (!io_task_runner_->RunsTasksOnCurrentThread() && 511 if (!io_task_runner_->RunsTasksOnCurrentThread() &&
513 io_task_runner_->DeleteSoon(FROM_HERE, this)) { 512 io_task_runner_->DeleteSoon(FROM_HERE, this)) {
514 return; 513 return;
515 } 514 }
516 delete this; 515 delete this;
517 } 516 }
518 517
519 FileSystemOperation* FileSystemContext::CreateFileSystemOperation( 518 FileSystemOperation* FileSystemContext::CreateFileSystemOperation(
520 const FileSystemURL& url, base::File::Error* error_code) { 519 const FileSystemURL& url,
520 base::File::Error* error_code) {
521 if (!url.is_valid()) { 521 if (!url.is_valid()) {
522 if (error_code) 522 if (error_code)
523 *error_code = base::File::FILE_ERROR_INVALID_URL; 523 *error_code = base::File::FILE_ERROR_INVALID_URL;
524 return NULL; 524 return NULL;
525 } 525 }
526 526
527 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 527 FileSystemBackend* backend = GetFileSystemBackend(url.type());
528 if (!backend) { 528 if (!backend) {
529 if (error_code) 529 if (error_code)
530 *error_code = base::File::FILE_ERROR_FAILED; 530 *error_code = base::File::FILE_ERROR_FAILED;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 562 }
563 if (cracked == current) 563 if (cracked == current)
564 break; 564 break;
565 current = cracked; 565 current = cracked;
566 } 566 }
567 return current; 567 return current;
568 } 568 }
569 569
570 void FileSystemContext::RegisterBackend(FileSystemBackend* backend) { 570 void FileSystemContext::RegisterBackend(FileSystemBackend* backend) {
571 const FileSystemType mount_types[] = { 571 const FileSystemType mount_types[] = {
572 kFileSystemTypeTemporary, 572 kFileSystemTypeTemporary, kFileSystemTypePersistent,
573 kFileSystemTypePersistent, 573 kFileSystemTypeIsolated, kFileSystemTypeExternal,
574 kFileSystemTypeIsolated,
575 kFileSystemTypeExternal,
576 }; 574 };
577 // Register file system backends for public mount types. 575 // Register file system backends for public mount types.
578 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { 576 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) {
579 if (backend->CanHandleType(mount_types[j])) { 577 if (backend->CanHandleType(mount_types[j])) {
580 const bool inserted = backend_map_.insert( 578 const bool inserted =
581 std::make_pair(mount_types[j], backend)).second; 579 backend_map_.insert(std::make_pair(mount_types[j], backend)).second;
582 DCHECK(inserted); 580 DCHECK(inserted);
583 } 581 }
584 } 582 }
585 // Register file system backends for internal types. 583 // Register file system backends for internal types.
586 for (int t = kFileSystemInternalTypeEnumStart + 1; 584 for (int t = kFileSystemInternalTypeEnumStart + 1;
587 t < kFileSystemInternalTypeEnumEnd; ++t) { 585 t < kFileSystemInternalTypeEnumEnd;
586 ++t) {
588 FileSystemType type = static_cast<FileSystemType>(t); 587 FileSystemType type = static_cast<FileSystemType>(t);
589 if (backend->CanHandleType(type)) { 588 if (backend->CanHandleType(type)) {
590 const bool inserted = backend_map_.insert( 589 const bool inserted =
591 std::make_pair(type, backend)).second; 590 backend_map_.insert(std::make_pair(type, backend)).second;
592 DCHECK(inserted); 591 DCHECK(inserted);
593 } 592 }
594 } 593 }
595 } 594 }
596 595
597 void FileSystemContext::DidOpenFileSystemForResolveURL( 596 void FileSystemContext::DidOpenFileSystemForResolveURL(
598 const FileSystemURL& url, 597 const FileSystemURL& url,
599 const FileSystemContext::ResolveURLCallback& callback, 598 const FileSystemContext::ResolveURLCallback& callback,
600 const GURL& filesystem_root, 599 const GURL& filesystem_root,
601 const std::string& filesystem_name, 600 const std::string& filesystem_name,
602 base::File::Error error) { 601 base::File::Error error) {
603 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 602 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
604 603
605 if (error != base::File::FILE_OK) { 604 if (error != base::File::FILE_OK) {
606 callback.Run(error, FileSystemInfo(), base::FilePath(), 605 callback.Run(error,
606 FileSystemInfo(),
607 base::FilePath(),
607 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND); 608 FileSystemContext::RESOLVED_ENTRY_NOT_FOUND);
608 return; 609 return;
609 } 610 }
610 611
611 fileapi::FileSystemInfo info( 612 storage::FileSystemInfo info(
612 filesystem_name, filesystem_root, url.mount_type()); 613 filesystem_name, filesystem_root, url.mount_type());
613 614
614 // Extract the virtual path not containing a filesystem type part from |url|. 615 // Extract the virtual path not containing a filesystem type part from |url|.
615 base::FilePath parent = CrackURL(filesystem_root).virtual_path(); 616 base::FilePath parent = CrackURL(filesystem_root).virtual_path();
616 base::FilePath child = url.virtual_path(); 617 base::FilePath child = url.virtual_path();
617 base::FilePath path; 618 base::FilePath path;
618 619
619 if (parent.empty()) { 620 if (parent.empty()) {
620 path = child; 621 path = child;
621 } else if (parent != child) { 622 } else if (parent != child) {
622 bool result = parent.AppendRelativePath(child, &path); 623 bool result = parent.AppendRelativePath(child, &path);
623 DCHECK(result); 624 DCHECK(result);
624 } 625 }
625 626
626 operation_runner()->GetMetadata( 627 operation_runner()->GetMetadata(
627 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info)); 628 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info));
628 } 629 }
629 630
630 } // namespace fileapi 631 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/file_system_context.h ('k') | storage/browser/fileapi/file_system_dir_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698