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/drive_cache.h" | 5 #include "chrome/browser/chromeos/drive/drive_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/logging.h" | 10 #include "base/logging.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 FileEnumerator enumerator(directory, false /* recursive */, | 98 FileEnumerator enumerator(directory, false /* recursive */, |
99 FileEnumerator::FILES); | 99 FileEnumerator::FILES); |
100 for (FilePath file_path = enumerator.Next(); !file_path.empty(); | 100 for (FilePath file_path = enumerator.Next(); !file_path.empty(); |
101 file_path = enumerator.Next()) { | 101 file_path = enumerator.Next()) { |
102 DVLOG(1) << "Removing " << file_path.value(); | 102 DVLOG(1) << "Removing " << file_path.value(); |
103 if (!file_util::Delete(file_path, false /* recursive */)) | 103 if (!file_util::Delete(file_path, false /* recursive */)) |
104 LOG(WARNING) << "Failed to delete " << file_path.value(); | 104 LOG(WARNING) << "Failed to delete " << file_path.value(); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 // Modifies cache state of file on blocking pool, which involves: | 108 // Deletes the symlink. |
109 // - moving or copying file (per |file_operation_type|) from |source_path| to | 109 void DeleteSymlink(const FilePath& symlink_path) { |
110 // |dest_path| if they're different | |
111 // - deleting symlink if |symlink_path| is not empty | |
112 // - creating symlink if |symlink_path| is not empty and |create_symlink| is | |
113 // true. | |
114 DriveFileError ModifyCacheState( | |
115 const FilePath& source_path, | |
116 const FilePath& dest_path, | |
117 DriveCache::FileOperationType file_operation_type, | |
118 const FilePath& symlink_path, | |
119 bool create_symlink) { | |
120 // Move or copy |source_path| to |dest_path| if they are different. | |
121 if (source_path != dest_path) { | |
122 bool success = false; | |
123 if (file_operation_type == DriveCache::FILE_OPERATION_MOVE) | |
124 success = file_util::Move(source_path, dest_path); | |
125 else if (file_operation_type == DriveCache::FILE_OPERATION_COPY) | |
126 success = file_util::CopyFile(source_path, dest_path); | |
127 if (!success) { | |
128 LOG(ERROR) << "Failed to " | |
129 << (file_operation_type == DriveCache::FILE_OPERATION_MOVE ? | |
130 "move " : "copy ") | |
131 << source_path.value() | |
132 << " to " << dest_path.value(); | |
133 return DRIVE_FILE_ERROR_FAILED; | |
134 } else { | |
135 DVLOG(1) << (file_operation_type == DriveCache::FILE_OPERATION_MOVE ? | |
136 "Moved " : "Copied ") | |
137 << source_path.value() | |
138 << " to " << dest_path.value(); | |
139 } | |
140 } else { | |
141 DVLOG(1) << "No need to move file: source = destination"; | |
142 } | |
143 | |
144 if (symlink_path.empty()) | |
145 return DRIVE_FILE_OK; | |
146 | |
147 // Remove symlink regardless of |create_symlink| because creating a link will | |
148 // not overwrite an existing one. | |
149 // We try to save one file operation by not checking if link exists before | 110 // We try to save one file operation by not checking if link exists before |
150 // deleting it, so unlink may return error if link doesn't exist, but it | 111 // deleting it, so unlink may return error if link doesn't exist, but it |
151 // doesn't really matter to us. | 112 // doesn't really matter to us. |
152 file_util::Delete(symlink_path, false); | 113 file_util::Delete(symlink_path, false); |
114 } | |
153 | 115 |
154 if (!create_symlink) | 116 // Creates a symlink. |
155 return DRIVE_FILE_OK; | 117 bool CreateSymlink(const FilePath& cache_file_path, |
118 const FilePath& symlink_path) { | |
119 // Remove symlink because creating a link will not overwrite an existing one. | |
120 DeleteSymlink(symlink_path); | |
156 | 121 |
157 // Create new symlink to |dest_path|. | 122 // Create new symlink to |cache_file_path|. |
158 if (!file_util::CreateSymbolicLink(dest_path, symlink_path)) { | 123 if (!file_util::CreateSymbolicLink(cache_file_path, symlink_path)) { |
159 LOG(ERROR) << "Failed to create a symlink from " << symlink_path.value() | 124 LOG(ERROR) << "Failed to create a symlink from " << symlink_path.value() |
125 << " to " << cache_file_path.value(); | |
126 return false; | |
127 } | |
128 return true; | |
129 } | |
130 | |
131 // Moves the file. | |
132 bool MoveFile(const FilePath& source_path, const FilePath& dest_path) { | |
133 if (!file_util::Move(source_path, dest_path)) { | |
134 LOG(ERROR) << "Failed to move " << source_path.value() | |
160 << " to " << dest_path.value(); | 135 << " to " << dest_path.value(); |
161 return DRIVE_FILE_ERROR_FAILED; | 136 return false; |
162 } | 137 } |
138 DVLOG(1) << "Moved " << source_path.value() << " to " << dest_path.value(); | |
139 return true; | |
140 } | |
163 | 141 |
164 return DRIVE_FILE_OK; | 142 // Copies the file. |
143 bool CopyFile(const FilePath& source_path, const FilePath& dest_path) { | |
144 if (!file_util::CopyFile(source_path, dest_path)) { | |
145 LOG(ERROR) << "Failed to copy " << source_path.value() | |
146 << " to " << dest_path.value(); | |
147 return false; | |
148 } | |
149 DVLOG(1) << "Copied " << source_path.value() << " to " << dest_path.value(); | |
150 return true; | |
165 } | 151 } |
166 | 152 |
167 // Deletes all files that match |path_to_delete_pattern| except for | 153 // Deletes all files that match |path_to_delete_pattern| except for |
168 // |path_to_keep| on blocking pool. | 154 // |path_to_keep| on blocking pool. |
169 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are | 155 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are |
170 // deleted. | 156 // deleted. |
171 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, | 157 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, |
172 const FilePath& path_to_keep) { | 158 const FilePath& path_to_keep) { |
173 // Enumerate all files in directory of |path_to_delete_pattern| that match | 159 // Enumerate all files in directory of |path_to_delete_pattern| that match |
174 // base name of |path_to_delete_pattern|. | 160 // base name of |path_to_delete_pattern|. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 314 |
329 bool DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes) { | 315 bool DriveCache::FreeDiskSpaceOnBlockingPoolIfNeededFor(int64 num_bytes) { |
330 AssertOnSequencedWorkerPool(); | 316 AssertOnSequencedWorkerPool(); |
331 | 317 |
332 // Do nothing and return if we have enough space. | 318 // Do nothing and return if we have enough space. |
333 if (HasEnoughSpaceFor(num_bytes)) | 319 if (HasEnoughSpaceFor(num_bytes)) |
334 return true; | 320 return true; |
335 | 321 |
336 // Otherwise, try to free up the disk space. | 322 // Otherwise, try to free up the disk space. |
337 DVLOG(1) << "Freeing up disk space for " << num_bytes; | 323 DVLOG(1) << "Freeing up disk space for " << num_bytes; |
338 // First remove temporary files from the cache map. | 324 // First remove temporary files from the metadata. |
339 metadata_->RemoveTemporaryFiles(); | 325 metadata_->RemoveTemporaryFiles(); |
340 // Then remove all files under "tmp" directory. | 326 // Then remove all files under "tmp" directory. |
341 RemoveAllFiles(GetCacheDirectoryPath(CACHE_TYPE_TMP)); | 327 RemoveAllFiles(GetCacheDirectoryPath(CACHE_TYPE_TMP)); |
342 | 328 |
343 // Check the disk space again. | 329 // Check the disk space again. |
344 return HasEnoughSpaceFor(num_bytes); | 330 return HasEnoughSpaceFor(num_bytes); |
345 } | 331 } |
346 | 332 |
347 void DriveCache::GetFile(const std::string& resource_id, | 333 void DriveCache::GetFile(const std::string& resource_id, |
348 const std::string& md5, | 334 const std::string& md5, |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 if (!file_util::GetFileSize(source_path, &file_size)) { | 602 if (!file_util::GetFileSize(source_path, &file_size)) { |
617 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); | 603 LOG(WARNING) << "Couldn't get file size for: " << source_path.value(); |
618 return DRIVE_FILE_ERROR_FAILED; | 604 return DRIVE_FILE_ERROR_FAILED; |
619 } | 605 } |
620 | 606 |
621 const bool enough_space = FreeDiskSpaceOnBlockingPoolIfNeededFor(file_size); | 607 const bool enough_space = FreeDiskSpaceOnBlockingPoolIfNeededFor(file_size); |
622 if (!enough_space) | 608 if (!enough_space) |
623 return DRIVE_FILE_ERROR_NO_SPACE; | 609 return DRIVE_FILE_ERROR_NO_SPACE; |
624 } | 610 } |
625 | 611 |
626 FilePath dest_path; | |
627 FilePath symlink_path; | 612 FilePath symlink_path; |
628 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 613 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
629 | 614 |
630 // If file was previously pinned, store it in persistent dir and create | 615 // If file was previously pinned, store it in persistent dir and create |
631 // symlink in pinned dir. | 616 // symlink in pinned dir. |
632 DriveCacheEntry cache_entry; | 617 DriveCacheEntry cache_entry; |
633 if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { | 618 if (GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { |
634 // File exists in cache. | 619 // File exists in cache. |
635 // If file is dirty or mounted, return error. | 620 // If file is dirty or mounted, return error. |
636 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 621 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
637 LOG(WARNING) << "Can't store a file to replace a " | 622 LOG(WARNING) << "Can't store a file to replace a " |
638 << (cache_entry.is_dirty() ? "dirty" : "mounted") | 623 << (cache_entry.is_dirty() ? "dirty" : "mounted") |
639 << " file: res_id=" << resource_id | 624 << " file: res_id=" << resource_id |
640 << ", md5=" << md5; | 625 << ", md5=" << md5; |
641 return DRIVE_FILE_ERROR_IN_USE; | 626 return DRIVE_FILE_ERROR_IN_USE; |
642 } | 627 } |
643 | 628 |
644 // If file is pinned, determines destination path. | 629 // If file is pinned, determines destination path. |
645 if (cache_entry.is_pinned()) { | 630 if (cache_entry.is_pinned()) { |
646 sub_dir_type = CACHE_TYPE_PERSISTENT; | 631 sub_dir_type = CACHE_TYPE_PERSISTENT; |
647 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | |
648 CACHED_FILE_FROM_SERVER); | |
649 symlink_path = GetCacheFilePath( | 632 symlink_path = GetCacheFilePath( |
650 resource_id, std::string(), CACHE_TYPE_PINNED, | 633 resource_id, std::string(), CACHE_TYPE_PINNED, |
651 CACHED_FILE_FROM_SERVER); | 634 CACHED_FILE_FROM_SERVER); |
652 } | 635 } |
653 } | 636 } |
654 | 637 |
655 // File wasn't pinned or doesn't exist in cache, store in tmp dir. | 638 FilePath dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, |
656 if (dest_path.empty()) { | 639 CACHED_FILE_FROM_SERVER); |
657 DCHECK_EQ(CACHE_TYPE_TMP, sub_dir_type); | 640 bool success = false; |
658 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | 641 switch (file_operation_type) { |
659 CACHED_FILE_FROM_SERVER); | 642 case FILE_OPERATION_MOVE: |
643 success = MoveFile(source_path, dest_path); | |
644 break; | |
645 case FILE_OPERATION_COPY: | |
646 success = CopyFile(source_path, dest_path); | |
647 break; | |
648 default: | |
649 NOTREACHED(); | |
660 } | 650 } |
661 | 651 |
662 DriveFileError error = ModifyCacheState( | 652 if (success && !symlink_path.empty()) |
kinaba
2012/11/09 08:10:22
If I understand correctly, cache_entry.is_pinned()
hashimoto
2012/11/09 08:39:34
Sounds great.
Done.
| |
663 source_path, | 653 success = CreateSymlink(dest_path, symlink_path); |
664 dest_path, | |
665 file_operation_type, | |
666 symlink_path, | |
667 !symlink_path.empty()); // create symlink | |
668 | 654 |
669 // Determine search pattern for stale filenames corresponding to resource_id, | 655 // Determine search pattern for stale filenames corresponding to resource_id, |
670 // either "<resource_id>*" or "<resource_id>.*". | 656 // either "<resource_id>*" or "<resource_id>.*". |
671 FilePath stale_filenames_pattern; | 657 FilePath stale_filenames_pattern; |
672 if (md5.empty()) { | 658 if (md5.empty()) { |
673 // No md5 means no extension, append '*' after base name, i.e. | 659 // No md5 means no extension, append '*' after base name, i.e. |
674 // "<resource_id>*". | 660 // "<resource_id>*". |
675 // Cannot call |dest_path|.ReplaceExtension when there's no md5 extension: | 661 // Cannot call |dest_path|.ReplaceExtension when there's no md5 extension: |
676 // if base name of |dest_path| (i.e. escaped resource_id) contains the | 662 // if base name of |dest_path| (i.e. escaped resource_id) contains the |
677 // extension separator '.', ReplaceExtension will remove it and everything | 663 // extension separator '.', ReplaceExtension will remove it and everything |
678 // after it. The result will be nothing like the escaped resource_id. | 664 // after it. The result will be nothing like the escaped resource_id. |
679 stale_filenames_pattern = FilePath(dest_path.value() + util::kWildCard); | 665 stale_filenames_pattern = FilePath(dest_path.value() + util::kWildCard); |
680 } else { | 666 } else { |
681 // Replace md5 extension with '*' i.e. "<resource_id>.*". | 667 // Replace md5 extension with '*' i.e. "<resource_id>.*". |
682 // Note that ReplaceExtension automatically prefixes the extension with the | 668 // Note that ReplaceExtension automatically prefixes the extension with the |
683 // extension separator '.'. | 669 // extension separator '.'. |
684 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); | 670 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); |
685 } | 671 } |
686 | 672 |
687 // Delete files that match |stale_filenames_pattern| except for |dest_path|. | 673 // Delete files that match |stale_filenames_pattern| except for |dest_path|. |
688 DeleteFilesSelectively(stale_filenames_pattern, dest_path); | 674 DeleteFilesSelectively(stale_filenames_pattern, dest_path); |
689 | 675 |
690 if (error == DRIVE_FILE_OK) { | 676 if (success) { |
691 // Now that file operations have completed, update cache map. | 677 // Now that file operations have completed, update metadata. |
692 cache_entry.set_md5(md5); | 678 cache_entry.set_md5(md5); |
693 cache_entry.set_is_present(true); | 679 cache_entry.set_is_present(true); |
694 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 680 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
695 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 681 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
696 } | 682 } |
697 | 683 |
698 return error; | 684 return success ? DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
699 } | 685 } |
700 | 686 |
701 DriveFileError DriveCache::PinOnBlockingPool(const std::string& resource_id, | 687 DriveFileError DriveCache::PinOnBlockingPool(const std::string& resource_id, |
702 const std::string& md5) { | 688 const std::string& md5) { |
703 AssertOnSequencedWorkerPool(); | 689 AssertOnSequencedWorkerPool(); |
704 | 690 |
705 FilePath source_path; | |
706 FilePath dest_path; | 691 FilePath dest_path; |
707 FilePath symlink_path; | |
708 bool create_symlink = true; | 692 bool create_symlink = true; |
709 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 693 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
710 | 694 |
711 DriveCacheEntry cache_entry; | 695 DriveCacheEntry cache_entry; |
712 if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { | 696 if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { |
713 // Entry does not exist in cache. | 697 // Entry does not exist in cache. Set |dest_path| to /dev/null, so that |
714 // Set both |dest_path| and |source_path| to /dev/null, so that: | 698 // symlinks to /dev/null will be picked up by DriveSyncClient to download |
715 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| | 699 // pinned files that don't exist in cache. |
716 // are the same. | |
717 // 2) symlinks to /dev/null will be picked up by DriveSyncClient to download | |
718 // pinned files that don't exist in cache. | |
719 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); | 700 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); |
720 source_path = dest_path; | |
721 | 701 |
722 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', | 702 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', |
723 // then moved to 'persistent'. | 703 // then moved to 'persistent'. |
724 sub_dir_type = CACHE_TYPE_TMP; | 704 sub_dir_type = CACHE_TYPE_TMP; |
725 } else { // File exists in cache, determines destination path. | 705 } else { // File exists in cache, determines destination path. |
726 // Determine source and destination paths. | 706 // Determine source and destination paths. |
727 | 707 |
728 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 708 // If file is dirty or mounted, don't move it. |
729 // set |source_path| the same, because ModifyCacheState only moves files if | |
730 // source and destination are different. | |
731 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 709 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
732 DCHECK(cache_entry.is_persistent()); | 710 DCHECK(cache_entry.is_persistent()); |
733 dest_path = GetCacheFilePath(resource_id, | 711 dest_path = GetCacheFilePath(resource_id, |
734 md5, | 712 md5, |
735 GetSubDirectoryType(cache_entry), | 713 GetSubDirectoryType(cache_entry), |
736 CACHED_FILE_LOCALLY_MODIFIED); | 714 CACHED_FILE_LOCALLY_MODIFIED); |
737 source_path = dest_path; | |
738 } else { | 715 } else { |
739 // Gets the current path of the file in cache. | 716 // Gets the current path of the file in cache. |
740 source_path = GetCacheFilePath(resource_id, | 717 FilePath source_path = GetCacheFilePath(resource_id, |
741 md5, | 718 md5, |
742 GetSubDirectoryType(cache_entry), | 719 GetSubDirectoryType(cache_entry), |
743 CACHED_FILE_FROM_SERVER); | 720 CACHED_FILE_FROM_SERVER); |
744 | 721 |
745 // If file was pinned before but actual file blob doesn't exist in cache: | 722 // If file was pinned before but actual file blob doesn't exist in cache: |
746 // - don't need to move the file, so set |dest_path| to |source_path|, | 723 // - don't need to move the file. |
747 // because ModifyCacheState only moves files if source and destination | |
748 // are different | |
749 // - don't create symlink since it already exists. | 724 // - don't create symlink since it already exists. |
750 if (!cache_entry.is_present()) { | 725 if (!cache_entry.is_present()) { |
751 dest_path = source_path; | 726 dest_path = source_path; |
kinaba
2012/11/09 08:10:22
In this case, we don't create symlink, so there's
hashimoto
2012/11/09 08:39:34
Sounds sweat.
Done.
| |
752 create_symlink = false; | 727 create_symlink = false; |
kinaba
2012/11/09 08:10:22
Well, besides, I have some doubt in the logic here
hashimoto
2012/11/09 08:39:34
Good catch.
Done.
| |
753 } else { // File exists, move it to persistent dir. | 728 } else { // File exists, move it to persistent dir. |
754 dest_path = GetCacheFilePath(resource_id, | 729 dest_path = GetCacheFilePath(resource_id, |
755 md5, | 730 md5, |
756 CACHE_TYPE_PERSISTENT, | 731 CACHE_TYPE_PERSISTENT, |
757 CACHED_FILE_FROM_SERVER); | 732 CACHED_FILE_FROM_SERVER); |
733 if (!MoveFile(source_path, dest_path)) | |
734 return DRIVE_FILE_ERROR_FAILED; | |
758 } | 735 } |
759 } | 736 } |
760 } | 737 } |
761 | 738 |
762 // Create symlink in pinned dir. | 739 // Create symlink in pinned dir. |
763 if (create_symlink) { | 740 if (create_symlink) { |
764 symlink_path = GetCacheFilePath(resource_id, | 741 FilePath symlink_path = GetCacheFilePath(resource_id, |
765 std::string(), | 742 std::string(), |
766 CACHE_TYPE_PINNED, | 743 CACHE_TYPE_PINNED, |
767 CACHED_FILE_FROM_SERVER); | 744 CACHED_FILE_FROM_SERVER); |
745 if (!CreateSymlink(dest_path, symlink_path)) | |
746 return DRIVE_FILE_ERROR_FAILED; | |
768 } | 747 } |
769 | 748 |
770 DriveFileError error = ModifyCacheState(source_path, | 749 // Now that file operations have completed, update metadata. |
771 dest_path, | 750 cache_entry.set_md5(md5); |
772 FILE_OPERATION_MOVE, | 751 cache_entry.set_is_pinned(true); |
773 symlink_path, | 752 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
774 create_symlink); | 753 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
775 if (error == DRIVE_FILE_OK) { | 754 return DRIVE_FILE_OK; |
776 // Now that file operations have completed, update cache map. | |
777 cache_entry.set_md5(md5); | |
778 cache_entry.set_is_pinned(true); | |
779 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | |
780 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | |
781 } | |
782 | |
783 return error; | |
784 } | 755 } |
785 | 756 |
786 DriveFileError DriveCache::UnpinOnBlockingPool(const std::string& resource_id, | 757 DriveFileError DriveCache::UnpinOnBlockingPool(const std::string& resource_id, |
787 const std::string& md5) { | 758 const std::string& md5) { |
788 AssertOnSequencedWorkerPool(); | 759 AssertOnSequencedWorkerPool(); |
789 | 760 |
790 // Unpinning a file means its entry must exist in cache. | 761 // Unpinning a file means its entry must exist in cache. |
791 DriveCacheEntry cache_entry; | 762 DriveCacheEntry cache_entry; |
792 if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { | 763 if (!GetCacheEntryOnBlockingPool(resource_id, md5, &cache_entry)) { |
793 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" | 764 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" |
794 << resource_id | 765 << resource_id |
795 << ", md5=" << md5; | 766 << ", md5=" << md5; |
796 return DRIVE_FILE_ERROR_NOT_FOUND; | 767 return DRIVE_FILE_ERROR_NOT_FOUND; |
797 } | 768 } |
798 | 769 |
799 // Entry exists in cache, determines source and destination paths. | |
800 | |
801 FilePath source_path; | |
802 FilePath dest_path; | |
803 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 770 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
804 | 771 |
805 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 772 // If file is dirty or mounted, don't move it. |
806 // set |source_path| the same, because ModifyCacheState moves files if source | |
807 // and destination are different. | |
808 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { | 773 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { |
809 sub_dir_type = CACHE_TYPE_PERSISTENT; | 774 sub_dir_type = CACHE_TYPE_PERSISTENT; |
810 DCHECK(cache_entry.is_persistent()); | 775 DCHECK(cache_entry.is_persistent()); |
811 dest_path = GetCacheFilePath(resource_id, | |
812 md5, | |
813 GetSubDirectoryType(cache_entry), | |
814 CACHED_FILE_LOCALLY_MODIFIED); | |
815 source_path = dest_path; | |
816 } else { | 776 } else { |
817 // Gets the current path of the file in cache. | |
818 source_path = GetCacheFilePath(resource_id, | |
819 md5, | |
820 GetSubDirectoryType(cache_entry), | |
821 CACHED_FILE_FROM_SERVER); | |
822 | |
823 // If file was pinned but actual file blob still doesn't exist in cache, | 777 // If file was pinned but actual file blob still doesn't exist in cache, |
824 // don't need to move the file, so set |dest_path| to |source_path|, because | 778 // don't need to move the file. |
825 // ModifyCacheState only moves files if source and destination are | 779 if (cache_entry.is_present()) { |
826 // different. | 780 // Gets the current path of the file in cache. |
827 if (!cache_entry.is_present()) { | 781 FilePath source_path = GetCacheFilePath(resource_id, |
828 dest_path = source_path; | 782 md5, |
829 } else { // File exists, move it to tmp dir. | 783 GetSubDirectoryType(cache_entry), |
830 dest_path = GetCacheFilePath(resource_id, md5, | 784 CACHED_FILE_FROM_SERVER); |
831 CACHE_TYPE_TMP, | 785 // File exists, move it to tmp dir. |
832 CACHED_FILE_FROM_SERVER); | 786 FilePath dest_path = GetCacheFilePath(resource_id, |
787 md5, | |
788 CACHE_TYPE_TMP, | |
789 CACHED_FILE_FROM_SERVER); | |
790 if (!MoveFile(source_path, dest_path)) | |
791 return DRIVE_FILE_ERROR_FAILED; | |
833 } | 792 } |
834 } | 793 } |
835 | 794 |
836 // If file was pinned, get absolute path of symlink in pinned dir so as to | 795 // If file was pinned, remove the symlink in pinned dir. |
837 // remove it. | |
838 FilePath symlink_path; | |
839 if (cache_entry.is_pinned()) { | 796 if (cache_entry.is_pinned()) { |
840 symlink_path = GetCacheFilePath(resource_id, | 797 FilePath symlink_path = GetCacheFilePath(resource_id, |
841 std::string(), | 798 std::string(), |
842 CACHE_TYPE_PINNED, | 799 CACHE_TYPE_PINNED, |
843 CACHED_FILE_FROM_SERVER); | 800 CACHED_FILE_FROM_SERVER); |
801 DeleteSymlink(symlink_path); | |
844 } | 802 } |
845 | 803 |
846 DriveFileError error = ModifyCacheState( | 804 // Now that file operations have completed, update metadata. |
847 source_path, | 805 if (cache_entry.is_present()) { |
848 dest_path, | 806 cache_entry.set_md5(md5); |
849 FILE_OPERATION_MOVE, | 807 cache_entry.set_is_pinned(false); |
850 symlink_path, // This will be deleted if it exists. | 808 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
851 false /* don't create symlink*/); | 809 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
852 | 810 } else { |
853 if (error == DRIVE_FILE_OK) { | 811 // Remove the existing entry if we are unpinning a non-present file. |
854 // Now that file operations have completed, update cache map. | 812 metadata_->RemoveCacheEntry(resource_id); |
855 if (cache_entry.is_present()) { | |
856 cache_entry.set_md5(md5); | |
857 cache_entry.set_is_pinned(false); | |
858 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | |
859 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | |
860 } else { | |
861 // Remove the existing entry if we are unpinning a non-present file. | |
862 metadata_->RemoveCacheEntry(resource_id); | |
863 } | |
864 } | 813 } |
865 | 814 return DRIVE_FILE_OK; |
866 return error; | |
867 } | 815 } |
868 | 816 |
869 scoped_ptr<DriveCache::GetFileResult> DriveCache::SetMountedStateOnBlockingPool( | 817 scoped_ptr<DriveCache::GetFileResult> DriveCache::SetMountedStateOnBlockingPool( |
870 const FilePath& file_path, | 818 const FilePath& file_path, |
871 bool to_mount) { | 819 bool to_mount) { |
872 AssertOnSequencedWorkerPool(); | 820 AssertOnSequencedWorkerPool(); |
873 | 821 |
874 scoped_ptr<GetFileResult> result(new GetFileResult); | 822 scoped_ptr<GetFileResult> result(new GetFileResult); |
875 | 823 |
876 // Parse file path to obtain resource_id, md5 and extra_extension. | 824 // Parse file path to obtain resource_id, md5 and extra_extension. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 dest_subdir = mounted_subdir; | 862 dest_subdir = mounted_subdir; |
915 cache_entry.set_is_mounted(true); | 863 cache_entry.set_is_mounted(true); |
916 } else { | 864 } else { |
917 source_path = mounted_path; | 865 source_path = mounted_path; |
918 cache_file_path = unmounted_path; | 866 cache_file_path = unmounted_path; |
919 dest_subdir = unmounted_subdir; | 867 dest_subdir = unmounted_subdir; |
920 cache_entry.set_is_mounted(false); | 868 cache_entry.set_is_mounted(false); |
921 } | 869 } |
922 | 870 |
923 // Move cache blob from source path to destination path. | 871 // Move cache blob from source path to destination path. |
924 DriveFileError error = ModifyCacheState( | 872 bool success = MoveFile(source_path, cache_file_path); |
925 source_path, cache_file_path, FILE_OPERATION_MOVE, FilePath(), false); | 873 |
926 if (error == DRIVE_FILE_OK) { | 874 if (success) { |
927 // Now that cache operation is complete, update cache map | 875 // Now that cache operation is complete, update metadata |
928 cache_entry.set_md5(md5); | 876 cache_entry.set_md5(md5); |
929 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT); | 877 cache_entry.set_is_persistent(dest_subdir == CACHE_TYPE_PERSISTENT); |
930 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 878 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
931 } | 879 } |
932 | 880 result->first = success ? DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
933 result->first = error; | |
934 result->second = cache_file_path; | 881 result->second = cache_file_path; |
935 return result.Pass(); | 882 return result.Pass(); |
936 } | 883 } |
937 | 884 |
938 scoped_ptr<DriveCache::GetFileResult> DriveCache::MarkDirtyOnBlockingPool( | 885 scoped_ptr<DriveCache::GetFileResult> DriveCache::MarkDirtyOnBlockingPool( |
939 const std::string& resource_id, | 886 const std::string& resource_id, |
940 const std::string& md5) { | 887 const std::string& md5) { |
941 AssertOnSequencedWorkerPool(); | 888 AssertOnSequencedWorkerPool(); |
942 | 889 |
943 scoped_ptr<GetFileResult> result(new GetFileResult); | 890 scoped_ptr<GetFileResult> result(new GetFileResult); |
(...skipping 19 matching lines...) Expand all Loading... | |
963 // delete outgoing symlink if it exists. | 910 // delete outgoing symlink if it exists. |
964 // TODO(benchan): We should only delete outgoing symlink if file is currently | 911 // TODO(benchan): We should only delete outgoing symlink if file is currently |
965 // not being uploaded. However, for now, cache doesn't know if uploading of a | 912 // not being uploaded. However, for now, cache doesn't know if uploading of a |
966 // file is in progress. Per zel, the upload process should be canceled before | 913 // file is in progress. Per zel, the upload process should be canceled before |
967 // MarkDirtyInCache is called again. | 914 // MarkDirtyInCache is called again. |
968 if (cache_entry.is_dirty()) { | 915 if (cache_entry.is_dirty()) { |
969 // The file must be in persistent dir. | 916 // The file must be in persistent dir. |
970 DCHECK(cache_entry.is_persistent()); | 917 DCHECK(cache_entry.is_persistent()); |
971 | 918 |
972 // Determine symlink path in outgoing dir, so as to remove it. | 919 // Determine symlink path in outgoing dir, so as to remove it. |
973 FilePath symlink_path = GetCacheFilePath( | 920 FilePath symlink_path = GetCacheFilePath(resource_id, |
974 resource_id, | 921 std::string(), |
975 std::string(), | 922 CACHE_TYPE_OUTGOING, |
976 CACHE_TYPE_OUTGOING, | 923 CACHED_FILE_FROM_SERVER); |
977 CACHED_FILE_FROM_SERVER); | 924 DeleteSymlink(symlink_path); |
978 | |
979 // We're not moving files here, so simply use empty FilePath for both | |
980 // |source_path| and |dest_path| because ModifyCacheState only move files | |
981 // if source and destination are different. | |
982 DriveFileError error = ModifyCacheState( | |
983 FilePath(), // non-applicable source path | |
984 FilePath(), // non-applicable dest path | |
985 FILE_OPERATION_MOVE, | |
986 symlink_path, | |
987 false /* don't create symlink */); | |
988 | 925 |
989 // Determine current path of dirty file. | 926 // Determine current path of dirty file. |
990 result->first = error; | 927 result->first = DRIVE_FILE_OK; |
991 if (error == DRIVE_FILE_OK) { | 928 result->second = GetCacheFilePath(resource_id, |
992 result->second = GetCacheFilePath(resource_id, | 929 md5, |
993 md5, | 930 CACHE_TYPE_PERSISTENT, |
994 CACHE_TYPE_PERSISTENT, | 931 CACHED_FILE_LOCALLY_MODIFIED); |
995 CACHED_FILE_LOCALLY_MODIFIED); | |
996 } | |
997 return result.Pass(); | 932 return result.Pass(); |
998 } | 933 } |
999 | 934 |
1000 // Move file to persistent dir with new .local extension. | 935 // Move file to persistent dir with new .local extension. |
1001 | 936 |
1002 // Get the current path of the file in cache. | 937 // Get the current path of the file in cache. |
1003 FilePath source_path = GetCacheFilePath( | 938 FilePath source_path = GetCacheFilePath(resource_id, |
1004 resource_id, | 939 md5, |
1005 md5, | 940 GetSubDirectoryType(cache_entry), |
1006 GetSubDirectoryType(cache_entry), | 941 CACHED_FILE_FROM_SERVER); |
1007 CACHED_FILE_FROM_SERVER); | |
1008 | |
1009 // Determine destination path. | 942 // Determine destination path. |
1010 const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 943 const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
1011 FilePath cache_file_path = GetCacheFilePath(resource_id, | 944 FilePath cache_file_path = GetCacheFilePath(resource_id, |
1012 md5, | 945 md5, |
1013 sub_dir_type, | 946 sub_dir_type, |
1014 CACHED_FILE_LOCALLY_MODIFIED); | 947 CACHED_FILE_LOCALLY_MODIFIED); |
1015 | 948 |
949 bool success = MoveFile(source_path, cache_file_path); | |
950 | |
1016 // If file is pinned, update symlink in pinned dir. | 951 // If file is pinned, update symlink in pinned dir. |
1017 FilePath symlink_path; | 952 if (success && cache_entry.is_pinned()) { |
1018 if (cache_entry.is_pinned()) { | 953 FilePath symlink_path = GetCacheFilePath(resource_id, |
1019 symlink_path = GetCacheFilePath(resource_id, | 954 std::string(), |
1020 std::string(), | 955 CACHE_TYPE_PINNED, |
1021 CACHE_TYPE_PINNED, | 956 CACHED_FILE_FROM_SERVER); |
1022 CACHED_FILE_FROM_SERVER); | 957 success = CreateSymlink(cache_file_path, symlink_path); |
1023 } | 958 } |
1024 | 959 |
1025 DriveFileError error = ModifyCacheState( | 960 if (success) { |
1026 source_path, | 961 // Now that file operations have completed, update metadata. |
1027 cache_file_path, | |
1028 FILE_OPERATION_MOVE, | |
1029 symlink_path, | |
1030 !symlink_path.empty() /* create symlink */); | |
1031 | |
1032 if (error == DRIVE_FILE_OK) { | |
1033 // Now that file operations have completed, update cache map. | |
1034 cache_entry.set_md5(md5); | 962 cache_entry.set_md5(md5); |
1035 cache_entry.set_is_dirty(true); | 963 cache_entry.set_is_dirty(true); |
1036 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 964 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
1037 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 965 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
1038 } | 966 } |
1039 result->first = error; | 967 result->first = success ? DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
1040 result->second = cache_file_path; | 968 result->second = cache_file_path; |
1041 return result.Pass(); | 969 return result.Pass(); |
1042 } | 970 } |
1043 | 971 |
1044 DriveFileError DriveCache::CommitDirtyOnBlockingPool( | 972 DriveFileError DriveCache::CommitDirtyOnBlockingPool( |
1045 const std::string& resource_id, | 973 const std::string& resource_id, |
1046 const std::string& md5) { | 974 const std::string& md5) { |
1047 AssertOnSequencedWorkerPool(); | 975 AssertOnSequencedWorkerPool(); |
1048 | 976 |
1049 // If file has already been marked dirty in previous instance of chrome, we | 977 // If file has already been marked dirty in previous instance of chrome, we |
(...skipping 29 matching lines...) Expand all Loading... | |
1079 std::string(), | 1007 std::string(), |
1080 CACHE_TYPE_OUTGOING, | 1008 CACHE_TYPE_OUTGOING, |
1081 CACHED_FILE_FROM_SERVER); | 1009 CACHED_FILE_FROM_SERVER); |
1082 | 1010 |
1083 // Get target path of symlink i.e. current path of the file in cache. | 1011 // Get target path of symlink i.e. current path of the file in cache. |
1084 FilePath target_path = GetCacheFilePath(resource_id, | 1012 FilePath target_path = GetCacheFilePath(resource_id, |
1085 md5, | 1013 md5, |
1086 GetSubDirectoryType(cache_entry), | 1014 GetSubDirectoryType(cache_entry), |
1087 CACHED_FILE_LOCALLY_MODIFIED); | 1015 CACHED_FILE_LOCALLY_MODIFIED); |
1088 | 1016 |
1089 // Since there's no need to move files, use |target_path| for both | 1017 return CreateSymlink(target_path, symlink_path) ? |
1090 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1018 DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
1091 // if source and destination are different. | |
1092 return ModifyCacheState(target_path, // source | |
1093 target_path, // destination | |
1094 FILE_OPERATION_MOVE, | |
1095 symlink_path, | |
1096 true /* create symlink */); | |
1097 } | 1019 } |
1098 | 1020 |
1099 DriveFileError DriveCache::ClearDirtyOnBlockingPool( | 1021 DriveFileError DriveCache::ClearDirtyOnBlockingPool( |
1100 const std::string& resource_id, | 1022 const std::string& resource_id, |
1101 const std::string& md5) { | 1023 const std::string& md5) { |
1102 AssertOnSequencedWorkerPool(); | 1024 AssertOnSequencedWorkerPool(); |
1103 | 1025 |
1104 // |md5| is the new .<md5> extension to rename the file to. | 1026 // |md5| is the new .<md5> extension to rename the file to. |
1105 // So, search for entry in cache without comparing md5. | 1027 // So, search for entry in cache without comparing md5. |
1106 DriveCacheEntry cache_entry; | 1028 DriveCacheEntry cache_entry; |
(...skipping 29 matching lines...) Expand all Loading... | |
1136 // Determine destination path. | 1058 // Determine destination path. |
1137 // If file is pinned, move it to persistent dir with .md5 extension; | 1059 // If file is pinned, move it to persistent dir with .md5 extension; |
1138 // otherwise, move it to tmp dir with .md5 extension. | 1060 // otherwise, move it to tmp dir with .md5 extension. |
1139 const CacheSubDirectoryType sub_dir_type = | 1061 const CacheSubDirectoryType sub_dir_type = |
1140 cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1062 cache_entry.is_pinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1141 FilePath dest_path = GetCacheFilePath(resource_id, | 1063 FilePath dest_path = GetCacheFilePath(resource_id, |
1142 md5, | 1064 md5, |
1143 sub_dir_type, | 1065 sub_dir_type, |
1144 CACHED_FILE_FROM_SERVER); | 1066 CACHED_FILE_FROM_SERVER); |
1145 | 1067 |
1146 // Delete symlink in outgoing dir. | 1068 bool success = MoveFile(source_path, dest_path); |
1147 FilePath symlink_path = GetCacheFilePath(resource_id, | |
1148 std::string(), | |
1149 CACHE_TYPE_OUTGOING, | |
1150 CACHED_FILE_FROM_SERVER); | |
1151 | 1069 |
1152 DriveFileError error = ModifyCacheState(source_path, | 1070 if (success) { |
1153 dest_path, | 1071 // Delete symlink in outgoing dir. |
1154 FILE_OPERATION_MOVE, | 1072 FilePath symlink_path = GetCacheFilePath(resource_id, |
1155 symlink_path, | 1073 std::string(), |
1156 false /* don't create symlink */); | 1074 CACHE_TYPE_OUTGOING, |
1075 CACHED_FILE_FROM_SERVER); | |
1076 DeleteSymlink(symlink_path); | |
1077 } | |
1157 | 1078 |
1158 // If file is pinned, update symlink in pinned dir. | 1079 // If file is pinned, update symlink in pinned dir. |
1159 if (error == DRIVE_FILE_OK && cache_entry.is_pinned()) { | 1080 if (success && cache_entry.is_pinned()) { |
1160 symlink_path = GetCacheFilePath(resource_id, | 1081 FilePath symlink_path = GetCacheFilePath(resource_id, |
1161 std::string(), | 1082 std::string(), |
1162 CACHE_TYPE_PINNED, | 1083 CACHE_TYPE_PINNED, |
1163 CACHED_FILE_FROM_SERVER); | 1084 CACHED_FILE_FROM_SERVER); |
1164 | 1085 |
1165 // Since there's no moving of files here, use |dest_path| for both | 1086 success = CreateSymlink(dest_path, symlink_path); |
1166 // |source_path| and |dest_path|, because ModifyCacheState only moves files | |
1167 // if source and destination are different. | |
1168 error = ModifyCacheState(dest_path, // source path | |
1169 dest_path, // destination path | |
1170 FILE_OPERATION_MOVE, | |
1171 symlink_path, | |
1172 true /* create symlink */); | |
1173 } | 1087 } |
1174 | 1088 |
1175 if (error == DRIVE_FILE_OK) { | 1089 if (success) { |
1176 // Now that file operations have completed, update cache map. | 1090 // Now that file operations have completed, update metadata. |
1177 cache_entry.set_md5(md5); | 1091 cache_entry.set_md5(md5); |
1178 cache_entry.set_is_dirty(false); | 1092 cache_entry.set_is_dirty(false); |
1179 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1093 cache_entry.set_is_persistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
1180 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); | 1094 metadata_->AddOrUpdateCacheEntry(resource_id, cache_entry); |
1181 } | 1095 } |
1182 | 1096 |
1183 return error; | 1097 return success ? DRIVE_FILE_OK : DRIVE_FILE_ERROR_FAILED; |
1184 } | 1098 } |
1185 | 1099 |
1186 DriveFileError DriveCache::RemoveOnBlockingPool( | 1100 DriveFileError DriveCache::RemoveOnBlockingPool( |
1187 const std::string& resource_id) { | 1101 const std::string& resource_id) { |
1188 AssertOnSequencedWorkerPool(); | 1102 AssertOnSequencedWorkerPool(); |
1189 | 1103 |
1190 // MD5 is not passed into RemoveCacheEntry because we would delete all | 1104 // MD5 is not passed into RemoveCacheEntry because we would delete all |
1191 // cache files corresponding to <resource_id> regardless of the md5. | 1105 // cache files corresponding to <resource_id> regardless of the md5. |
1192 // So, search for entry in cache without taking md5 into account. | 1106 // So, search for entry in cache without taking md5 into account. |
1193 DriveCacheEntry cache_entry; | 1107 DriveCacheEntry cache_entry; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1231 // outgoing path to |paths_to_delete|. | 1145 // outgoing path to |paths_to_delete|. |
1232 FilePath path_to_keep = GetCacheFilePath(resource_id, | 1146 FilePath path_to_keep = GetCacheFilePath(resource_id, |
1233 std::string(), | 1147 std::string(), |
1234 CACHE_TYPE_PERSISTENT, | 1148 CACHE_TYPE_PERSISTENT, |
1235 CACHED_FILE_LOCALLY_MODIFIED); | 1149 CACHED_FILE_LOCALLY_MODIFIED); |
1236 | 1150 |
1237 for (size_t i = 0; i < paths_to_delete.size(); ++i) { | 1151 for (size_t i = 0; i < paths_to_delete.size(); ++i) { |
1238 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); | 1152 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); |
1239 } | 1153 } |
1240 | 1154 |
1241 // Now that all file operations have completed, remove from cache map. | 1155 // Now that all file operations have completed, remove from metadata. |
1242 metadata_->RemoveCacheEntry(resource_id); | 1156 metadata_->RemoveCacheEntry(resource_id); |
1243 | 1157 |
1244 return DRIVE_FILE_OK; | 1158 return DRIVE_FILE_OK; |
1245 } | 1159 } |
1246 | 1160 |
1247 bool DriveCache::ClearAllOnBlockingPool() { | 1161 bool DriveCache::ClearAllOnBlockingPool() { |
1248 AssertOnSequencedWorkerPool(); | 1162 AssertOnSequencedWorkerPool(); |
1249 | 1163 |
1250 if (!file_util::Delete(cache_root_path_, true)) { | 1164 if (!file_util::Delete(cache_root_path_, true)) { |
1251 LOG(WARNING) << "Failed to delete the cache directory"; | 1165 LOG(WARNING) << "Failed to delete the cache directory"; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 const DriveCacheEntry& cache_entry) { | 1276 const DriveCacheEntry& cache_entry) { |
1363 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1277 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1364 } | 1278 } |
1365 | 1279 |
1366 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1280 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1367 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1281 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1368 global_free_disk_getter_for_testing = getter; | 1282 global_free_disk_getter_for_testing = getter; |
1369 } | 1283 } |
1370 | 1284 |
1371 } // namespace drive | 1285 } // namespace drive |
OLD | NEW |