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

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

Issue 23856002: SyncFS: Support resolveLocalFileSystemURL on SyncFileSystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add struct FileSystemInfo, and change file path manipulation Created 7 years, 3 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 "webkit/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 "url/gurl.h" 11 #include "url/gurl.h"
12 #include "webkit/browser/blob/file_stream_reader.h" 12 #include "webkit/browser/blob/file_stream_reader.h"
13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
14 #include "webkit/browser/fileapi/external_mount_points.h" 14 #include "webkit/browser/fileapi/external_mount_points.h"
15 #include "webkit/browser/fileapi/file_permission_policy.h" 15 #include "webkit/browser/fileapi/file_permission_policy.h"
16 #include "webkit/browser/fileapi/file_stream_writer.h" 16 #include "webkit/browser/fileapi/file_stream_writer.h"
17 #include "webkit/browser/fileapi/file_system_file_util.h" 17 #include "webkit/browser/fileapi/file_system_file_util.h"
18 #include "webkit/browser/fileapi/file_system_operation.h" 18 #include "webkit/browser/fileapi/file_system_operation.h"
19 #include "webkit/browser/fileapi/file_system_operation_runner.h" 19 #include "webkit/browser/fileapi/file_system_operation_runner.h"
20 #include "webkit/browser/fileapi/file_system_options.h" 20 #include "webkit/browser/fileapi/file_system_options.h"
21 #include "webkit/browser/fileapi/file_system_quota_client.h" 21 #include "webkit/browser/fileapi/file_system_quota_client.h"
22 #include "webkit/browser/fileapi/file_system_url.h" 22 #include "webkit/browser/fileapi/file_system_url.h"
23 #include "webkit/browser/fileapi/isolated_context.h" 23 #include "webkit/browser/fileapi/isolated_context.h"
24 #include "webkit/browser/fileapi/isolated_file_system_backend.h" 24 #include "webkit/browser/fileapi/isolated_file_system_backend.h"
25 #include "webkit/browser/fileapi/mount_points.h" 25 #include "webkit/browser/fileapi/mount_points.h"
26 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 26 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
27 #include "webkit/browser/fileapi/test_file_system_backend.h" 27 #include "webkit/browser/fileapi/test_file_system_backend.h"
28 #include "webkit/browser/quota/quota_manager.h" 28 #include "webkit/browser/quota/quota_manager.h"
29 #include "webkit/browser/quota/special_storage_policy.h" 29 #include "webkit/browser/quota/special_storage_policy.h"
30 #include "webkit/common/fileapi/file_system_info.h"
30 #include "webkit/common/fileapi/file_system_util.h" 31 #include "webkit/common/fileapi/file_system_util.h"
31 32
32 using quota::QuotaClient; 33 using quota::QuotaClient;
33 34
34 namespace fileapi { 35 namespace fileapi {
35 36
36 namespace { 37 namespace {
37 38
38 QuotaClient* CreateQuotaClient( 39 QuotaClient* CreateQuotaClient(
39 FileSystemContext* context, 40 FileSystemContext* context,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 FileSystemBackend* backend = GetFileSystemBackend(type); 269 FileSystemBackend* backend = GetFileSystemBackend(type);
269 if (!backend) { 270 if (!backend) {
270 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); 271 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL());
271 return; 272 return;
272 } 273 }
273 274
274 backend->OpenFileSystem(origin_url, type, mode, 275 backend->OpenFileSystem(origin_url, type, mode,
275 base::Bind(&DidOpenFileSystem, callback)); 276 base::Bind(&DidOpenFileSystem, callback));
276 } 277 }
277 278
279 void FileSystemContext::ResolveURL(
280 const FileSystemURL& url,
281 const ResolveURLCallback& callback) {
282 DCHECK(!callback.is_null());
kinuko 2013/09/09 12:52:23 Can we add DCHECK(io_task_runner_->RunsTasksOnCurr
nhiroki 2013/09/10 06:30:39 Added the check for the ResolveURL. I'm going to
283
284 FileSystemBackend* backend = GetFileSystemBackend(url.type());
285 if (!backend) {
286 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY,
287 FileSystemInfo(), base::FilePath(), false);
288 return;
289 }
290
291 backend->OpenFileSystem(
292 url.origin(), url.type(),
293 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
294 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL,
295 this, url, callback));
296 }
297
278 void FileSystemContext::DeleteFileSystem( 298 void FileSystemContext::DeleteFileSystem(
279 const GURL& origin_url, 299 const GURL& origin_url,
280 FileSystemType type, 300 FileSystemType type,
281 const DeleteFileSystemCallback& callback) { 301 const DeleteFileSystemCallback& callback) {
282 DCHECK(origin_url == origin_url.GetOrigin()); 302 DCHECK(origin_url == origin_url.GetOrigin());
283 FileSystemBackend* backend = GetFileSystemBackend(type); 303 FileSystemBackend* backend = GetFileSystemBackend(type);
284 if (!backend) { 304 if (!backend) {
285 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 305 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY);
286 return; 306 return;
287 } 307 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (cracked.is_valid()) 437 if (cracked.is_valid())
418 break; 438 break;
419 } 439 }
420 if (cracked == current) 440 if (cracked == current)
421 break; 441 break;
422 current = cracked; 442 current = cracked;
423 } 443 }
424 return current; 444 return current;
425 } 445 }
426 446
427 void FileSystemContext::RegisterBackend( 447 void FileSystemContext::RegisterBackend(FileSystemBackend* backend) {
428 FileSystemBackend* backend) {
429 const FileSystemType mount_types[] = { 448 const FileSystemType mount_types[] = {
430 kFileSystemTypeTemporary, 449 kFileSystemTypeTemporary,
431 kFileSystemTypePersistent, 450 kFileSystemTypePersistent,
432 kFileSystemTypeIsolated, 451 kFileSystemTypeIsolated,
433 kFileSystemTypeExternal, 452 kFileSystemTypeExternal,
434 }; 453 };
435 // Register file system backends for public mount types. 454 // Register file system backends for public mount types.
436 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { 455 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) {
437 if (backend->CanHandleType(mount_types[j])) { 456 if (backend->CanHandleType(mount_types[j])) {
438 const bool inserted = backend_map_.insert( 457 const bool inserted = backend_map_.insert(
439 std::make_pair(mount_types[j], backend)).second; 458 std::make_pair(mount_types[j], backend)).second;
440 DCHECK(inserted); 459 DCHECK(inserted);
441 } 460 }
442 } 461 }
443 // Register file system backends for internal types. 462 // Register file system backends for internal types.
444 for (int t = kFileSystemInternalTypeEnumStart + 1; 463 for (int t = kFileSystemInternalTypeEnumStart + 1;
445 t < kFileSystemInternalTypeEnumEnd; ++t) { 464 t < kFileSystemInternalTypeEnumEnd; ++t) {
446 FileSystemType type = static_cast<FileSystemType>(t); 465 FileSystemType type = static_cast<FileSystemType>(t);
447 if (backend->CanHandleType(type)) { 466 if (backend->CanHandleType(type)) {
448 const bool inserted = backend_map_.insert( 467 const bool inserted = backend_map_.insert(
449 std::make_pair(type, backend)).second; 468 std::make_pair(type, backend)).second;
450 DCHECK(inserted); 469 DCHECK(inserted);
451 } 470 }
452 } 471 }
453 } 472 }
454 473
474 void FileSystemContext::DidOpenFileSystemForResolveURL(
475 const FileSystemURL& url,
476 const FileSystemContext::ResolveURLCallback& callback,
477 const GURL& filesystem_root,
478 const std::string& filesystem_name,
479 base::PlatformFileError error) {
480 if (error != base::PLATFORM_FILE_OK) {
481 callback.Run(error, FileSystemInfo(), base::FilePath(), false);
482 return;
483 }
484 fileapi::FileSystemInfo info(
485 filesystem_name, filesystem_root, url.mount_type());
486
487 // Extract the virtual path not containing a filesystem type part from |url|.
488 base::FilePath parent =
489 base::FilePath::FromUTF8Unsafe(filesystem_root.path());
490 base::FilePath child = base::FilePath::FromUTF8Unsafe(url.ToGURL().path());
491 base::FilePath path;
492 bool result = parent.AppendRelativePath(child, &path);
493 DCHECK(result);
494
495 operation_runner()->GetMetadata(
496 url,
497 base::Bind(&FileSystemContext::DidGetMetadataForResolveURL,
498 this, path, callback, info));
499 }
500
501 void FileSystemContext::DidGetMetadataForResolveURL(
kinuko 2013/09/09 12:52:23 Does this need to be a method of FSC? (I guess Di
nhiroki 2013/09/10 06:30:39 Done.
502 const base::FilePath& path,
503 const FileSystemContext::ResolveURLCallback& callback,
504 const FileSystemInfo& info,
505 base::PlatformFileError error,
506 const base::PlatformFileInfo& file_info) {
507 if (error != base::PLATFORM_FILE_OK) {
508 callback.Run(error, FileSystemInfo(), base::FilePath(), false);
509 return;
510 }
511 callback.Run(error, info, path, file_info.is_directory);
512 }
513
455 } // namespace fileapi 514 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698