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" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( | 491 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( |
492 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { | 492 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { |
493 | 493 |
494 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); | 494 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); |
495 | 495 |
496 return sandbox_file_util_->GetDirectoryForOriginAndType( | 496 return sandbox_file_util_->GetDirectoryForOriginAndType( |
497 origin_url, type, create); | 497 origin_url, type, create); |
498 } | 498 } |
499 | 499 |
500 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( | 500 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( |
501 FileSystemContext* file_system_context, | 501 QuotaManagerProxy* proxy, const GURL& origin_url, |
502 QuotaManagerProxy* proxy, | |
503 const GURL& origin_url, | |
504 fileapi::FileSystemType type) { | 502 fileapi::FileSystemType type) { |
505 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); | 503 MigrateIfNeeded(sandbox_file_util_.get(), old_base_path()); |
506 | 504 |
507 int64 usage = GetOriginUsageOnFileThread(file_system_context, | 505 int64 usage = GetOriginUsageOnFileThread(origin_url, type); |
508 origin_url, type); | |
509 | 506 |
510 bool result = | 507 bool result = |
511 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type); | 508 sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type); |
512 if (result && proxy) { | 509 if (result && proxy) { |
513 proxy->NotifyStorageModified( | 510 proxy->NotifyStorageModified( |
514 quota::QuotaClient::kFileSystem, | 511 quota::QuotaClient::kFileSystem, |
515 origin_url, | 512 origin_url, |
516 FileSystemTypeToQuotaStorageType(type), | 513 FileSystemTypeToQuotaStorageType(type), |
517 -usage); | 514 -usage); |
518 } | 515 } |
(...skipping 29 matching lines...) Expand all Loading... |
548 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); | 545 scoped_ptr<OriginEnumerator> enumerator(CreateOriginEnumerator()); |
549 GURL origin; | 546 GURL origin; |
550 while (!(origin = enumerator->Next()).is_empty()) { | 547 while (!(origin = enumerator->Next()).is_empty()) { |
551 if (host == net::GetHostOrSpecFromURL(origin) && | 548 if (host == net::GetHostOrSpecFromURL(origin) && |
552 enumerator->HasFileSystemType(type)) | 549 enumerator->HasFileSystemType(type)) |
553 origins->insert(origin); | 550 origins->insert(origin); |
554 } | 551 } |
555 } | 552 } |
556 | 553 |
557 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( | 554 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( |
558 FileSystemContext* file_system_context, | 555 const GURL& origin_url, fileapi::FileSystemType type) { |
559 const GURL& origin_url, | |
560 fileapi::FileSystemType type) { | |
561 DCHECK(type == kFileSystemTypeTemporary || | 556 DCHECK(type == kFileSystemTypeTemporary || |
562 type == kFileSystemTypePersistent); | 557 type == kFileSystemTypePersistent); |
563 FilePath base_path = | 558 FilePath base_path = |
564 GetBaseDirectoryForOriginAndType(origin_url, type, false); | 559 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
565 if (base_path.empty() || !file_util::DirectoryExists(base_path)) return 0; | 560 if (base_path.empty() || !file_util::DirectoryExists(base_path)) return 0; |
566 FilePath usage_file_path = | 561 FilePath usage_file_path = |
567 base_path.Append(FileSystemUsageCache::kUsageFileName); | 562 base_path.Append(FileSystemUsageCache::kUsageFileName); |
568 | 563 |
569 bool is_valid = FileSystemUsageCache::IsValid(usage_file_path); | 564 bool is_valid = FileSystemUsageCache::IsValid(usage_file_path); |
570 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); | 565 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); |
571 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); | 566 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); |
572 visited_origins_.insert(origin_url); | 567 visited_origins_.insert(origin_url); |
573 if (is_valid && (dirty_status == 0 || (dirty_status > 0 && visited))) { | 568 if (is_valid && (dirty_status == 0 || (dirty_status > 0 && visited))) { |
574 // The usage cache is clean (dirty == 0) or the origin is already | 569 // The usage cache is clean (dirty == 0) or the origin is already |
575 // initialized and running. Read the cache file to get the usage. | 570 // initialized and running. Read the cache file to get the usage. |
576 return FileSystemUsageCache::GetUsage(usage_file_path); | 571 return FileSystemUsageCache::GetUsage(usage_file_path); |
577 } | 572 } |
578 // The usage cache has not been initialized or the cache is dirty. | 573 // The usage cache has not been initialized or the cache is dirty. |
579 // Get the directory size now and update the cache. | 574 // Get the directory size now and update the cache. |
580 FileSystemUsageCache::Delete(usage_file_path); | 575 FileSystemUsageCache::Delete(usage_file_path); |
581 | 576 |
582 FileSystemOperationContext context(file_system_context); | 577 FileSystemOperationContext context(NULL); |
583 FileSystemPath path(origin_url, type, FilePath()); | 578 FileSystemPath path(origin_url, type, FilePath()); |
584 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( | 579 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( |
585 sandbox_file_util_->CreateFileEnumerator(&context, path, true)); | 580 sandbox_file_util_->CreateFileEnumerator(&context, path, true)); |
586 | 581 |
587 FilePath file_path_each; | 582 FilePath file_path_each; |
588 int64 usage = 0; | 583 int64 usage = 0; |
589 | 584 |
590 while (!(file_path_each = enumerator->Next()).empty()) { | 585 while (!(file_path_each = enumerator->Next()).empty()) { |
591 base::PlatformFileInfo file_info; | 586 base::PlatformFileInfo file_info; |
592 FilePath platform_file_path; | 587 FilePath platform_file_path; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 break; | 735 break; |
741 case base::PLATFORM_FILE_ERROR_FAILED: | 736 case base::PLATFORM_FILE_ERROR_FAILED: |
742 default: | 737 default: |
743 REPORT(kUnknownError); | 738 REPORT(kUnknownError); |
744 break; | 739 break; |
745 } | 740 } |
746 #undef REPORT | 741 #undef REPORT |
747 } | 742 } |
748 | 743 |
749 } // namespace fileapi | 744 } // namespace fileapi |
OLD | NEW |