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/gdata/gdata_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 } | 682 } |
683 | 683 |
684 void GDataCache::RequestInitializeOnUIThread() { | 684 void GDataCache::RequestInitializeOnUIThread() { |
685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
686 | 686 |
687 pool_->GetSequencedTaskRunner(sequence_token_)->PostTask( | 687 pool_->GetSequencedTaskRunner(sequence_token_)->PostTask( |
688 FROM_HERE, | 688 FROM_HERE, |
689 base::Bind(&GDataCache::Initialize, base::Unretained(this))); | 689 base::Bind(&GDataCache::Initialize, base::Unretained(this))); |
690 } | 690 } |
691 | 691 |
692 scoped_ptr<GDataCache::CacheEntry> GDataCache::GetCacheEntry( | 692 bool GDataCache::GetCacheEntry(const std::string& resource_id, |
693 const std::string& resource_id, | 693 const std::string& md5, |
694 const std::string& md5) { | 694 CacheEntry* entry) { |
satorux1
2012/06/20 15:29:23
add DCHECK(entry); ?
hashimoto
2012/07/11 12:01:56
Done.
| |
695 AssertOnSequencedWorkerPool(); | 695 AssertOnSequencedWorkerPool(); |
696 return metadata_->GetCacheEntry(resource_id, md5); | 696 return metadata_->GetCacheEntry(resource_id, md5, entry); |
697 } | 697 } |
698 | 698 |
699 // static | 699 // static |
700 GDataCache* GDataCache::CreateGDataCacheOnUIThread( | 700 GDataCache* GDataCache::CreateGDataCacheOnUIThread( |
701 const FilePath& cache_root_path, | 701 const FilePath& cache_root_path, |
702 base::SequencedWorkerPool* pool, | 702 base::SequencedWorkerPool* pool, |
703 const base::SequencedWorkerPool::SequenceToken& sequence_token) { | 703 const base::SequencedWorkerPool::SequenceToken& sequence_token) { |
704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
705 return new GDataCache(cache_root_path, pool, sequence_token); | 705 return new GDataCache(cache_root_path, pool, sequence_token); |
706 } | 706 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 } | 741 } |
742 | 742 |
743 void GDataCache::GetFile(const std::string& resource_id, | 743 void GDataCache::GetFile(const std::string& resource_id, |
744 const std::string& md5, | 744 const std::string& md5, |
745 base::PlatformFileError* error, | 745 base::PlatformFileError* error, |
746 FilePath* cache_file_path) { | 746 FilePath* cache_file_path) { |
747 AssertOnSequencedWorkerPool(); | 747 AssertOnSequencedWorkerPool(); |
748 DCHECK(error); | 748 DCHECK(error); |
749 DCHECK(cache_file_path); | 749 DCHECK(cache_file_path); |
750 | 750 |
751 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 751 CacheEntry cache_entry; |
752 resource_id, md5); | 752 if (GetCacheEntry(resource_id, md5, &cache_entry) && |
753 if (cache_entry.get() && cache_entry->IsPresent()) { | 753 cache_entry.IsPresent()) { |
754 CachedFileOrigin file_origin; | 754 CachedFileOrigin file_origin; |
755 if (cache_entry->IsMounted()) { | 755 if (cache_entry.IsMounted()) { |
756 file_origin = CACHED_FILE_MOUNTED; | 756 file_origin = CACHED_FILE_MOUNTED; |
757 } else if (cache_entry->IsDirty()) { | 757 } else if (cache_entry.IsDirty()) { |
758 file_origin = CACHED_FILE_LOCALLY_MODIFIED; | 758 file_origin = CACHED_FILE_LOCALLY_MODIFIED; |
759 } else { | 759 } else { |
760 file_origin = CACHED_FILE_FROM_SERVER; | 760 file_origin = CACHED_FILE_FROM_SERVER; |
761 } | 761 } |
762 *cache_file_path = GetCacheFilePath( | 762 *cache_file_path = GetCacheFilePath( |
763 resource_id, | 763 resource_id, |
764 md5, | 764 md5, |
765 cache_entry->sub_dir_type, | 765 cache_entry.sub_dir_type, |
766 file_origin); | 766 file_origin); |
767 *error = base::PLATFORM_FILE_OK; | 767 *error = base::PLATFORM_FILE_OK; |
768 } else { | 768 } else { |
769 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 769 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
770 } | 770 } |
771 } | 771 } |
772 | 772 |
773 void GDataCache::Store(const std::string& resource_id, | 773 void GDataCache::Store(const std::string& resource_id, |
774 const std::string& md5, | 774 const std::string& md5, |
775 const FilePath& source_path, | 775 const FilePath& source_path, |
776 FileOperationType file_operation_type, | 776 FileOperationType file_operation_type, |
777 base::PlatformFileError* error) { | 777 base::PlatformFileError* error) { |
778 AssertOnSequencedWorkerPool(); | 778 AssertOnSequencedWorkerPool(); |
779 DCHECK(error); | 779 DCHECK(error); |
780 | 780 |
781 FilePath dest_path; | 781 FilePath dest_path; |
782 FilePath symlink_path; | 782 FilePath symlink_path; |
783 int cache_state = CACHE_STATE_PRESENT; | 783 int cache_state = CACHE_STATE_PRESENT; |
784 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 784 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
785 | 785 |
786 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 786 CacheEntry cache_entry; |
787 | 787 |
788 // If file was previously pinned, store it in persistent dir and create | 788 // If file was previously pinned, store it in persistent dir and create |
789 // symlink in pinned dir. | 789 // symlink in pinned dir. |
790 if (cache_entry.get()) { // File exists in cache. | 790 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
791 // If file is dirty or mounted, return error. | 791 // If file is dirty or mounted, return error. |
792 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 792 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
793 LOG(WARNING) << "Can't store a file to replace a " | 793 LOG(WARNING) << "Can't store a file to replace a " |
794 << (cache_entry->IsDirty() ? "dirty" : "mounted") | 794 << (cache_entry.IsDirty() ? "dirty" : "mounted") |
795 << " file: res_id=" << resource_id | 795 << " file: res_id=" << resource_id |
796 << ", md5=" << md5; | 796 << ", md5=" << md5; |
797 *error = base::PLATFORM_FILE_ERROR_IN_USE; | 797 *error = base::PLATFORM_FILE_ERROR_IN_USE; |
798 return; | 798 return; |
799 } | 799 } |
800 | 800 |
801 cache_state |= cache_entry->cache_state; | 801 cache_state |= cache_entry.cache_state; |
802 | 802 |
803 // If file is pinned, determines destination path. | 803 // If file is pinned, determines destination path. |
804 if (cache_entry->IsPinned()) { | 804 if (cache_entry.IsPinned()) { |
805 sub_dir_type = CACHE_TYPE_PERSISTENT; | 805 sub_dir_type = CACHE_TYPE_PERSISTENT; |
806 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | 806 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, |
807 CACHED_FILE_FROM_SERVER); | 807 CACHED_FILE_FROM_SERVER); |
808 symlink_path = GetCacheFilePath( | 808 symlink_path = GetCacheFilePath( |
809 resource_id, std::string(), CACHE_TYPE_PINNED, | 809 resource_id, std::string(), CACHE_TYPE_PINNED, |
810 CACHED_FILE_FROM_SERVER); | 810 CACHED_FILE_FROM_SERVER); |
811 } | 811 } |
812 } | 812 } |
813 | 813 |
814 // File wasn't pinned or doesn't exist in cache, store in tmp dir. | 814 // File wasn't pinned or doesn't exist in cache, store in tmp dir. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 AssertOnSequencedWorkerPool(); | 859 AssertOnSequencedWorkerPool(); |
860 DCHECK(error); | 860 DCHECK(error); |
861 | 861 |
862 FilePath source_path; | 862 FilePath source_path; |
863 FilePath dest_path; | 863 FilePath dest_path; |
864 FilePath symlink_path; | 864 FilePath symlink_path; |
865 bool create_symlink = true; | 865 bool create_symlink = true; |
866 int cache_state = CACHE_STATE_PINNED; | 866 int cache_state = CACHE_STATE_PINNED; |
867 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 867 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
868 | 868 |
869 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 869 CacheEntry cache_entry; |
870 | 870 |
871 if (!cache_entry.get()) { // Entry does not exist in cache. | 871 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
872 // Entry does not exist in cache. | |
872 // Set both |dest_path| and |source_path| to /dev/null, so that: | 873 // Set both |dest_path| and |source_path| to /dev/null, so that: |
873 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| | 874 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| |
874 // are the same. | 875 // are the same. |
875 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download | 876 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download |
876 // pinned files that don't exist in cache. | 877 // pinned files that don't exist in cache. |
877 dest_path = FilePath(kSymLinkToDevNull); | 878 dest_path = FilePath(kSymLinkToDevNull); |
878 source_path = dest_path; | 879 source_path = dest_path; |
879 | 880 |
880 // Set sub_dir_type to PINNED to indicate that the file doesn't exist. | 881 // Set sub_dir_type to PINNED to indicate that the file doesn't exist. |
881 // When the file is finally downloaded and StoreToCache called, it will be | 882 // When the file is finally downloaded and StoreToCache called, it will be |
882 // moved to persistent directory. | 883 // moved to persistent directory. |
883 sub_dir_type = CACHE_TYPE_PINNED; | 884 sub_dir_type = CACHE_TYPE_PINNED; |
884 } else { // File exists in cache, determines destination path. | 885 } else { // File exists in cache, determines destination path. |
885 cache_state |= cache_entry->cache_state; | 886 cache_state |= cache_entry.cache_state; |
886 | 887 |
887 // Determine source and destination paths. | 888 // Determine source and destination paths. |
888 | 889 |
889 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 890 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
890 // set |source_path| the same, because ModifyCacheState only moves files if | 891 // set |source_path| the same, because ModifyCacheState only moves files if |
891 // source and destination are different. | 892 // source and destination are different. |
892 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 893 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
893 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); | 894 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry.sub_dir_type); |
894 dest_path = GetCacheFilePath(resource_id, | 895 dest_path = GetCacheFilePath(resource_id, |
895 md5, | 896 md5, |
896 cache_entry->sub_dir_type, | 897 cache_entry.sub_dir_type, |
897 CACHED_FILE_LOCALLY_MODIFIED); | 898 CACHED_FILE_LOCALLY_MODIFIED); |
898 source_path = dest_path; | 899 source_path = dest_path; |
899 } else { | 900 } else { |
900 // Gets the current path of the file in cache. | 901 // Gets the current path of the file in cache. |
901 source_path = GetCacheFilePath(resource_id, | 902 source_path = GetCacheFilePath(resource_id, |
902 md5, | 903 md5, |
903 cache_entry->sub_dir_type, | 904 cache_entry.sub_dir_type, |
904 CACHED_FILE_FROM_SERVER); | 905 CACHED_FILE_FROM_SERVER); |
905 | 906 |
906 // If file was pinned before but actual file blob doesn't exist in cache: | 907 // If file was pinned before but actual file blob doesn't exist in cache: |
907 // - don't need to move the file, so set |dest_path| to |source_path|, | 908 // - don't need to move the file, so set |dest_path| to |source_path|, |
908 // because ModifyCacheState only moves files if source and destination | 909 // because ModifyCacheState only moves files if source and destination |
909 // are different | 910 // are different |
910 // - don't create symlink since it already exists. | 911 // - don't create symlink since it already exists. |
911 if (cache_entry->sub_dir_type == CACHE_TYPE_PINNED) { | 912 if (cache_entry.sub_dir_type == CACHE_TYPE_PINNED) { |
912 dest_path = source_path; | 913 dest_path = source_path; |
913 create_symlink = false; | 914 create_symlink = false; |
914 } else { // File exists, move it to persistent dir. | 915 } else { // File exists, move it to persistent dir. |
915 dest_path = GetCacheFilePath(resource_id, | 916 dest_path = GetCacheFilePath(resource_id, |
916 md5, | 917 md5, |
917 CACHE_TYPE_PERSISTENT, | 918 CACHE_TYPE_PERSISTENT, |
918 CACHED_FILE_FROM_SERVER); | 919 CACHED_FILE_FROM_SERVER); |
919 } | 920 } |
920 } | 921 } |
921 } | 922 } |
(...skipping 18 matching lines...) Expand all Loading... | |
940 } | 941 } |
941 } | 942 } |
942 | 943 |
943 void GDataCache::Unpin(const std::string& resource_id, | 944 void GDataCache::Unpin(const std::string& resource_id, |
944 const std::string& md5, | 945 const std::string& md5, |
945 FileOperationType file_operation_type, | 946 FileOperationType file_operation_type, |
946 base::PlatformFileError* error) { | 947 base::PlatformFileError* error) { |
947 AssertOnSequencedWorkerPool(); | 948 AssertOnSequencedWorkerPool(); |
948 DCHECK(error); | 949 DCHECK(error); |
949 | 950 |
950 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 951 CacheEntry cache_entry; |
951 | 952 |
952 // Unpinning a file means its entry must exist in cache. | 953 // Unpinning a file means its entry must exist in cache. |
953 if (!cache_entry.get()) { | 954 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
954 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" | 955 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" |
955 << resource_id | 956 << resource_id |
956 << ", md5=" << md5; | 957 << ", md5=" << md5; |
957 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 958 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
958 return; | 959 return; |
959 } | 960 } |
960 | 961 |
961 // Entry exists in cache, determines source and destination paths. | 962 // Entry exists in cache, determines source and destination paths. |
962 | 963 |
963 FilePath source_path; | 964 FilePath source_path; |
964 FilePath dest_path; | 965 FilePath dest_path; |
965 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 966 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
966 | 967 |
967 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 968 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
968 // set |source_path| the same, because ModifyCacheState moves files if source | 969 // set |source_path| the same, because ModifyCacheState moves files if source |
969 // and destination are different. | 970 // and destination are different. |
970 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 971 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
971 sub_dir_type = CACHE_TYPE_PERSISTENT; | 972 sub_dir_type = CACHE_TYPE_PERSISTENT; |
972 DCHECK_EQ(sub_dir_type, cache_entry->sub_dir_type); | 973 DCHECK_EQ(sub_dir_type, cache_entry.sub_dir_type); |
973 dest_path = GetCacheFilePath(resource_id, | 974 dest_path = GetCacheFilePath(resource_id, |
974 md5, | 975 md5, |
975 cache_entry->sub_dir_type, | 976 cache_entry.sub_dir_type, |
976 CACHED_FILE_LOCALLY_MODIFIED); | 977 CACHED_FILE_LOCALLY_MODIFIED); |
977 source_path = dest_path; | 978 source_path = dest_path; |
978 } else { | 979 } else { |
979 // Gets the current path of the file in cache. | 980 // Gets the current path of the file in cache. |
980 source_path = GetCacheFilePath(resource_id, | 981 source_path = GetCacheFilePath(resource_id, |
981 md5, | 982 md5, |
982 cache_entry->sub_dir_type, | 983 cache_entry.sub_dir_type, |
983 CACHED_FILE_FROM_SERVER); | 984 CACHED_FILE_FROM_SERVER); |
984 | 985 |
985 // If file was pinned but actual file blob still doesn't exist in cache, | 986 // If file was pinned but actual file blob still doesn't exist in cache, |
986 // don't need to move the file, so set |dest_path| to |source_path|, because | 987 // don't need to move the file, so set |dest_path| to |source_path|, because |
987 // ModifyCacheState only moves files if source and destination are | 988 // ModifyCacheState only moves files if source and destination are |
988 // different. | 989 // different. |
989 if (cache_entry->sub_dir_type == CACHE_TYPE_PINNED) { | 990 if (cache_entry.sub_dir_type == CACHE_TYPE_PINNED) { |
990 dest_path = source_path; | 991 dest_path = source_path; |
991 } else { // File exists, move it to tmp dir. | 992 } else { // File exists, move it to tmp dir. |
992 dest_path = GetCacheFilePath(resource_id, md5, | 993 dest_path = GetCacheFilePath(resource_id, md5, |
993 CACHE_TYPE_TMP, | 994 CACHE_TYPE_TMP, |
994 CACHED_FILE_FROM_SERVER); | 995 CACHED_FILE_FROM_SERVER); |
995 } | 996 } |
996 } | 997 } |
997 | 998 |
998 // If file was pinned, get absolute path of symlink in pinned dir so as to | 999 // If file was pinned, get absolute path of symlink in pinned dir so as to |
999 // remove it. | 1000 // remove it. |
1000 FilePath symlink_path; | 1001 FilePath symlink_path; |
1001 if (cache_entry->IsPinned()) { | 1002 if (cache_entry.IsPinned()) { |
1002 symlink_path = GetCacheFilePath(resource_id, | 1003 symlink_path = GetCacheFilePath(resource_id, |
1003 std::string(), | 1004 std::string(), |
1004 CACHE_TYPE_PINNED, | 1005 CACHE_TYPE_PINNED, |
1005 CACHED_FILE_FROM_SERVER); | 1006 CACHED_FILE_FROM_SERVER); |
1006 } | 1007 } |
1007 | 1008 |
1008 *error = ModifyCacheState( | 1009 *error = ModifyCacheState( |
1009 source_path, | 1010 source_path, |
1010 dest_path, | 1011 dest_path, |
1011 file_operation_type, | 1012 file_operation_type, |
1012 symlink_path, // This will be deleted if it exists. | 1013 symlink_path, // This will be deleted if it exists. |
1013 false /* don't create symlink*/); | 1014 false /* don't create symlink*/); |
1014 | 1015 |
1015 if (*error == base::PLATFORM_FILE_OK) { | 1016 if (*error == base::PLATFORM_FILE_OK) { |
1016 // Now that file operations have completed, update cache map. | 1017 // Now that file operations have completed, update cache map. |
1017 int cache_state = ClearCachePinned(cache_entry->cache_state); | 1018 int cache_state = ClearCachePinned(cache_entry.cache_state); |
1018 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); | 1019 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); |
1019 } | 1020 } |
1020 } | 1021 } |
1021 | 1022 |
1022 void GDataCache::SetMountedState(const FilePath& file_path, | 1023 void GDataCache::SetMountedState(const FilePath& file_path, |
1023 bool to_mount, | 1024 bool to_mount, |
1024 base::PlatformFileError *error, | 1025 base::PlatformFileError *error, |
1025 FilePath* cache_file_path) { | 1026 FilePath* cache_file_path) { |
1026 AssertOnSequencedWorkerPool(); | 1027 AssertOnSequencedWorkerPool(); |
1027 DCHECK(error); | 1028 DCHECK(error); |
1028 DCHECK(cache_file_path); | 1029 DCHECK(cache_file_path); |
1029 | 1030 |
1030 // Parse file path to obtain resource_id, md5 and extra_extension. | 1031 // Parse file path to obtain resource_id, md5 and extra_extension. |
1031 std::string resource_id; | 1032 std::string resource_id; |
1032 std::string md5; | 1033 std::string md5; |
1033 std::string extra_extension; | 1034 std::string extra_extension; |
1034 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); | 1035 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); |
1035 // The extra_extension shall be ".mounted" iff we're unmounting. | 1036 // The extra_extension shall be ".mounted" iff we're unmounting. |
1036 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); | 1037 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); |
1037 | 1038 |
1038 // Get cache entry associated with the resource_id and md5 | 1039 // Get cache entry associated with the resource_id and md5 |
1039 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 1040 CacheEntry cache_entry; |
1040 resource_id, md5); | 1041 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
1041 if (!cache_entry.get()) { | |
1042 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1042 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1043 return; | 1043 return; |
1044 } | 1044 } |
1045 if (to_mount == cache_entry->IsMounted()) { | 1045 if (to_mount == cache_entry.IsMounted()) { |
1046 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1046 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
1047 return; | 1047 return; |
1048 } | 1048 } |
1049 | 1049 |
1050 // Get the subdir type and path for the unmounted state. | 1050 // Get the subdir type and path for the unmounted state. |
1051 CacheSubDirectoryType unmounted_subdir = | 1051 CacheSubDirectoryType unmounted_subdir = |
1052 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1052 cache_entry.IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1053 FilePath unmounted_path = GetCacheFilePath( | 1053 FilePath unmounted_path = GetCacheFilePath( |
1054 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); | 1054 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); |
1055 | 1055 |
1056 // Get the subdir type and path for the mounted state. | 1056 // Get the subdir type and path for the mounted state. |
1057 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; | 1057 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; |
1058 FilePath mounted_path = GetCacheFilePath( | 1058 FilePath mounted_path = GetCacheFilePath( |
1059 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); | 1059 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); |
1060 | 1060 |
1061 // Determine the source and destination paths for moving the cache blob. | 1061 // Determine the source and destination paths for moving the cache blob. |
1062 FilePath source_path; | 1062 FilePath source_path; |
1063 CacheSubDirectoryType dest_subdir; | 1063 CacheSubDirectoryType dest_subdir; |
1064 int cache_state = cache_entry->cache_state; | 1064 int cache_state = cache_entry.cache_state; |
1065 if (to_mount) { | 1065 if (to_mount) { |
1066 source_path = unmounted_path; | 1066 source_path = unmounted_path; |
1067 *cache_file_path = mounted_path; | 1067 *cache_file_path = mounted_path; |
1068 dest_subdir = mounted_subdir; | 1068 dest_subdir = mounted_subdir; |
1069 cache_state = SetCacheMounted(cache_state); | 1069 cache_state = SetCacheMounted(cache_state); |
1070 } else { | 1070 } else { |
1071 source_path = mounted_path; | 1071 source_path = mounted_path; |
1072 *cache_file_path = unmounted_path; | 1072 *cache_file_path = unmounted_path; |
1073 dest_subdir = unmounted_subdir; | 1073 dest_subdir = unmounted_subdir; |
1074 cache_state = ClearCacheMounted(cache_state); | 1074 cache_state = ClearCacheMounted(cache_state); |
(...skipping 14 matching lines...) Expand all Loading... | |
1089 base::PlatformFileError* error, | 1089 base::PlatformFileError* error, |
1090 FilePath* cache_file_path) { | 1090 FilePath* cache_file_path) { |
1091 AssertOnSequencedWorkerPool(); | 1091 AssertOnSequencedWorkerPool(); |
1092 DCHECK(error); | 1092 DCHECK(error); |
1093 DCHECK(cache_file_path); | 1093 DCHECK(cache_file_path); |
1094 | 1094 |
1095 // If file has already been marked dirty in previous instance of chrome, we | 1095 // If file has already been marked dirty in previous instance of chrome, we |
1096 // would have lost the md5 info during cache initialization, because the file | 1096 // would have lost the md5 info during cache initialization, because the file |
1097 // would have been renamed to .local extension. | 1097 // would have been renamed to .local extension. |
1098 // So, search for entry in cache without comparing md5. | 1098 // So, search for entry in cache without comparing md5. |
1099 scoped_ptr<CacheEntry> cache_entry = | 1099 CacheEntry cache_entry; |
1100 GetCacheEntry(resource_id, std::string()); | |
1101 | 1100 |
1102 // Marking a file dirty means its entry and actual file blob must exist in | 1101 // Marking a file dirty means its entry and actual file blob must exist in |
1103 // cache. | 1102 // cache. |
1104 if (!cache_entry.get() || | 1103 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
1105 cache_entry->sub_dir_type == CACHE_TYPE_PINNED) { | 1104 cache_entry.sub_dir_type == CACHE_TYPE_PINNED) { |
1106 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" | 1105 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" |
1107 << resource_id | 1106 << resource_id |
1108 << ", md5=" << md5; | 1107 << ", md5=" << md5; |
1109 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1108 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1110 return; | 1109 return; |
1111 } | 1110 } |
1112 | 1111 |
1113 // If a file is already dirty (i.e. MarkDirtyInCache was called before), | 1112 // If a file is already dirty (i.e. MarkDirtyInCache was called before), |
1114 // delete outgoing symlink if it exists. | 1113 // delete outgoing symlink if it exists. |
1115 // TODO(benchan): We should only delete outgoing symlink if file is currently | 1114 // TODO(benchan): We should only delete outgoing symlink if file is currently |
1116 // not being uploaded. However, for now, cache doesn't know if uploading of a | 1115 // not being uploaded. However, for now, cache doesn't know if uploading of a |
1117 // file is in progress. Per zel, the upload process should be canceled before | 1116 // file is in progress. Per zel, the upload process should be canceled before |
1118 // MarkDirtyInCache is called again. | 1117 // MarkDirtyInCache is called again. |
1119 if (cache_entry->IsDirty()) { | 1118 if (cache_entry.IsDirty()) { |
1120 // The file must be in persistent dir. | 1119 // The file must be in persistent dir. |
1121 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); | 1120 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry.sub_dir_type); |
1122 | 1121 |
1123 // Determine symlink path in outgoing dir, so as to remove it. | 1122 // Determine symlink path in outgoing dir, so as to remove it. |
1124 FilePath symlink_path = GetCacheFilePath( | 1123 FilePath symlink_path = GetCacheFilePath( |
1125 resource_id, | 1124 resource_id, |
1126 std::string(), | 1125 std::string(), |
1127 CACHE_TYPE_OUTGOING, | 1126 CACHE_TYPE_OUTGOING, |
1128 CACHED_FILE_FROM_SERVER); | 1127 CACHED_FILE_FROM_SERVER); |
1129 | 1128 |
1130 // We're not moving files here, so simply use empty FilePath for both | 1129 // We're not moving files here, so simply use empty FilePath for both |
1131 // |source_path| and |dest_path| because ModifyCacheState only move files | 1130 // |source_path| and |dest_path| because ModifyCacheState only move files |
(...skipping 15 matching lines...) Expand all Loading... | |
1147 } | 1146 } |
1148 return; | 1147 return; |
1149 } | 1148 } |
1150 | 1149 |
1151 // Move file to persistent dir with new .local extension. | 1150 // Move file to persistent dir with new .local extension. |
1152 | 1151 |
1153 // Get the current path of the file in cache. | 1152 // Get the current path of the file in cache. |
1154 FilePath source_path = GetCacheFilePath( | 1153 FilePath source_path = GetCacheFilePath( |
1155 resource_id, | 1154 resource_id, |
1156 md5, | 1155 md5, |
1157 cache_entry->sub_dir_type, | 1156 cache_entry.sub_dir_type, |
1158 CACHED_FILE_FROM_SERVER); | 1157 CACHED_FILE_FROM_SERVER); |
1159 | 1158 |
1160 // Determine destination path. | 1159 // Determine destination path. |
1161 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 1160 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
1162 *cache_file_path = GetCacheFilePath(resource_id, | 1161 *cache_file_path = GetCacheFilePath(resource_id, |
1163 md5, | 1162 md5, |
1164 sub_dir_type, | 1163 sub_dir_type, |
1165 CACHED_FILE_LOCALLY_MODIFIED); | 1164 CACHED_FILE_LOCALLY_MODIFIED); |
1166 | 1165 |
1167 // If file is pinned, update symlink in pinned dir. | 1166 // If file is pinned, update symlink in pinned dir. |
1168 FilePath symlink_path; | 1167 FilePath symlink_path; |
1169 if (cache_entry->IsPinned()) { | 1168 if (cache_entry.IsPinned()) { |
1170 symlink_path = GetCacheFilePath(resource_id, | 1169 symlink_path = GetCacheFilePath(resource_id, |
1171 std::string(), | 1170 std::string(), |
1172 CACHE_TYPE_PINNED, | 1171 CACHE_TYPE_PINNED, |
1173 CACHED_FILE_FROM_SERVER); | 1172 CACHED_FILE_FROM_SERVER); |
1174 } | 1173 } |
1175 | 1174 |
1176 *error = ModifyCacheState( | 1175 *error = ModifyCacheState( |
1177 source_path, | 1176 source_path, |
1178 *cache_file_path, | 1177 *cache_file_path, |
1179 file_operation_type, | 1178 file_operation_type, |
1180 symlink_path, | 1179 symlink_path, |
1181 !symlink_path.empty() /* create symlink */); | 1180 !symlink_path.empty() /* create symlink */); |
1182 | 1181 |
1183 if (*error == base::PLATFORM_FILE_OK) { | 1182 if (*error == base::PLATFORM_FILE_OK) { |
1184 // Now that file operations have completed, update cache map. | 1183 // Now that file operations have completed, update cache map. |
1185 int cache_state = SetCacheDirty(cache_entry->cache_state); | 1184 int cache_state = SetCacheDirty(cache_entry.cache_state); |
1186 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); | 1185 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); |
1187 } | 1186 } |
1188 } | 1187 } |
1189 | 1188 |
1190 void GDataCache::CommitDirty(const std::string& resource_id, | 1189 void GDataCache::CommitDirty(const std::string& resource_id, |
1191 const std::string& md5, | 1190 const std::string& md5, |
1192 FileOperationType file_operation_type, | 1191 FileOperationType file_operation_type, |
1193 base::PlatformFileError* error) { | 1192 base::PlatformFileError* error) { |
1194 AssertOnSequencedWorkerPool(); | 1193 AssertOnSequencedWorkerPool(); |
1195 DCHECK(error); | 1194 DCHECK(error); |
1196 | 1195 |
1197 // If file has already been marked dirty in previous instance of chrome, we | 1196 // If file has already been marked dirty in previous instance of chrome, we |
1198 // would have lost the md5 info during cache initialization, because the file | 1197 // would have lost the md5 info during cache initialization, because the file |
1199 // would have been renamed to .local extension. | 1198 // would have been renamed to .local extension. |
1200 // So, search for entry in cache without comparing md5. | 1199 // So, search for entry in cache without comparing md5. |
1201 scoped_ptr<CacheEntry> cache_entry = | 1200 CacheEntry cache_entry; |
1202 GetCacheEntry(resource_id, std::string()); | |
1203 | 1201 |
1204 // Committing a file dirty means its entry and actual file blob must exist in | 1202 // Committing a file dirty means its entry and actual file blob must exist in |
1205 // cache. | 1203 // cache. |
1206 if (!cache_entry.get() || | 1204 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
1207 cache_entry->sub_dir_type == CACHE_TYPE_PINNED) { | 1205 cache_entry.sub_dir_type == CACHE_TYPE_PINNED) { |
1208 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" | 1206 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" |
1209 << resource_id | 1207 << resource_id |
1210 << ", md5=" << md5; | 1208 << ", md5=" << md5; |
1211 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1209 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1212 return; | 1210 return; |
1213 } | 1211 } |
1214 | 1212 |
1215 // If a file is not dirty (it should have been marked dirty via | 1213 // If a file is not dirty (it should have been marked dirty via |
1216 // MarkDirtyInCache), committing it dirty is an invalid operation. | 1214 // MarkDirtyInCache), committing it dirty is an invalid operation. |
1217 if (!cache_entry->IsDirty()) { | 1215 if (!cache_entry.IsDirty()) { |
1218 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" | 1216 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" |
1219 << resource_id | 1217 << resource_id |
1220 << ", md5=" << md5; | 1218 << ", md5=" << md5; |
1221 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1219 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
1222 return; | 1220 return; |
1223 } | 1221 } |
1224 | 1222 |
1225 // Dirty files must be in persistent dir. | 1223 // Dirty files must be in persistent dir. |
1226 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); | 1224 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry.sub_dir_type); |
1227 | 1225 |
1228 // Create symlink in outgoing dir. | 1226 // Create symlink in outgoing dir. |
1229 FilePath symlink_path = GetCacheFilePath(resource_id, | 1227 FilePath symlink_path = GetCacheFilePath(resource_id, |
1230 std::string(), | 1228 std::string(), |
1231 CACHE_TYPE_OUTGOING, | 1229 CACHE_TYPE_OUTGOING, |
1232 CACHED_FILE_FROM_SERVER); | 1230 CACHED_FILE_FROM_SERVER); |
1233 | 1231 |
1234 // Get target path of symlink i.e. current path of the file in cache. | 1232 // Get target path of symlink i.e. current path of the file in cache. |
1235 FilePath target_path = GetCacheFilePath(resource_id, | 1233 FilePath target_path = GetCacheFilePath(resource_id, |
1236 md5, | 1234 md5, |
1237 cache_entry->sub_dir_type, | 1235 cache_entry.sub_dir_type, |
1238 CACHED_FILE_LOCALLY_MODIFIED); | 1236 CACHED_FILE_LOCALLY_MODIFIED); |
1239 | 1237 |
1240 // Since there's no need to move files, use |target_path| for both | 1238 // Since there's no need to move files, use |target_path| for both |
1241 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1239 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
1242 // if source and destination are different. | 1240 // if source and destination are different. |
1243 *error = ModifyCacheState(target_path, // source | 1241 *error = ModifyCacheState(target_path, // source |
1244 target_path, // destination | 1242 target_path, // destination |
1245 file_operation_type, | 1243 file_operation_type, |
1246 symlink_path, | 1244 symlink_path, |
1247 true /* create symlink */); | 1245 true /* create symlink */); |
1248 } | 1246 } |
1249 | 1247 |
1250 void GDataCache::ClearDirty(const std::string& resource_id, | 1248 void GDataCache::ClearDirty(const std::string& resource_id, |
1251 const std::string& md5, | 1249 const std::string& md5, |
1252 FileOperationType file_operation_type, | 1250 FileOperationType file_operation_type, |
1253 base::PlatformFileError* error) { | 1251 base::PlatformFileError* error) { |
1254 AssertOnSequencedWorkerPool(); | 1252 AssertOnSequencedWorkerPool(); |
1255 DCHECK(error); | 1253 DCHECK(error); |
1256 | 1254 |
1257 // |md5| is the new .<md5> extension to rename the file to. | 1255 // |md5| is the new .<md5> extension to rename the file to. |
1258 // So, search for entry in cache without comparing md5. | 1256 // So, search for entry in cache without comparing md5. |
1259 scoped_ptr<CacheEntry> cache_entry = | 1257 CacheEntry cache_entry; |
1260 GetCacheEntry(resource_id, std::string()); | |
1261 | 1258 |
1262 // Clearing a dirty file means its entry and actual file blob must exist in | 1259 // Clearing a dirty file means its entry and actual file blob must exist in |
1263 // cache. | 1260 // cache. |
1264 if (!cache_entry.get() || | 1261 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
1265 cache_entry->sub_dir_type == CACHE_TYPE_PINNED) { | 1262 cache_entry.sub_dir_type == CACHE_TYPE_PINNED) { |
1266 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " | 1263 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " |
1267 << "res_id=" << resource_id | 1264 << "res_id=" << resource_id |
1268 << ", md5=" << md5; | 1265 << ", md5=" << md5; |
1269 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1266 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1270 return; | 1267 return; |
1271 } | 1268 } |
1272 | 1269 |
1273 // If a file is not dirty (it should have been marked dirty via | 1270 // If a file is not dirty (it should have been marked dirty via |
1274 // MarkDirtyInCache), clearing its dirty state is an invalid operation. | 1271 // MarkDirtyInCache), clearing its dirty state is an invalid operation. |
1275 if (!cache_entry->IsDirty()) { | 1272 if (!cache_entry.IsDirty()) { |
1276 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" | 1273 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" |
1277 << resource_id | 1274 << resource_id |
1278 << ", md5=" << md5; | 1275 << ", md5=" << md5; |
1279 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1276 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
1280 return; | 1277 return; |
1281 } | 1278 } |
1282 | 1279 |
1283 // File must be dirty and hence in persistent dir. | 1280 // File must be dirty and hence in persistent dir. |
1284 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); | 1281 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry.sub_dir_type); |
1285 | 1282 |
1286 // Get the current path of the file in cache. | 1283 // Get the current path of the file in cache. |
1287 FilePath source_path = GetCacheFilePath(resource_id, | 1284 FilePath source_path = GetCacheFilePath(resource_id, |
1288 md5, | 1285 md5, |
1289 cache_entry->sub_dir_type, | 1286 cache_entry.sub_dir_type, |
1290 CACHED_FILE_LOCALLY_MODIFIED); | 1287 CACHED_FILE_LOCALLY_MODIFIED); |
1291 | 1288 |
1292 // Determine destination path. | 1289 // Determine destination path. |
1293 // If file is pinned, move it to persistent dir with .md5 extension; | 1290 // If file is pinned, move it to persistent dir with .md5 extension; |
1294 // otherwise, move it to tmp dir with .md5 extension. | 1291 // otherwise, move it to tmp dir with .md5 extension. |
1295 CacheSubDirectoryType sub_dir_type = | 1292 CacheSubDirectoryType sub_dir_type = |
1296 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1293 cache_entry.IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1297 FilePath dest_path = GetCacheFilePath(resource_id, | 1294 FilePath dest_path = GetCacheFilePath(resource_id, |
1298 md5, | 1295 md5, |
1299 sub_dir_type, | 1296 sub_dir_type, |
1300 CACHED_FILE_FROM_SERVER); | 1297 CACHED_FILE_FROM_SERVER); |
1301 | 1298 |
1302 // Delete symlink in outgoing dir. | 1299 // Delete symlink in outgoing dir. |
1303 FilePath symlink_path = GetCacheFilePath(resource_id, | 1300 FilePath symlink_path = GetCacheFilePath(resource_id, |
1304 std::string(), | 1301 std::string(), |
1305 CACHE_TYPE_OUTGOING, | 1302 CACHE_TYPE_OUTGOING, |
1306 CACHED_FILE_FROM_SERVER); | 1303 CACHED_FILE_FROM_SERVER); |
1307 | 1304 |
1308 *error = ModifyCacheState(source_path, | 1305 *error = ModifyCacheState(source_path, |
1309 dest_path, | 1306 dest_path, |
1310 file_operation_type, | 1307 file_operation_type, |
1311 symlink_path, | 1308 symlink_path, |
1312 false /* don't create symlink */); | 1309 false /* don't create symlink */); |
1313 | 1310 |
1314 // If file is pinned, update symlink in pinned dir. | 1311 // If file is pinned, update symlink in pinned dir. |
1315 if (*error == base::PLATFORM_FILE_OK && cache_entry->IsPinned()) { | 1312 if (*error == base::PLATFORM_FILE_OK && cache_entry.IsPinned()) { |
1316 symlink_path = GetCacheFilePath(resource_id, | 1313 symlink_path = GetCacheFilePath(resource_id, |
1317 std::string(), | 1314 std::string(), |
1318 CACHE_TYPE_PINNED, | 1315 CACHE_TYPE_PINNED, |
1319 CACHED_FILE_FROM_SERVER); | 1316 CACHED_FILE_FROM_SERVER); |
1320 | 1317 |
1321 // Since there's no moving of files here, use |dest_path| for both | 1318 // Since there's no moving of files here, use |dest_path| for both |
1322 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1319 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
1323 // if source and destination are different. | 1320 // if source and destination are different. |
1324 *error = ModifyCacheState(dest_path, // source path | 1321 *error = ModifyCacheState(dest_path, // source path |
1325 dest_path, // destination path | 1322 dest_path, // destination path |
1326 file_operation_type, | 1323 file_operation_type, |
1327 symlink_path, | 1324 symlink_path, |
1328 true /* create symlink */); | 1325 true /* create symlink */); |
1329 } | 1326 } |
1330 | 1327 |
1331 if (*error == base::PLATFORM_FILE_OK) { | 1328 if (*error == base::PLATFORM_FILE_OK) { |
1332 // Now that file operations have completed, update cache map. | 1329 // Now that file operations have completed, update cache map. |
1333 int cache_state = ClearCacheDirty(cache_entry->cache_state); | 1330 int cache_state = ClearCacheDirty(cache_entry.cache_state); |
1334 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); | 1331 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state); |
1335 } | 1332 } |
1336 } | 1333 } |
1337 | 1334 |
1338 void GDataCache::Remove(const std::string& resource_id, | 1335 void GDataCache::Remove(const std::string& resource_id, |
1339 base::PlatformFileError* error) { | 1336 base::PlatformFileError* error) { |
1340 AssertOnSequencedWorkerPool(); | 1337 AssertOnSequencedWorkerPool(); |
1341 DCHECK(error); | 1338 DCHECK(error); |
1342 | 1339 |
1343 // MD5 is not passed into RemoveFromCache and hence | 1340 // MD5 is not passed into RemoveFromCache and hence |
1344 // RemoveFromCacheOnBlockingPool, because we would delete all cache files | 1341 // RemoveFromCacheOnBlockingPool, because we would delete all cache files |
1345 // corresponding to <resource_id> regardless of the md5. | 1342 // corresponding to <resource_id> regardless of the md5. |
1346 // So, search for entry in cache without taking md5 into account. | 1343 // So, search for entry in cache without taking md5 into account. |
1347 scoped_ptr<CacheEntry> cache_entry = | 1344 CacheEntry cache_entry; |
1348 GetCacheEntry(resource_id, std::string()); | |
1349 | 1345 |
1350 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. | 1346 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. |
1351 if (!cache_entry.get() || | 1347 const bool entry_found = |
1352 cache_entry->IsDirty() || | 1348 GetCacheEntry(resource_id, std::string(), &cache_entry); |
1353 cache_entry->IsMounted()) { | 1349 if (!entry_found || cache_entry.IsDirty() || cache_entry.IsMounted()) { |
1354 DVLOG(1) << "Entry is " | 1350 DVLOG(1) << "Entry is " |
1355 << (cache_entry.get() ? | 1351 << (entry_found ? |
1356 (cache_entry->IsDirty() ? "dirty" : "mounted") : | 1352 (cache_entry.IsDirty() ? "dirty" : "mounted") : |
1357 "non-existent") | 1353 "non-existent") |
1358 << " in cache, not removing"; | 1354 << " in cache, not removing"; |
1359 *error = base::PLATFORM_FILE_OK; | 1355 *error = base::PLATFORM_FILE_OK; |
1360 return; | 1356 return; |
1361 } | 1357 } |
1362 | 1358 |
1363 // Determine paths to delete all cache versions of |resource_id| in | 1359 // Determine paths to delete all cache versions of |resource_id| in |
1364 // persistent, tmp and pinned directories. | 1360 // persistent, tmp and pinned directories. |
1365 std::vector<FilePath> paths_to_delete; | 1361 std::vector<FilePath> paths_to_delete; |
1366 | 1362 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1460 cache_base_path.Append(chrome::kGDataCacheDirname); | 1456 cache_base_path.Append(chrome::kGDataCacheDirname); |
1461 return cache_root_path.Append(kGDataCacheVersionDir); | 1457 return cache_root_path.Append(kGDataCacheVersionDir); |
1462 } | 1458 } |
1463 | 1459 |
1464 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1460 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1465 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1461 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1466 global_free_disk_getter_for_testing = getter; | 1462 global_free_disk_getter_for_testing = getter; |
1467 } | 1463 } |
1468 | 1464 |
1469 } // namespace gdata | 1465 } // namespace gdata |
OLD | NEW |