Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache.cc

Issue 10698135: Revert 145933 - gdata: Remove sub_dir_type from CacheEntry for simplicity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 const FilePath::CharType kGDataCacheOutgoingDir[] = 30 const FilePath::CharType kGDataCacheOutgoingDir[] =
31 FILE_PATH_LITERAL("outgoing"); 31 FILE_PATH_LITERAL("outgoing");
32 const FilePath::CharType kGDataCachePersistentDir[] = 32 const FilePath::CharType kGDataCachePersistentDir[] =
33 FILE_PATH_LITERAL("persistent"); 33 FILE_PATH_LITERAL("persistent");
34 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 34 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
35 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 35 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
36 FILE_PATH_LITERAL("tmp/downloads"); 36 FILE_PATH_LITERAL("tmp/downloads");
37 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = 37 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
38 FILE_PATH_LITERAL("tmp/documents"); 38 FILE_PATH_LITERAL("tmp/documents");
39 39
40 std::string CacheSubDirectoryTypeToString(
41 GDataCache::CacheSubDirectoryType subdir) {
42 switch (subdir) {
43 case GDataCache::CACHE_TYPE_META:
44 return "meta";
45 case GDataCache::CACHE_TYPE_PINNED:
46 return "pinned";
47 case GDataCache::CACHE_TYPE_OUTGOING:
48 return "outgoing";
49 case GDataCache::CACHE_TYPE_PERSISTENT:
50 return "persistent";
51 case GDataCache::CACHE_TYPE_TMP:
52 return "tmp";
53 case GDataCache::CACHE_TYPE_TMP_DOWNLOADS:
54 return "tmp_downloads";
55 case GDataCache::CACHE_TYPE_TMP_DOCUMENTS:
56 return "tmp_documents";
57 case GDataCache::NUM_CACHE_TYPES:
58 NOTREACHED();
59 }
60 NOTREACHED();
61 return "unknown subdir";
62 }
63
40 // Returns the home directory path, or an empty string if the home directory 64 // Returns the home directory path, or an empty string if the home directory
41 // is not found. 65 // is not found.
42 // Copied from webkit/chromeos/cros_mount_point_provider.h. 66 // Copied from webkit/chromeos/cros_mount_point_provider.h.
43 // TODO(satorux): Share the code. 67 // TODO(satorux): Share the code.
44 std::string GetHomeDirectory() { 68 std::string GetHomeDirectory() {
45 if (base::chromeos::IsRunningOnChromeOS()) 69 if (base::chromeos::IsRunningOnChromeOS())
46 return "/home/chronos/user"; 70 return "/home/chronos/user";
47 71
48 const char* home = getenv("HOME"); 72 const char* home = getenv("HOME");
49 if (home) 73 if (home)
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } // namespace 360 } // namespace
337 361
338 std::string GDataCache::CacheEntry::ToString() const { 362 std::string GDataCache::CacheEntry::ToString() const {
339 std::vector<std::string> cache_states; 363 std::vector<std::string> cache_states;
340 if (GDataCache::IsCachePresent(cache_state)) 364 if (GDataCache::IsCachePresent(cache_state))
341 cache_states.push_back("present"); 365 cache_states.push_back("present");
342 if (GDataCache::IsCachePinned(cache_state)) 366 if (GDataCache::IsCachePinned(cache_state))
343 cache_states.push_back("pinned"); 367 cache_states.push_back("pinned");
344 if (GDataCache::IsCacheDirty(cache_state)) 368 if (GDataCache::IsCacheDirty(cache_state))
345 cache_states.push_back("dirty"); 369 cache_states.push_back("dirty");
346 if (GDataCache::IsCachePersistent(cache_state))
347 cache_states.push_back("persistent");
348 370
349 return base::StringPrintf("md5=%s, cache_state=%s", 371 return base::StringPrintf("md5=%s, subdir=%s, cache_state=%s",
350 md5.c_str(), 372 md5.c_str(),
373 CacheSubDirectoryTypeToString(sub_dir_type).c_str(),
351 JoinString(cache_states, ',').c_str()); 374 JoinString(cache_states, ',').c_str());
352 } 375 }
353 376
354 GDataCache::GDataCache( 377 GDataCache::GDataCache(
355 const FilePath& cache_root_path, 378 const FilePath& cache_root_path,
356 base::SequencedWorkerPool* pool, 379 base::SequencedWorkerPool* pool,
357 const base::SequencedWorkerPool::SequenceToken& sequence_token) 380 const base::SequencedWorkerPool::SequenceToken& sequence_token)
358 : cache_root_path_(cache_root_path), 381 : cache_root_path_(cache_root_path),
359 cache_paths_(GetCachePaths(cache_root_path_)), 382 cache_paths_(GetCachePaths(cache_root_path_)),
360 pool_(pool), 383 pool_(pool),
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 if (cache_entry->IsMounted()) { 810 if (cache_entry->IsMounted()) {
788 file_origin = CACHED_FILE_MOUNTED; 811 file_origin = CACHED_FILE_MOUNTED;
789 } else if (cache_entry->IsDirty()) { 812 } else if (cache_entry->IsDirty()) {
790 file_origin = CACHED_FILE_LOCALLY_MODIFIED; 813 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
791 } else { 814 } else {
792 file_origin = CACHED_FILE_FROM_SERVER; 815 file_origin = CACHED_FILE_FROM_SERVER;
793 } 816 }
794 *cache_file_path = GetCacheFilePath( 817 *cache_file_path = GetCacheFilePath(
795 resource_id, 818 resource_id,
796 md5, 819 md5,
797 cache_entry->GetSubDirectoryType(), 820 cache_entry->sub_dir_type,
798 file_origin); 821 file_origin);
799 *error = base::PLATFORM_FILE_OK; 822 *error = base::PLATFORM_FILE_OK;
800 } else { 823 } else {
801 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; 824 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND;
802 } 825 }
803 } 826 }
804 827
805 void GDataCache::Store(const std::string& resource_id, 828 void GDataCache::Store(const std::string& resource_id,
806 const std::string& md5, 829 const std::string& md5,
807 const FilePath& source_path, 830 const FilePath& source_path,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 // Note that ReplaceExtension automatically prefixes the extension with the 896 // Note that ReplaceExtension automatically prefixes the extension with the
874 // extension separator '.'. 897 // extension separator '.'.
875 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); 898 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard);
876 } 899 }
877 900
878 // Delete files that match |stale_filenames_pattern| except for |dest_path|. 901 // Delete files that match |stale_filenames_pattern| except for |dest_path|.
879 DeleteFilesSelectively(stale_filenames_pattern, dest_path); 902 DeleteFilesSelectively(stale_filenames_pattern, dest_path);
880 903
881 if (*error == base::PLATFORM_FILE_OK) { 904 if (*error == base::PLATFORM_FILE_OK) {
882 // Now that file operations have completed, update cache map. 905 // Now that file operations have completed, update cache map.
883 UpdateCacheWithSubDirectoryType(resource_id, 906 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
884 md5,
885 sub_dir_type,
886 cache_state);
887 } 907 }
888 } 908 }
889 909
890 void GDataCache::Pin(const std::string& resource_id, 910 void GDataCache::Pin(const std::string& resource_id,
891 const std::string& md5, 911 const std::string& md5,
892 FileOperationType file_operation_type, 912 FileOperationType file_operation_type,
893 base::PlatformFileError* error) { 913 base::PlatformFileError* error) {
894 AssertOnSequencedWorkerPool(); 914 AssertOnSequencedWorkerPool();
895 DCHECK(error); 915 DCHECK(error);
896 916
(...skipping 20 matching lines...) Expand all
917 sub_dir_type = CACHE_TYPE_TMP; 937 sub_dir_type = CACHE_TYPE_TMP;
918 } else { // File exists in cache, determines destination path. 938 } else { // File exists in cache, determines destination path.
919 cache_state |= cache_entry->cache_state; 939 cache_state |= cache_entry->cache_state;
920 940
921 // Determine source and destination paths. 941 // Determine source and destination paths.
922 942
923 // If file is dirty or mounted, don't move it, so determine |dest_path| and 943 // If file is dirty or mounted, don't move it, so determine |dest_path| and
924 // set |source_path| the same, because ModifyCacheState only moves files if 944 // set |source_path| the same, because ModifyCacheState only moves files if
925 // source and destination are different. 945 // source and destination are different.
926 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { 946 if (cache_entry->IsDirty() || cache_entry->IsMounted()) {
927 DCHECK(cache_entry->IsPersistent()); 947 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
928 dest_path = GetCacheFilePath(resource_id, 948 dest_path = GetCacheFilePath(resource_id,
929 md5, 949 md5,
930 cache_entry->GetSubDirectoryType(), 950 cache_entry->sub_dir_type,
931 CACHED_FILE_LOCALLY_MODIFIED); 951 CACHED_FILE_LOCALLY_MODIFIED);
932 source_path = dest_path; 952 source_path = dest_path;
933 } else { 953 } else {
934 // Gets the current path of the file in cache. 954 // Gets the current path of the file in cache.
935 source_path = GetCacheFilePath(resource_id, 955 source_path = GetCacheFilePath(resource_id,
936 md5, 956 md5,
937 cache_entry->GetSubDirectoryType(), 957 cache_entry->sub_dir_type,
938 CACHED_FILE_FROM_SERVER); 958 CACHED_FILE_FROM_SERVER);
939 959
940 // If file was pinned before but actual file blob doesn't exist in cache: 960 // If file was pinned before but actual file blob doesn't exist in cache:
941 // - don't need to move the file, so set |dest_path| to |source_path|, 961 // - don't need to move the file, so set |dest_path| to |source_path|,
942 // because ModifyCacheState only moves files if source and destination 962 // because ModifyCacheState only moves files if source and destination
943 // are different 963 // are different
944 // - don't create symlink since it already exists. 964 // - don't create symlink since it already exists.
945 if (!cache_entry->IsPresent()) { 965 if (!cache_entry->IsPresent()) {
946 dest_path = source_path; 966 dest_path = source_path;
947 create_symlink = false; 967 create_symlink = false;
(...skipping 15 matching lines...) Expand all
963 } 983 }
964 984
965 *error = ModifyCacheState(source_path, 985 *error = ModifyCacheState(source_path,
966 dest_path, 986 dest_path,
967 file_operation_type, 987 file_operation_type,
968 symlink_path, 988 symlink_path,
969 create_symlink); 989 create_symlink);
970 990
971 if (*error == base::PLATFORM_FILE_OK) { 991 if (*error == base::PLATFORM_FILE_OK) {
972 // Now that file operations have completed, update cache map. 992 // Now that file operations have completed, update cache map.
973 UpdateCacheWithSubDirectoryType(resource_id, 993 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
974 md5,
975 sub_dir_type,
976 cache_state);
977 } 994 }
978 } 995 }
979 996
980 void GDataCache::Unpin(const std::string& resource_id, 997 void GDataCache::Unpin(const std::string& resource_id,
981 const std::string& md5, 998 const std::string& md5,
982 FileOperationType file_operation_type, 999 FileOperationType file_operation_type,
983 base::PlatformFileError* error) { 1000 base::PlatformFileError* error) {
984 AssertOnSequencedWorkerPool(); 1001 AssertOnSequencedWorkerPool();
985 DCHECK(error); 1002 DCHECK(error);
986 1003
(...skipping 12 matching lines...) Expand all
999 1016
1000 FilePath source_path; 1017 FilePath source_path;
1001 FilePath dest_path; 1018 FilePath dest_path;
1002 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; 1019 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP;
1003 1020
1004 // If file is dirty or mounted, don't move it, so determine |dest_path| and 1021 // If file is dirty or mounted, don't move it, so determine |dest_path| and
1005 // set |source_path| the same, because ModifyCacheState moves files if source 1022 // set |source_path| the same, because ModifyCacheState moves files if source
1006 // and destination are different. 1023 // and destination are different.
1007 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { 1024 if (cache_entry->IsDirty() || cache_entry->IsMounted()) {
1008 sub_dir_type = CACHE_TYPE_PERSISTENT; 1025 sub_dir_type = CACHE_TYPE_PERSISTENT;
1009 DCHECK(cache_entry->IsPersistent()); 1026 DCHECK_EQ(sub_dir_type, cache_entry->sub_dir_type);
1010 dest_path = GetCacheFilePath(resource_id, 1027 dest_path = GetCacheFilePath(resource_id,
1011 md5, 1028 md5,
1012 cache_entry->GetSubDirectoryType(), 1029 cache_entry->sub_dir_type,
1013 CACHED_FILE_LOCALLY_MODIFIED); 1030 CACHED_FILE_LOCALLY_MODIFIED);
1014 source_path = dest_path; 1031 source_path = dest_path;
1015 } else { 1032 } else {
1016 // Gets the current path of the file in cache. 1033 // Gets the current path of the file in cache.
1017 source_path = GetCacheFilePath(resource_id, 1034 source_path = GetCacheFilePath(resource_id,
1018 md5, 1035 md5,
1019 cache_entry->GetSubDirectoryType(), 1036 cache_entry->sub_dir_type,
1020 CACHED_FILE_FROM_SERVER); 1037 CACHED_FILE_FROM_SERVER);
1021 1038
1022 // If file was pinned but actual file blob still doesn't exist in cache, 1039 // If file was pinned but actual file blob still doesn't exist in cache,
1023 // don't need to move the file, so set |dest_path| to |source_path|, because 1040 // don't need to move the file, so set |dest_path| to |source_path|, because
1024 // ModifyCacheState only moves files if source and destination are 1041 // ModifyCacheState only moves files if source and destination are
1025 // different. 1042 // different.
1026 if (!cache_entry->IsPresent()) { 1043 if (!cache_entry->IsPresent()) {
1027 dest_path = source_path; 1044 dest_path = source_path;
1028 } else { // File exists, move it to tmp dir. 1045 } else { // File exists, move it to tmp dir.
1029 dest_path = GetCacheFilePath(resource_id, md5, 1046 dest_path = GetCacheFilePath(resource_id, md5,
(...skipping 15 matching lines...) Expand all
1045 *error = ModifyCacheState( 1062 *error = ModifyCacheState(
1046 source_path, 1063 source_path,
1047 dest_path, 1064 dest_path,
1048 file_operation_type, 1065 file_operation_type,
1049 symlink_path, // This will be deleted if it exists. 1066 symlink_path, // This will be deleted if it exists.
1050 false /* don't create symlink*/); 1067 false /* don't create symlink*/);
1051 1068
1052 if (*error == base::PLATFORM_FILE_OK) { 1069 if (*error == base::PLATFORM_FILE_OK) {
1053 // Now that file operations have completed, update cache map. 1070 // Now that file operations have completed, update cache map.
1054 int cache_state = ClearCachePinned(cache_entry->cache_state); 1071 int cache_state = ClearCachePinned(cache_entry->cache_state);
1055 UpdateCacheWithSubDirectoryType(resource_id, 1072 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
1056 md5,
1057 sub_dir_type,
1058 cache_state);
1059 } 1073 }
1060 } 1074 }
1061 1075
1062 void GDataCache::SetMountedState(const FilePath& file_path, 1076 void GDataCache::SetMountedState(const FilePath& file_path,
1063 bool to_mount, 1077 bool to_mount,
1064 base::PlatformFileError *error, 1078 base::PlatformFileError *error,
1065 FilePath* cache_file_path) { 1079 FilePath* cache_file_path) {
1066 AssertOnSequencedWorkerPool(); 1080 AssertOnSequencedWorkerPool();
1067 DCHECK(error); 1081 DCHECK(error);
1068 DCHECK(cache_file_path); 1082 DCHECK(cache_file_path);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 *cache_file_path = unmounted_path; 1126 *cache_file_path = unmounted_path;
1113 dest_subdir = unmounted_subdir; 1127 dest_subdir = unmounted_subdir;
1114 cache_state = ClearCacheMounted(cache_state); 1128 cache_state = ClearCacheMounted(cache_state);
1115 } 1129 }
1116 1130
1117 // Move cache blob from source path to destination path. 1131 // Move cache blob from source path to destination path.
1118 *error = ModifyCacheState(source_path, *cache_file_path, 1132 *error = ModifyCacheState(source_path, *cache_file_path,
1119 FILE_OPERATION_MOVE, FilePath(), false); 1133 FILE_OPERATION_MOVE, FilePath(), false);
1120 if (*error == base::PLATFORM_FILE_OK) { 1134 if (*error == base::PLATFORM_FILE_OK) {
1121 // Now that cache operation is complete, update cache map 1135 // Now that cache operation is complete, update cache map
1122 UpdateCacheWithSubDirectoryType(resource_id, 1136 metadata_->UpdateCache(resource_id, md5, dest_subdir, cache_state);
1123 md5,
1124 dest_subdir,
1125 cache_state);
1126 } 1137 }
1127 } 1138 }
1128 1139
1129 void GDataCache::MarkDirty(const std::string& resource_id, 1140 void GDataCache::MarkDirty(const std::string& resource_id,
1130 const std::string& md5, 1141 const std::string& md5,
1131 FileOperationType file_operation_type, 1142 FileOperationType file_operation_type,
1132 base::PlatformFileError* error, 1143 base::PlatformFileError* error,
1133 FilePath* cache_file_path) { 1144 FilePath* cache_file_path) {
1134 AssertOnSequencedWorkerPool(); 1145 AssertOnSequencedWorkerPool();
1135 DCHECK(error); 1146 DCHECK(error);
(...skipping 17 matching lines...) Expand all
1153 } 1164 }
1154 1165
1155 // If a file is already dirty (i.e. MarkDirtyInCache was called before), 1166 // If a file is already dirty (i.e. MarkDirtyInCache was called before),
1156 // delete outgoing symlink if it exists. 1167 // delete outgoing symlink if it exists.
1157 // TODO(benchan): We should only delete outgoing symlink if file is currently 1168 // TODO(benchan): We should only delete outgoing symlink if file is currently
1158 // not being uploaded. However, for now, cache doesn't know if uploading of a 1169 // not being uploaded. However, for now, cache doesn't know if uploading of a
1159 // file is in progress. Per zel, the upload process should be canceled before 1170 // file is in progress. Per zel, the upload process should be canceled before
1160 // MarkDirtyInCache is called again. 1171 // MarkDirtyInCache is called again.
1161 if (cache_entry->IsDirty()) { 1172 if (cache_entry->IsDirty()) {
1162 // The file must be in persistent dir. 1173 // The file must be in persistent dir.
1163 DCHECK(cache_entry->IsPersistent()); 1174 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
1164 1175
1165 // Determine symlink path in outgoing dir, so as to remove it. 1176 // Determine symlink path in outgoing dir, so as to remove it.
1166 FilePath symlink_path = GetCacheFilePath( 1177 FilePath symlink_path = GetCacheFilePath(
1167 resource_id, 1178 resource_id,
1168 std::string(), 1179 std::string(),
1169 CACHE_TYPE_OUTGOING, 1180 CACHE_TYPE_OUTGOING,
1170 CACHED_FILE_FROM_SERVER); 1181 CACHED_FILE_FROM_SERVER);
1171 1182
1172 // We're not moving files here, so simply use empty FilePath for both 1183 // We're not moving files here, so simply use empty FilePath for both
1173 // |source_path| and |dest_path| because ModifyCacheState only move files 1184 // |source_path| and |dest_path| because ModifyCacheState only move files
(...skipping 15 matching lines...) Expand all
1189 } 1200 }
1190 return; 1201 return;
1191 } 1202 }
1192 1203
1193 // Move file to persistent dir with new .local extension. 1204 // Move file to persistent dir with new .local extension.
1194 1205
1195 // Get the current path of the file in cache. 1206 // Get the current path of the file in cache.
1196 FilePath source_path = GetCacheFilePath( 1207 FilePath source_path = GetCacheFilePath(
1197 resource_id, 1208 resource_id,
1198 md5, 1209 md5,
1199 cache_entry->GetSubDirectoryType(), 1210 cache_entry->sub_dir_type,
1200 CACHED_FILE_FROM_SERVER); 1211 CACHED_FILE_FROM_SERVER);
1201 1212
1202 // Determine destination path. 1213 // Determine destination path.
1203 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; 1214 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT;
1204 *cache_file_path = GetCacheFilePath(resource_id, 1215 *cache_file_path = GetCacheFilePath(resource_id,
1205 md5, 1216 md5,
1206 sub_dir_type, 1217 sub_dir_type,
1207 CACHED_FILE_LOCALLY_MODIFIED); 1218 CACHED_FILE_LOCALLY_MODIFIED);
1208 1219
1209 // If file is pinned, update symlink in pinned dir. 1220 // If file is pinned, update symlink in pinned dir.
1210 FilePath symlink_path; 1221 FilePath symlink_path;
1211 if (cache_entry->IsPinned()) { 1222 if (cache_entry->IsPinned()) {
1212 symlink_path = GetCacheFilePath(resource_id, 1223 symlink_path = GetCacheFilePath(resource_id,
1213 std::string(), 1224 std::string(),
1214 CACHE_TYPE_PINNED, 1225 CACHE_TYPE_PINNED,
1215 CACHED_FILE_FROM_SERVER); 1226 CACHED_FILE_FROM_SERVER);
1216 } 1227 }
1217 1228
1218 *error = ModifyCacheState( 1229 *error = ModifyCacheState(
1219 source_path, 1230 source_path,
1220 *cache_file_path, 1231 *cache_file_path,
1221 file_operation_type, 1232 file_operation_type,
1222 symlink_path, 1233 symlink_path,
1223 !symlink_path.empty() /* create symlink */); 1234 !symlink_path.empty() /* create symlink */);
1224 1235
1225 if (*error == base::PLATFORM_FILE_OK) { 1236 if (*error == base::PLATFORM_FILE_OK) {
1226 // Now that file operations have completed, update cache map. 1237 // Now that file operations have completed, update cache map.
1227 int cache_state = SetCacheDirty(cache_entry->cache_state); 1238 int cache_state = SetCacheDirty(cache_entry->cache_state);
1228 UpdateCacheWithSubDirectoryType(resource_id, 1239 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
1229 md5,
1230 sub_dir_type,
1231 cache_state);
1232 } 1240 }
1233 } 1241 }
1234 1242
1235 void GDataCache::CommitDirty(const std::string& resource_id, 1243 void GDataCache::CommitDirty(const std::string& resource_id,
1236 const std::string& md5, 1244 const std::string& md5,
1237 FileOperationType file_operation_type, 1245 FileOperationType file_operation_type,
1238 base::PlatformFileError* error) { 1246 base::PlatformFileError* error) {
1239 AssertOnSequencedWorkerPool(); 1247 AssertOnSequencedWorkerPool();
1240 DCHECK(error); 1248 DCHECK(error);
1241 1249
(...skipping 18 matching lines...) Expand all
1260 // MarkDirtyInCache), committing it dirty is an invalid operation. 1268 // MarkDirtyInCache), committing it dirty is an invalid operation.
1261 if (!cache_entry->IsDirty()) { 1269 if (!cache_entry->IsDirty()) {
1262 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" 1270 LOG(WARNING) << "Can't commit a non-dirty file: res_id="
1263 << resource_id 1271 << resource_id
1264 << ", md5=" << md5; 1272 << ", md5=" << md5;
1265 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 1273 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
1266 return; 1274 return;
1267 } 1275 }
1268 1276
1269 // Dirty files must be in persistent dir. 1277 // Dirty files must be in persistent dir.
1270 DCHECK(cache_entry->IsPersistent()); 1278 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
1271 1279
1272 // Create symlink in outgoing dir. 1280 // Create symlink in outgoing dir.
1273 FilePath symlink_path = GetCacheFilePath(resource_id, 1281 FilePath symlink_path = GetCacheFilePath(resource_id,
1274 std::string(), 1282 std::string(),
1275 CACHE_TYPE_OUTGOING, 1283 CACHE_TYPE_OUTGOING,
1276 CACHED_FILE_FROM_SERVER); 1284 CACHED_FILE_FROM_SERVER);
1277 1285
1278 // Get target path of symlink i.e. current path of the file in cache. 1286 // Get target path of symlink i.e. current path of the file in cache.
1279 FilePath target_path = GetCacheFilePath(resource_id, 1287 FilePath target_path = GetCacheFilePath(resource_id,
1280 md5, 1288 md5,
1281 cache_entry->GetSubDirectoryType(), 1289 cache_entry->sub_dir_type,
1282 CACHED_FILE_LOCALLY_MODIFIED); 1290 CACHED_FILE_LOCALLY_MODIFIED);
1283 1291
1284 // Since there's no need to move files, use |target_path| for both 1292 // Since there's no need to move files, use |target_path| for both
1285 // |source_path| and |dest_path|, because ModifyCacheState only moves files 1293 // |source_path| and |dest_path|, because ModifyCacheState only moves files
1286 // if source and destination are different. 1294 // if source and destination are different.
1287 *error = ModifyCacheState(target_path, // source 1295 *error = ModifyCacheState(target_path, // source
1288 target_path, // destination 1296 target_path, // destination
1289 file_operation_type, 1297 file_operation_type,
1290 symlink_path, 1298 symlink_path,
1291 true /* create symlink */); 1299 true /* create symlink */);
(...skipping 25 matching lines...) Expand all
1317 // MarkDirtyInCache), clearing its dirty state is an invalid operation. 1325 // MarkDirtyInCache), clearing its dirty state is an invalid operation.
1318 if (!cache_entry->IsDirty()) { 1326 if (!cache_entry->IsDirty()) {
1319 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" 1327 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id="
1320 << resource_id 1328 << resource_id
1321 << ", md5=" << md5; 1329 << ", md5=" << md5;
1322 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 1330 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
1323 return; 1331 return;
1324 } 1332 }
1325 1333
1326 // File must be dirty and hence in persistent dir. 1334 // File must be dirty and hence in persistent dir.
1327 DCHECK(cache_entry->IsPersistent()); 1335 DCHECK_EQ(CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type);
1328 1336
1329 // Get the current path of the file in cache. 1337 // Get the current path of the file in cache.
1330 FilePath source_path = GetCacheFilePath(resource_id, 1338 FilePath source_path = GetCacheFilePath(resource_id,
1331 md5, 1339 md5,
1332 cache_entry->GetSubDirectoryType(), 1340 cache_entry->sub_dir_type,
1333 CACHED_FILE_LOCALLY_MODIFIED); 1341 CACHED_FILE_LOCALLY_MODIFIED);
1334 1342
1335 // Determine destination path. 1343 // Determine destination path.
1336 // If file is pinned, move it to persistent dir with .md5 extension; 1344 // If file is pinned, move it to persistent dir with .md5 extension;
1337 // otherwise, move it to tmp dir with .md5 extension. 1345 // otherwise, move it to tmp dir with .md5 extension.
1338 CacheSubDirectoryType sub_dir_type = 1346 CacheSubDirectoryType sub_dir_type =
1339 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1347 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1340 FilePath dest_path = GetCacheFilePath(resource_id, 1348 FilePath dest_path = GetCacheFilePath(resource_id,
1341 md5, 1349 md5,
1342 sub_dir_type, 1350 sub_dir_type,
(...skipping 24 matching lines...) Expand all
1367 *error = ModifyCacheState(dest_path, // source path 1375 *error = ModifyCacheState(dest_path, // source path
1368 dest_path, // destination path 1376 dest_path, // destination path
1369 file_operation_type, 1377 file_operation_type,
1370 symlink_path, 1378 symlink_path,
1371 true /* create symlink */); 1379 true /* create symlink */);
1372 } 1380 }
1373 1381
1374 if (*error == base::PLATFORM_FILE_OK) { 1382 if (*error == base::PLATFORM_FILE_OK) {
1375 // Now that file operations have completed, update cache map. 1383 // Now that file operations have completed, update cache map.
1376 int cache_state = ClearCacheDirty(cache_entry->cache_state); 1384 int cache_state = ClearCacheDirty(cache_entry->cache_state);
1377 UpdateCacheWithSubDirectoryType(resource_id, 1385 metadata_->UpdateCache(resource_id, md5, sub_dir_type, cache_state);
1378 md5,
1379 sub_dir_type,
1380 cache_state);
1381 } 1386 }
1382 } 1387 }
1383 1388
1384 void GDataCache::Remove(const std::string& resource_id, 1389 void GDataCache::Remove(const std::string& resource_id,
1385 base::PlatformFileError* error) { 1390 base::PlatformFileError* error) {
1386 AssertOnSequencedWorkerPool(); 1391 AssertOnSequencedWorkerPool();
1387 DCHECK(error); 1392 DCHECK(error);
1388 1393
1389 // MD5 is not passed into RemoveFromCache and hence 1394 // MD5 is not passed into RemoveFromCache and hence
1390 // RemoveFromCacheOnBlockingPool, because we would delete all cache files 1395 // RemoveFromCacheOnBlockingPool, because we would delete all cache files
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 AssertOnSequencedWorkerPool(); 1510 AssertOnSequencedWorkerPool();
1506 DCHECK(success); 1511 DCHECK(success);
1507 DCHECK(cache_entry); 1512 DCHECK(cache_entry);
1508 1513
1509 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); 1514 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5));
1510 *success = value.get(); 1515 *success = value.get();
1511 if (*success) 1516 if (*success)
1512 *cache_entry = *value; 1517 *cache_entry = *value;
1513 } 1518 }
1514 1519
1515 void GDataCache::UpdateCacheWithSubDirectoryType(
1516 const std::string& resource_id,
1517 const std::string& md5,
1518 CacheSubDirectoryType sub_dir_type,
1519 int cache_state) {
1520 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT ||
1521 sub_dir_type == CACHE_TYPE_TMP);
1522
1523 if (sub_dir_type == CACHE_TYPE_PERSISTENT)
1524 cache_state = SetCachePersistent(cache_state);
1525 else
1526 cache_state = ClearCachePersistent(cache_state);
1527
1528 metadata_->UpdateCache(resource_id, md5, cache_state);
1529 }
1530
1531 // static 1520 // static
1532 FilePath GDataCache::GetCacheRootPath(Profile* profile) { 1521 FilePath GDataCache::GetCacheRootPath(Profile* profile) {
1533 FilePath cache_base_path; 1522 FilePath cache_base_path;
1534 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 1523 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
1535 FilePath cache_root_path = 1524 FilePath cache_root_path =
1536 cache_base_path.Append(chrome::kGDataCacheDirname); 1525 cache_base_path.Append(chrome::kGDataCacheDirname);
1537 return cache_root_path.Append(kGDataCacheVersionDir); 1526 return cache_root_path.Append(kGDataCacheVersionDir);
1538 } 1527 }
1539 1528
1540 // static 1529 // static
(...skipping 30 matching lines...) Expand all
1571 } 1560 }
1572 return success; 1561 return success;
1573 } 1562 }
1574 1563
1575 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1564 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1576 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1565 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1577 global_free_disk_getter_for_testing = getter; 1566 global_free_disk_getter_for_testing = getter;
1578 } 1567 }
1579 1568
1580 } // namespace gdata 1569 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.h ('k') | chrome/browser/chromeos/gdata/gdata_cache_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698