| 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/fileapi/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/task_runner_util.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 18 #include "webkit/fileapi/file_system_file_stream_reader.h" | 19 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_options.h" | 21 #include "webkit/fileapi/file_system_options.h" |
| 21 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
| 22 #include "webkit/fileapi/file_system_usage_cache.h" | 23 #include "webkit/fileapi/file_system_usage_cache.h" |
| 23 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
| 24 #include "webkit/fileapi/local_file_system_operation.h" | 25 #include "webkit/fileapi/local_file_system_operation.h" |
| 25 #include "webkit/fileapi/native_file_util.h" | 26 #include "webkit/fileapi/native_file_util.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // done before anyone looks up a filesystem. Most entry points start by trying | 262 // done before anyone looks up a filesystem. Most entry points start by trying |
| 262 // to look up the filesystem's root, so we can take care of most of them by | 263 // to look up the filesystem's root, so we can take care of most of them by |
| 263 // putting a check there. | 264 // putting a check there. |
| 264 void MigrateIfNeeded( | 265 void MigrateIfNeeded( |
| 265 ObfuscatedFileUtil* file_util, | 266 ObfuscatedFileUtil* file_util, |
| 266 const FilePath& old_base_path) { | 267 const FilePath& old_base_path) { |
| 267 if (file_util::DirectoryExists(old_base_path)) | 268 if (file_util::DirectoryExists(old_base_path)) |
| 268 MigrateAllOldFileSystems(file_util, old_base_path); | 269 MigrateAllOldFileSystems(file_util, old_base_path); |
| 269 } | 270 } |
| 270 | 271 |
| 271 void PassPointerErrorByValue( | |
| 272 const base::Callback<void(PlatformFileError)>& callback, | |
| 273 PlatformFileError* error_ptr) { | |
| 274 DCHECK(error_ptr); | |
| 275 callback.Run(*error_ptr); | |
| 276 } | |
| 277 | |
| 278 void DidValidateFileSystemRoot( | 272 void DidValidateFileSystemRoot( |
| 279 base::WeakPtr<SandboxMountPointProvider> mount_point_provider, | 273 base::WeakPtr<SandboxMountPointProvider> mount_point_provider, |
| 280 const base::Callback<void(PlatformFileError)>& callback, | 274 const FileSystemMountPointProvider::ValidateFileSystemCallback& callback, |
| 281 base::PlatformFileError* error) { | 275 base::PlatformFileError* error) { |
| 282 if (mount_point_provider.get()) | 276 if (mount_point_provider.get()) |
| 283 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); | 277 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); |
| 284 callback.Run(*error); | 278 callback.Run(*error); |
| 285 } | 279 } |
| 286 | 280 |
| 287 void ValidateRootOnFileThread( | 281 void ValidateRootOnFileThread( |
| 288 ObfuscatedFileUtil* file_util, | 282 ObfuscatedFileUtil* file_util, |
| 289 const GURL& origin_url, | 283 const GURL& origin_url, |
| 290 FileSystemType type, | 284 FileSystemType type, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 const FileSystemURL& url, | 446 const FileSystemURL& url, |
| 453 int64 offset, | 447 int64 offset, |
| 454 FileSystemContext* context) const { | 448 FileSystemContext* context) const { |
| 455 return new SandboxFileStreamWriter(context, url, offset); | 449 return new SandboxFileStreamWriter(context, url, offset); |
| 456 } | 450 } |
| 457 | 451 |
| 458 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { | 452 FileSystemQuotaUtil* SandboxMountPointProvider::GetQuotaUtil() { |
| 459 return this; | 453 return this; |
| 460 } | 454 } |
| 461 | 455 |
| 456 void SandboxMountPointProvider::DeleteFileSystem( |
| 457 const GURL& origin_url, |
| 458 FileSystemType type, |
| 459 FileSystemContext* context, |
| 460 const DeleteFileSystemCallback& callback) { |
| 461 base::PostTaskAndReplyWithResult( |
| 462 context->file_task_runner(), |
| 463 FROM_HERE, |
| 464 // It is safe to pass Unretained(this) since context owns it. |
| 465 base::Bind(&SandboxMountPointProvider::DeleteOriginDataOnFileThread, |
| 466 base::Unretained(this), |
| 467 make_scoped_refptr(context), |
| 468 base::Unretained(context->quota_manager_proxy()), |
| 469 origin_url, |
| 470 type), |
| 471 callback); |
| 472 } |
| 473 |
| 462 FilePath SandboxMountPointProvider::old_base_path() const { | 474 FilePath SandboxMountPointProvider::old_base_path() const { |
| 463 return profile_path_.Append(kOldFileSystemDirectory); | 475 return profile_path_.Append(kOldFileSystemDirectory); |
| 464 } | 476 } |
| 465 | 477 |
| 466 FilePath SandboxMountPointProvider::new_base_path() const { | 478 FilePath SandboxMountPointProvider::new_base_path() const { |
| 467 return profile_path_.Append(kNewFileSystemDirectory); | 479 return profile_path_.Append(kNewFileSystemDirectory); |
| 468 } | 480 } |
| 469 | 481 |
| 470 FilePath SandboxMountPointProvider::renamed_old_base_path() const { | 482 FilePath SandboxMountPointProvider::renamed_old_base_path() const { |
| 471 return profile_path_.Append(kRenamedOldFileSystemDirectory); | 483 return profile_path_.Append(kRenamedOldFileSystemDirectory); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 483 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); | 495 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); |
| 484 | 496 |
| 485 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 497 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 486 FilePath path = sandbox_file_util_->GetDirectoryForOriginAndType( | 498 FilePath path = sandbox_file_util_->GetDirectoryForOriginAndType( |
| 487 origin_url, type, create, &error); | 499 origin_url, type, create, &error); |
| 488 if (error != base::PLATFORM_FILE_OK) | 500 if (error != base::PLATFORM_FILE_OK) |
| 489 return FilePath(); | 501 return FilePath(); |
| 490 return path; | 502 return path; |
| 491 } | 503 } |
| 492 | 504 |
| 493 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( | 505 base::PlatformFileError |
| 506 SandboxMountPointProvider::DeleteOriginDataOnFileThread( |
| 494 FileSystemContext* file_system_context, | 507 FileSystemContext* file_system_context, |
| 495 QuotaManagerProxy* proxy, | 508 QuotaManagerProxy* proxy, |
| 496 const GURL& origin_url, | 509 const GURL& origin_url, |
| 497 fileapi::FileSystemType type) { | 510 fileapi::FileSystemType type) { |
| 498 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); | 511 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); |
| 499 | 512 |
| 500 int64 usage = GetOriginUsageOnFileThread(file_system_context, | 513 int64 usage = GetOriginUsageOnFileThread(file_system_context, |
| 501 origin_url, type); | 514 origin_url, type); |
| 502 | 515 |
| 503 bool result = | 516 bool result = |
| 504 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type); | 517 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type); |
| 505 if (result && proxy) { | 518 if (result && proxy) { |
| 506 proxy->NotifyStorageModified( | 519 proxy->NotifyStorageModified( |
| 507 quota::QuotaClient::kFileSystem, | 520 quota::QuotaClient::kFileSystem, |
| 508 origin_url, | 521 origin_url, |
| 509 FileSystemTypeToQuotaStorageType(type), | 522 FileSystemTypeToQuotaStorageType(type), |
| 510 -usage); | 523 -usage); |
| 511 } | 524 } |
| 512 return result; | 525 |
| 526 if (result) |
| 527 return base::PLATFORM_FILE_OK; |
| 528 return base::PLATFORM_FILE_ERROR_FAILED; |
| 513 } | 529 } |
| 514 | 530 |
| 515 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread( | 531 void SandboxMountPointProvider::GetOriginsForTypeOnFileThread( |
| 516 fileapi::FileSystemType type, std::set<GURL>* origins) { | 532 fileapi::FileSystemType type, std::set<GURL>* origins) { |
| 517 DCHECK(type == kFileSystemTypeTemporary || | 533 DCHECK(type == kFileSystemTypeTemporary || |
| 518 type == kFileSystemTypePersistent); | 534 type == kFileSystemTypePersistent); |
| 519 DCHECK(origins); | 535 DCHECK(origins); |
| 520 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); | 536 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); |
| 521 GURL origin; | 537 GURL origin; |
| 522 while (!(origin = enumerator->Next()).is_empty()) { | 538 while (!(origin = enumerator->Next()).is_empty()) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 break; | 749 break; |
| 734 case base::PLATFORM_FILE_ERROR_FAILED: | 750 case base::PLATFORM_FILE_ERROR_FAILED: |
| 735 default: | 751 default: |
| 736 REPORT(kUnknownError); | 752 REPORT(kUnknownError); |
| 737 break; | 753 break; |
| 738 } | 754 } |
| 739 #undef REPORT | 755 #undef REPORT |
| 740 } | 756 } |
| 741 | 757 |
| 742 } // namespace fileapi | 758 } // namespace fileapi |
| OLD | NEW |