OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_callback_factory.h" | 9 #include "base/memory/scoped_callback_factory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( | 518 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( |
519 const GURL& origin_url, fileapi::FileSystemType type) { | 519 const GURL& origin_url, fileapi::FileSystemType type) { |
520 DCHECK(type == fileapi::kFileSystemTypeTemporary || | 520 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
521 type == fileapi::kFileSystemTypePersistent); | 521 type == fileapi::kFileSystemTypePersistent); |
522 FilePath base_path = | 522 FilePath base_path = |
523 GetBaseDirectoryForOriginAndType(origin_url, type, false); | 523 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
524 if (base_path.empty() || !file_util::DirectoryExists(base_path)) return 0; | 524 if (base_path.empty() || !file_util::DirectoryExists(base_path)) return 0; |
525 FilePath usage_file_path = | 525 FilePath usage_file_path = |
526 base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); | 526 base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); |
527 | 527 |
| 528 bool is_valid = FileSystemUsageCache::IsValid(usage_file_path); |
528 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); | 529 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); |
529 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); | 530 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); |
530 visited_origins_.insert(origin_url); | 531 visited_origins_.insert(origin_url); |
531 if (dirty_status == 0 || (dirty_status > 0 && visited)) { | 532 if (is_valid && (dirty_status == 0 || (dirty_status > 0 && visited))) { |
532 // The usage cache is clean (dirty == 0) or the origin is already | 533 // The usage cache is clean (dirty == 0) or the origin is already |
533 // initialized and running. Read the cache file to get the usage. | 534 // initialized and running. Read the cache file to get the usage. |
534 return FileSystemUsageCache::GetUsage(usage_file_path); | 535 return FileSystemUsageCache::GetUsage(usage_file_path); |
535 } | 536 } |
536 // The usage cache has not been initialized or the cache is dirty. | 537 // The usage cache has not been initialized or the cache is dirty. |
537 // Get the directory size now and update the cache. | 538 // Get the directory size now and update the cache. |
538 FileSystemUsageCache::Delete(usage_file_path); | 539 FileSystemUsageCache::Delete(usage_file_path); |
539 | 540 |
540 FileSystemOperationContext context(NULL, sandbox_file_util_); | 541 FileSystemOperationContext context(NULL, sandbox_file_util_); |
541 context.set_src_origin_url(origin_url); | 542 context.set_src_origin_url(origin_url); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 613 |
613 void SandboxMountPointProvider::EndUpdateOriginOnFileThread( | 614 void SandboxMountPointProvider::EndUpdateOriginOnFileThread( |
614 const GURL& origin_url, fileapi::FileSystemType type) { | 615 const GURL& origin_url, fileapi::FileSystemType type) { |
615 DCHECK(type == fileapi::kFileSystemTypeTemporary || | 616 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
616 type == fileapi::kFileSystemTypePersistent); | 617 type == fileapi::kFileSystemTypePersistent); |
617 FilePath usage_file_path = GetUsageCachePathForOriginAndType( | 618 FilePath usage_file_path = GetUsageCachePathForOriginAndType( |
618 origin_url, type); | 619 origin_url, type); |
619 FileSystemUsageCache::DecrementDirty(usage_file_path); | 620 FileSystemUsageCache::DecrementDirty(usage_file_path); |
620 } | 621 } |
621 | 622 |
| 623 void SandboxMountPointProvider::InvalidateUsageCache( |
| 624 const GURL& origin_url, fileapi::FileSystemType type) { |
| 625 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
| 626 type == fileapi::kFileSystemTypePersistent); |
| 627 FilePath usage_file_path = GetUsageCachePathForOriginAndType( |
| 628 origin_url, type); |
| 629 FileSystemUsageCache::IncrementDirty(usage_file_path); |
| 630 } |
| 631 |
622 FileSystemFileUtil* SandboxMountPointProvider::GetFileSystemFileUtil() { | 632 FileSystemFileUtil* SandboxMountPointProvider::GetFileSystemFileUtil() { |
623 return sandbox_file_util_.get(); | 633 return sandbox_file_util_.get(); |
624 } | 634 } |
625 | 635 |
626 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( | 636 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( |
627 const GURL& origin_url, fileapi::FileSystemType type) const { | 637 const GURL& origin_url, fileapi::FileSystemType type) const { |
628 FilePath base_path = | 638 FilePath base_path = |
629 GetBaseDirectoryForOriginAndType(origin_url, type, false); | 639 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
630 if (base_path.empty()) | 640 if (base_path.empty()) |
631 return FilePath(); | 641 return FilePath(); |
(...skipping 19 matching lines...) Expand all Loading... |
651 | 661 |
652 // Creates the root directory. | 662 // Creates the root directory. |
653 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); | 663 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); |
654 if (!file_util::CreateDirectory(root)) | 664 if (!file_util::CreateDirectory(root)) |
655 return FilePath(); | 665 return FilePath(); |
656 | 666 |
657 return root; | 667 return root; |
658 } | 668 } |
659 | 669 |
660 } // namespace fileapi | 670 } // namespace fileapi |
OLD | NEW |