| 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 #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, |
| 40 bool is_incognito) { | 41 bool is_incognito) { |
| 41 return new FileSystemQuotaClient(context, is_incognito); | 42 return new FileSystemQuotaClient(context, is_incognito); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void DidOpenFileSystem( | 45 void DidOpenFileSystem( |
| 45 const FileSystemContext::OpenFileSystemCallback& callback, | 46 const FileSystemContext::OpenFileSystemCallback& callback, |
| 46 const GURL& filesystem_root, | 47 const GURL& filesystem_root, |
| 47 const std::string& filesystem_name, | 48 const std::string& filesystem_name, |
| 48 base::PlatformFileError error) { | 49 base::PlatformFileError error) { |
| 49 callback.Run(error, filesystem_name, filesystem_root); | 50 callback.Run(error, filesystem_name, filesystem_root); |
| 50 } | 51 } |
| 51 | 52 |
| 53 void DidGetMetadataForResolveURL( |
| 54 const base::FilePath& path, |
| 55 const FileSystemContext::ResolveURLCallback& callback, |
| 56 const FileSystemInfo& info, |
| 57 base::PlatformFileError error, |
| 58 const base::PlatformFileInfo& file_info) { |
| 59 if (error != base::PLATFORM_FILE_OK) { |
| 60 callback.Run(error, FileSystemInfo(), base::FilePath(), false); |
| 61 return; |
| 62 } |
| 63 callback.Run(error, info, path, file_info.is_directory); |
| 64 } |
| 65 |
| 52 } // namespace | 66 } // namespace |
| 53 | 67 |
| 54 // static | 68 // static |
| 55 int FileSystemContext::GetPermissionPolicy(FileSystemType type) { | 69 int FileSystemContext::GetPermissionPolicy(FileSystemType type) { |
| 56 switch (type) { | 70 switch (type) { |
| 57 case kFileSystemTypeTemporary: | 71 case kFileSystemTypeTemporary: |
| 58 case kFileSystemTypePersistent: | 72 case kFileSystemTypePersistent: |
| 59 case kFileSystemTypeSyncable: | 73 case kFileSystemTypeSyncable: |
| 60 return FILE_PERMISSION_SANDBOX; | 74 return FILE_PERMISSION_SANDBOX; |
| 61 | 75 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 FileSystemBackend* backend = GetFileSystemBackend(type); | 282 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 269 if (!backend) { | 283 if (!backend) { |
| 270 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); | 284 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); |
| 271 return; | 285 return; |
| 272 } | 286 } |
| 273 | 287 |
| 274 backend->OpenFileSystem(origin_url, type, mode, | 288 backend->OpenFileSystem(origin_url, type, mode, |
| 275 base::Bind(&DidOpenFileSystem, callback)); | 289 base::Bind(&DidOpenFileSystem, callback)); |
| 276 } | 290 } |
| 277 | 291 |
| 292 void FileSystemContext::ResolveURL( |
| 293 const FileSystemURL& url, |
| 294 const ResolveURLCallback& callback) { |
| 295 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 296 DCHECK(!callback.is_null()); |
| 297 |
| 298 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 299 if (!backend) { |
| 300 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, |
| 301 FileSystemInfo(), base::FilePath(), false); |
| 302 return; |
| 303 } |
| 304 |
| 305 backend->OpenFileSystem( |
| 306 url.origin(), url.type(), |
| 307 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 308 base::Bind(&FileSystemContext::DidOpenFileSystemForResolveURL, |
| 309 this, url, callback)); |
| 310 } |
| 311 |
| 278 void FileSystemContext::DeleteFileSystem( | 312 void FileSystemContext::DeleteFileSystem( |
| 279 const GURL& origin_url, | 313 const GURL& origin_url, |
| 280 FileSystemType type, | 314 FileSystemType type, |
| 281 const DeleteFileSystemCallback& callback) { | 315 const DeleteFileSystemCallback& callback) { |
| 282 DCHECK(origin_url == origin_url.GetOrigin()); | 316 DCHECK(origin_url == origin_url.GetOrigin()); |
| 283 FileSystemBackend* backend = GetFileSystemBackend(type); | 317 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 284 if (!backend) { | 318 if (!backend) { |
| 285 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 319 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
| 286 return; | 320 return; |
| 287 } | 321 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (cracked.is_valid()) | 451 if (cracked.is_valid()) |
| 418 break; | 452 break; |
| 419 } | 453 } |
| 420 if (cracked == current) | 454 if (cracked == current) |
| 421 break; | 455 break; |
| 422 current = cracked; | 456 current = cracked; |
| 423 } | 457 } |
| 424 return current; | 458 return current; |
| 425 } | 459 } |
| 426 | 460 |
| 427 void FileSystemContext::RegisterBackend( | 461 void FileSystemContext::RegisterBackend(FileSystemBackend* backend) { |
| 428 FileSystemBackend* backend) { | |
| 429 const FileSystemType mount_types[] = { | 462 const FileSystemType mount_types[] = { |
| 430 kFileSystemTypeTemporary, | 463 kFileSystemTypeTemporary, |
| 431 kFileSystemTypePersistent, | 464 kFileSystemTypePersistent, |
| 432 kFileSystemTypeIsolated, | 465 kFileSystemTypeIsolated, |
| 433 kFileSystemTypeExternal, | 466 kFileSystemTypeExternal, |
| 434 }; | 467 }; |
| 435 // Register file system backends for public mount types. | 468 // Register file system backends for public mount types. |
| 436 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { | 469 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(mount_types); ++j) { |
| 437 if (backend->CanHandleType(mount_types[j])) { | 470 if (backend->CanHandleType(mount_types[j])) { |
| 438 const bool inserted = backend_map_.insert( | 471 const bool inserted = backend_map_.insert( |
| 439 std::make_pair(mount_types[j], backend)).second; | 472 std::make_pair(mount_types[j], backend)).second; |
| 440 DCHECK(inserted); | 473 DCHECK(inserted); |
| 441 } | 474 } |
| 442 } | 475 } |
| 443 // Register file system backends for internal types. | 476 // Register file system backends for internal types. |
| 444 for (int t = kFileSystemInternalTypeEnumStart + 1; | 477 for (int t = kFileSystemInternalTypeEnumStart + 1; |
| 445 t < kFileSystemInternalTypeEnumEnd; ++t) { | 478 t < kFileSystemInternalTypeEnumEnd; ++t) { |
| 446 FileSystemType type = static_cast<FileSystemType>(t); | 479 FileSystemType type = static_cast<FileSystemType>(t); |
| 447 if (backend->CanHandleType(type)) { | 480 if (backend->CanHandleType(type)) { |
| 448 const bool inserted = backend_map_.insert( | 481 const bool inserted = backend_map_.insert( |
| 449 std::make_pair(type, backend)).second; | 482 std::make_pair(type, backend)).second; |
| 450 DCHECK(inserted); | 483 DCHECK(inserted); |
| 451 } | 484 } |
| 452 } | 485 } |
| 453 } | 486 } |
| 454 | 487 |
| 488 void FileSystemContext::DidOpenFileSystemForResolveURL( |
| 489 const FileSystemURL& url, |
| 490 const FileSystemContext::ResolveURLCallback& callback, |
| 491 const GURL& filesystem_root, |
| 492 const std::string& filesystem_name, |
| 493 base::PlatformFileError error) { |
| 494 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 495 |
| 496 if (error != base::PLATFORM_FILE_OK) { |
| 497 callback.Run(error, FileSystemInfo(), base::FilePath(), false); |
| 498 return; |
| 499 } |
| 500 |
| 501 fileapi::FileSystemInfo info( |
| 502 filesystem_name, filesystem_root, url.mount_type()); |
| 503 |
| 504 // Extract the virtual path not containing a filesystem type part from |url|. |
| 505 base::FilePath parent = |
| 506 base::FilePath::FromUTF8Unsafe(filesystem_root.path()); |
| 507 base::FilePath child = base::FilePath::FromUTF8Unsafe(url.ToGURL().path()); |
| 508 base::FilePath path; |
| 509 |
| 510 if (parent != child) { |
| 511 bool result = parent.AppendRelativePath(child, &path); |
| 512 DCHECK(result); |
| 513 } |
| 514 |
| 515 operation_runner()->GetMetadata( |
| 516 url, base::Bind(&DidGetMetadataForResolveURL, path, callback, info)); |
| 517 } |
| 518 |
| 455 } // namespace fileapi | 519 } // namespace fileapi |
| OLD | NEW |