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 "chrome/browser/chromeos/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 // Remove all files which have no corresponding cache entries. | 224 // Remove all files which have no corresponding cache entries. |
225 base::FileEnumerator enumerator(cache_file_directory_, | 225 base::FileEnumerator enumerator(cache_file_directory_, |
226 false, // not recursive | 226 false, // not recursive |
227 base::FileEnumerator::FILES); | 227 base::FileEnumerator::FILES); |
228 FileCacheEntry entry; | 228 FileCacheEntry entry; |
229 for (base::FilePath current = enumerator.Next(); !current.empty(); | 229 for (base::FilePath current = enumerator.Next(); !current.empty(); |
230 current = enumerator.Next()) { | 230 current = enumerator.Next()) { |
231 std::string resource_id = GetResourceIdFromPath(current); | 231 std::string resource_id = GetResourceIdFromPath(current); |
232 if (!storage_->GetCacheEntry(resource_id, &entry)) | 232 if (!storage_->GetCacheEntry(resource_id, &entry)) |
233 base::Delete(current, false /* recursive */); | 233 base::DeleteFile(current, false /* recursive */); |
234 } | 234 } |
235 | 235 |
236 // Check the disk space again. | 236 // Check the disk space again. |
237 return HasEnoughSpaceFor(num_bytes, cache_file_directory_); | 237 return HasEnoughSpaceFor(num_bytes, cache_file_directory_); |
238 } | 238 } |
239 | 239 |
240 void FileCache::GetFileOnUIThread(const std::string& resource_id, | 240 void FileCache::GetFileOnUIThread(const std::string& resource_id, |
241 const std::string& md5, | 241 const std::string& md5, |
242 const GetFileFromCacheCallback& callback) { | 242 const GetFileFromCacheCallback& callback) { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // If entry doesn't exist, nothing to do. | 486 // If entry doesn't exist, nothing to do. |
487 if (!storage_->GetCacheEntry(resource_id, &cache_entry)) | 487 if (!storage_->GetCacheEntry(resource_id, &cache_entry)) |
488 return FILE_ERROR_OK; | 488 return FILE_ERROR_OK; |
489 | 489 |
490 // Cannot delete a mounted file. | 490 // Cannot delete a mounted file. |
491 if (mounted_files_.count(resource_id)) | 491 if (mounted_files_.count(resource_id)) |
492 return FILE_ERROR_IN_USE; | 492 return FILE_ERROR_IN_USE; |
493 | 493 |
494 // Delete the file. | 494 // Delete the file. |
495 base::FilePath path = GetCacheFilePath(resource_id); | 495 base::FilePath path = GetCacheFilePath(resource_id); |
496 if (!base::Delete(path, false /* recursive */)) | 496 if (!base::DeleteFile(path, false /* recursive */)) |
497 return FILE_ERROR_FAILED; | 497 return FILE_ERROR_FAILED; |
498 | 498 |
499 // Now that all file operations have completed, remove from metadata. | 499 // Now that all file operations have completed, remove from metadata. |
500 return storage_->RemoveCacheEntry(resource_id) ? | 500 return storage_->RemoveCacheEntry(resource_id) ? |
501 FILE_ERROR_OK : FILE_ERROR_FAILED; | 501 FILE_ERROR_OK : FILE_ERROR_FAILED; |
502 } | 502 } |
503 | 503 |
504 void FileCache::ClearAllOnUIThread(const ClearAllCallback& callback) { | 504 void FileCache::ClearAllOnUIThread(const ClearAllCallback& callback) { |
505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
506 DCHECK(!callback.is_null()); | 506 DCHECK(!callback.is_null()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 662 |
663 if (it->HasError()) | 663 if (it->HasError()) |
664 return false; | 664 return false; |
665 | 665 |
666 // Remove files. | 666 // Remove files. |
667 base::FileEnumerator enumerator(cache_file_directory_, | 667 base::FileEnumerator enumerator(cache_file_directory_, |
668 false, // not recursive | 668 false, // not recursive |
669 base::FileEnumerator::FILES); | 669 base::FileEnumerator::FILES); |
670 for (base::FilePath file = enumerator.Next(); !file.empty(); | 670 for (base::FilePath file = enumerator.Next(); !file.empty(); |
671 file = enumerator.Next()) | 671 file = enumerator.Next()) |
672 base::Delete(file, false /* recursive */); | 672 base::DeleteFile(file, false /* recursive */); |
673 | 673 |
674 return true; | 674 return true; |
675 } | 675 } |
676 | 676 |
677 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, | 677 bool FileCache::HasEnoughSpaceFor(int64 num_bytes, |
678 const base::FilePath& path) { | 678 const base::FilePath& path) { |
679 int64 free_space = 0; | 679 int64 free_space = 0; |
680 if (free_disk_space_getter_) | 680 if (free_disk_space_getter_) |
681 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); | 681 free_space = free_disk_space_getter_->AmountOfFreeDiskSpace(); |
682 else | 682 else |
(...skipping 20 matching lines...) Expand all Loading... |
703 if (storage_->GetCacheEntry(it->GetKey(), &entry)) | 703 if (storage_->GetCacheEntry(it->GetKey(), &entry)) |
704 continue; // Do not overwrite. | 704 continue; // Do not overwrite. |
705 | 705 |
706 storage_->PutCacheEntry(it->GetKey(), it->GetValue()); | 706 storage_->PutCacheEntry(it->GetKey(), it->GetValue()); |
707 } | 707 } |
708 imported = true; | 708 imported = true; |
709 } | 709 } |
710 } | 710 } |
711 | 711 |
712 // Delete old DB. | 712 // Delete old DB. |
713 base::Delete(old_db_path, true /* recursive */ ); | 713 base::DeleteFile(old_db_path, true /* recursive */ ); |
714 return imported; | 714 return imported; |
715 } | 715 } |
716 | 716 |
717 void FileCache::RenameCacheFilesToNewFormat() { | 717 void FileCache::RenameCacheFilesToNewFormat() { |
718 // First, remove all files with multiple extensions just in case. | 718 // First, remove all files with multiple extensions just in case. |
719 { | 719 { |
720 base::FileEnumerator enumerator(cache_file_directory_, | 720 base::FileEnumerator enumerator(cache_file_directory_, |
721 false, // not recursive | 721 false, // not recursive |
722 base::FileEnumerator::FILES, | 722 base::FileEnumerator::FILES, |
723 "*.*.*"); | 723 "*.*.*"); |
724 for (base::FilePath current = enumerator.Next(); !current.empty(); | 724 for (base::FilePath current = enumerator.Next(); !current.empty(); |
725 current = enumerator.Next()) | 725 current = enumerator.Next()) |
726 base::Delete(current, false /* recursive */); | 726 base::DeleteFile(current, false /* recursive */); |
727 } | 727 } |
728 | 728 |
729 // Rename files. | 729 // Rename files. |
730 { | 730 { |
731 base::FileEnumerator enumerator(cache_file_directory_, | 731 base::FileEnumerator enumerator(cache_file_directory_, |
732 false, // not recursive | 732 false, // not recursive |
733 base::FileEnumerator::FILES); | 733 base::FileEnumerator::FILES); |
734 for (base::FilePath current = enumerator.Next(); !current.empty(); | 734 for (base::FilePath current = enumerator.Next(); !current.empty(); |
735 current = enumerator.Next()) | 735 current = enumerator.Next()) |
736 base::Move(current, current.RemoveExtension()); | 736 base::Move(current, current.RemoveExtension()); |
737 } | 737 } |
738 } | 738 } |
739 | 739 |
740 } // namespace internal | 740 } // namespace internal |
741 } // namespace drive | 741 } // namespace drive |
OLD | NEW |