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

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

Issue 10692171: gdata: Remove GDataCache::UpdateCacheWithSubDirectoryType() (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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 // extension separator '.'. 874 // extension separator '.'.
875 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard); 875 stale_filenames_pattern = dest_path.ReplaceExtension(util::kWildCard);
876 } 876 }
877 877
878 // Delete files that match |stale_filenames_pattern| except for |dest_path|. 878 // Delete files that match |stale_filenames_pattern| except for |dest_path|.
879 DeleteFilesSelectively(stale_filenames_pattern, dest_path); 879 DeleteFilesSelectively(stale_filenames_pattern, dest_path);
880 880
881 if (*error == base::PLATFORM_FILE_OK) { 881 if (*error == base::PLATFORM_FILE_OK) {
882 // Now that file operations have completed, update cache map. 882 // Now that file operations have completed, update cache map.
883 new_cache_entry.SetPresent(true); 883 new_cache_entry.SetPresent(true);
884 UpdateCacheWithSubDirectoryType(resource_id, 884 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
885 sub_dir_type, 885 metadata_->UpdateCache(resource_id, new_cache_entry);
886 new_cache_entry);
887 } 886 }
888 } 887 }
889 888
890 void GDataCache::Pin(const std::string& resource_id, 889 void GDataCache::Pin(const std::string& resource_id,
891 const std::string& md5, 890 const std::string& md5,
892 FileOperationType file_operation_type, 891 FileOperationType file_operation_type,
893 base::PlatformFileError* error) { 892 base::PlatformFileError* error) {
894 AssertOnSequencedWorkerPool(); 893 AssertOnSequencedWorkerPool();
895 DCHECK(error); 894 DCHECK(error);
896 895
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 963
965 *error = ModifyCacheState(source_path, 964 *error = ModifyCacheState(source_path,
966 dest_path, 965 dest_path,
967 file_operation_type, 966 file_operation_type,
968 symlink_path, 967 symlink_path,
969 create_symlink); 968 create_symlink);
970 969
971 if (*error == base::PLATFORM_FILE_OK) { 970 if (*error == base::PLATFORM_FILE_OK) {
972 // Now that file operations have completed, update cache map. 971 // Now that file operations have completed, update cache map.
973 new_cache_entry.SetPinned(true); 972 new_cache_entry.SetPinned(true);
974 UpdateCacheWithSubDirectoryType(resource_id, 973 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
975 sub_dir_type, 974 metadata_->UpdateCache(resource_id, new_cache_entry);
976 new_cache_entry);
977 } 975 }
978 } 976 }
979 977
980 void GDataCache::Unpin(const std::string& resource_id, 978 void GDataCache::Unpin(const std::string& resource_id,
981 const std::string& md5, 979 const std::string& md5,
982 FileOperationType file_operation_type, 980 FileOperationType file_operation_type,
983 base::PlatformFileError* error) { 981 base::PlatformFileError* error) {
984 AssertOnSequencedWorkerPool(); 982 AssertOnSequencedWorkerPool();
985 DCHECK(error); 983 DCHECK(error);
986 984
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 source_path, 1044 source_path,
1047 dest_path, 1045 dest_path,
1048 file_operation_type, 1046 file_operation_type,
1049 symlink_path, // This will be deleted if it exists. 1047 symlink_path, // This will be deleted if it exists.
1050 false /* don't create symlink*/); 1048 false /* don't create symlink*/);
1051 1049
1052 if (*error == base::PLATFORM_FILE_OK) { 1050 if (*error == base::PLATFORM_FILE_OK) {
1053 // Now that file operations have completed, update cache map. 1051 // Now that file operations have completed, update cache map.
1054 CacheEntry new_cache_entry(md5, cache_entry->cache_state); 1052 CacheEntry new_cache_entry(md5, cache_entry->cache_state);
1055 new_cache_entry.SetPinned(false); 1053 new_cache_entry.SetPinned(false);
1056 UpdateCacheWithSubDirectoryType(resource_id, 1054 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1057 sub_dir_type, 1055 metadata_->UpdateCache(resource_id, new_cache_entry);
1058 new_cache_entry);
1059 } 1056 }
1060 } 1057 }
1061 1058
1062 void GDataCache::SetMountedState(const FilePath& file_path, 1059 void GDataCache::SetMountedState(const FilePath& file_path,
1063 bool to_mount, 1060 bool to_mount,
1064 base::PlatformFileError *error, 1061 base::PlatformFileError *error,
1065 FilePath* cache_file_path) { 1062 FilePath* cache_file_path) {
1066 AssertOnSequencedWorkerPool(); 1063 AssertOnSequencedWorkerPool();
1067 DCHECK(error); 1064 DCHECK(error);
1068 DCHECK(cache_file_path); 1065 DCHECK(cache_file_path);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 *cache_file_path = unmounted_path; 1109 *cache_file_path = unmounted_path;
1113 dest_subdir = unmounted_subdir; 1110 dest_subdir = unmounted_subdir;
1114 new_cache_entry.SetMounted(false); 1111 new_cache_entry.SetMounted(false);
1115 } 1112 }
1116 1113
1117 // Move cache blob from source path to destination path. 1114 // Move cache blob from source path to destination path.
1118 *error = ModifyCacheState(source_path, *cache_file_path, 1115 *error = ModifyCacheState(source_path, *cache_file_path,
1119 FILE_OPERATION_MOVE, FilePath(), false); 1116 FILE_OPERATION_MOVE, FilePath(), false);
1120 if (*error == base::PLATFORM_FILE_OK) { 1117 if (*error == base::PLATFORM_FILE_OK) {
1121 // Now that cache operation is complete, update cache map 1118 // Now that cache operation is complete, update cache map
1122 UpdateCacheWithSubDirectoryType(resource_id, 1119 new_cache_entry.SetPersistent(dest_subdir == CACHE_TYPE_PERSISTENT);
1123 dest_subdir, 1120 metadata_->UpdateCache(resource_id, new_cache_entry);
1124 new_cache_entry);
1125 } 1121 }
1126 } 1122 }
1127 1123
1128 void GDataCache::MarkDirty(const std::string& resource_id, 1124 void GDataCache::MarkDirty(const std::string& resource_id,
1129 const std::string& md5, 1125 const std::string& md5,
1130 FileOperationType file_operation_type, 1126 FileOperationType file_operation_type,
1131 base::PlatformFileError* error, 1127 base::PlatformFileError* error,
1132 FilePath* cache_file_path) { 1128 FilePath* cache_file_path) {
1133 AssertOnSequencedWorkerPool(); 1129 AssertOnSequencedWorkerPool();
1134 DCHECK(error); 1130 DCHECK(error);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 // Move file to persistent dir with new .local extension. 1188 // Move file to persistent dir with new .local extension.
1193 1189
1194 // Get the current path of the file in cache. 1190 // Get the current path of the file in cache.
1195 FilePath source_path = GetCacheFilePath( 1191 FilePath source_path = GetCacheFilePath(
1196 resource_id, 1192 resource_id,
1197 md5, 1193 md5,
1198 cache_entry->GetSubDirectoryType(), 1194 cache_entry->GetSubDirectoryType(),
1199 CACHED_FILE_FROM_SERVER); 1195 CACHED_FILE_FROM_SERVER);
1200 1196
1201 // Determine destination path. 1197 // Determine destination path.
1202 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; 1198 const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT;
1203 *cache_file_path = GetCacheFilePath(resource_id, 1199 *cache_file_path = GetCacheFilePath(resource_id,
1204 md5, 1200 md5,
1205 sub_dir_type, 1201 sub_dir_type,
1206 CACHED_FILE_LOCALLY_MODIFIED); 1202 CACHED_FILE_LOCALLY_MODIFIED);
1207 1203
1208 // If file is pinned, update symlink in pinned dir. 1204 // If file is pinned, update symlink in pinned dir.
1209 FilePath symlink_path; 1205 FilePath symlink_path;
1210 if (cache_entry->IsPinned()) { 1206 if (cache_entry->IsPinned()) {
1211 symlink_path = GetCacheFilePath(resource_id, 1207 symlink_path = GetCacheFilePath(resource_id,
1212 std::string(), 1208 std::string(),
1213 CACHE_TYPE_PINNED, 1209 CACHE_TYPE_PINNED,
1214 CACHED_FILE_FROM_SERVER); 1210 CACHED_FILE_FROM_SERVER);
1215 } 1211 }
1216 1212
1217 *error = ModifyCacheState( 1213 *error = ModifyCacheState(
1218 source_path, 1214 source_path,
1219 *cache_file_path, 1215 *cache_file_path,
1220 file_operation_type, 1216 file_operation_type,
1221 symlink_path, 1217 symlink_path,
1222 !symlink_path.empty() /* create symlink */); 1218 !symlink_path.empty() /* create symlink */);
1223 1219
1224 if (*error == base::PLATFORM_FILE_OK) { 1220 if (*error == base::PLATFORM_FILE_OK) {
1225 // Now that file operations have completed, update cache map. 1221 // Now that file operations have completed, update cache map.
1226 CacheEntry new_cache_entry(md5, cache_entry->cache_state); 1222 CacheEntry new_cache_entry(md5, cache_entry->cache_state);
1227 new_cache_entry.SetDirty(true); 1223 new_cache_entry.SetDirty(true);
1228 UpdateCacheWithSubDirectoryType(resource_id, 1224 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1229 sub_dir_type, 1225 metadata_->UpdateCache(resource_id, new_cache_entry);
1230 new_cache_entry);
1231 } 1226 }
1232 } 1227 }
1233 1228
1234 void GDataCache::CommitDirty(const std::string& resource_id, 1229 void GDataCache::CommitDirty(const std::string& resource_id,
1235 const std::string& md5, 1230 const std::string& md5,
1236 FileOperationType file_operation_type, 1231 FileOperationType file_operation_type,
1237 base::PlatformFileError* error) { 1232 base::PlatformFileError* error) {
1238 AssertOnSequencedWorkerPool(); 1233 AssertOnSequencedWorkerPool();
1239 DCHECK(error); 1234 DCHECK(error);
1240 1235
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1322
1328 // Get the current path of the file in cache. 1323 // Get the current path of the file in cache.
1329 FilePath source_path = GetCacheFilePath(resource_id, 1324 FilePath source_path = GetCacheFilePath(resource_id,
1330 md5, 1325 md5,
1331 cache_entry->GetSubDirectoryType(), 1326 cache_entry->GetSubDirectoryType(),
1332 CACHED_FILE_LOCALLY_MODIFIED); 1327 CACHED_FILE_LOCALLY_MODIFIED);
1333 1328
1334 // Determine destination path. 1329 // Determine destination path.
1335 // If file is pinned, move it to persistent dir with .md5 extension; 1330 // If file is pinned, move it to persistent dir with .md5 extension;
1336 // otherwise, move it to tmp dir with .md5 extension. 1331 // otherwise, move it to tmp dir with .md5 extension.
1337 CacheSubDirectoryType sub_dir_type = 1332 const CacheSubDirectoryType sub_dir_type =
1338 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1333 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1339 FilePath dest_path = GetCacheFilePath(resource_id, 1334 FilePath dest_path = GetCacheFilePath(resource_id,
1340 md5, 1335 md5,
1341 sub_dir_type, 1336 sub_dir_type,
1342 CACHED_FILE_FROM_SERVER); 1337 CACHED_FILE_FROM_SERVER);
1343 1338
1344 // Delete symlink in outgoing dir. 1339 // Delete symlink in outgoing dir.
1345 FilePath symlink_path = GetCacheFilePath(resource_id, 1340 FilePath symlink_path = GetCacheFilePath(resource_id,
1346 std::string(), 1341 std::string(),
1347 CACHE_TYPE_OUTGOING, 1342 CACHE_TYPE_OUTGOING,
(...skipping 19 matching lines...) Expand all
1367 dest_path, // destination path 1362 dest_path, // destination path
1368 file_operation_type, 1363 file_operation_type,
1369 symlink_path, 1364 symlink_path,
1370 true /* create symlink */); 1365 true /* create symlink */);
1371 } 1366 }
1372 1367
1373 if (*error == base::PLATFORM_FILE_OK) { 1368 if (*error == base::PLATFORM_FILE_OK) {
1374 // Now that file operations have completed, update cache map. 1369 // Now that file operations have completed, update cache map.
1375 CacheEntry new_cache_entry(md5, cache_entry->cache_state); 1370 CacheEntry new_cache_entry(md5, cache_entry->cache_state);
1376 new_cache_entry.SetDirty(false); 1371 new_cache_entry.SetDirty(false);
1377 UpdateCacheWithSubDirectoryType(resource_id, 1372 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1378 sub_dir_type, 1373 metadata_->UpdateCache(resource_id, new_cache_entry);
1379 new_cache_entry);
1380 } 1374 }
1381 } 1375 }
1382 1376
1383 void GDataCache::Remove(const std::string& resource_id, 1377 void GDataCache::Remove(const std::string& resource_id,
1384 base::PlatformFileError* error) { 1378 base::PlatformFileError* error) {
1385 AssertOnSequencedWorkerPool(); 1379 AssertOnSequencedWorkerPool();
1386 DCHECK(error); 1380 DCHECK(error);
1387 1381
1388 // MD5 is not passed into RemoveFromCache and hence 1382 // MD5 is not passed into RemoveFromCache and hence
1389 // RemoveFromCacheOnBlockingPool, because we would delete all cache files 1383 // RemoveFromCacheOnBlockingPool, because we would delete all cache files
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 AssertOnSequencedWorkerPool(); 1498 AssertOnSequencedWorkerPool();
1505 DCHECK(success); 1499 DCHECK(success);
1506 DCHECK(cache_entry); 1500 DCHECK(cache_entry);
1507 1501
1508 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); 1502 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5));
1509 *success = value.get(); 1503 *success = value.get();
1510 if (*success) 1504 if (*success)
1511 *cache_entry = *value; 1505 *cache_entry = *value;
1512 } 1506 }
1513 1507
1514 void GDataCache::UpdateCacheWithSubDirectoryType(
1515 const std::string& resource_id,
1516 CacheSubDirectoryType sub_dir_type,
1517 const CacheEntry& in_cache_entry) {
1518 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT ||
1519 sub_dir_type == CACHE_TYPE_TMP);
1520
1521 CacheEntry cache_entry = in_cache_entry;
1522 cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1523
1524 metadata_->UpdateCache(resource_id, cache_entry);
1525 }
1526
1527 // static 1508 // static
1528 FilePath GDataCache::GetCacheRootPath(Profile* profile) { 1509 FilePath GDataCache::GetCacheRootPath(Profile* profile) {
1529 FilePath cache_base_path; 1510 FilePath cache_base_path;
1530 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 1511 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
1531 FilePath cache_root_path = 1512 FilePath cache_root_path =
1532 cache_base_path.Append(chrome::kGDataCacheDirname); 1513 cache_base_path.Append(chrome::kGDataCacheDirname);
1533 return cache_root_path.Append(kGDataCacheVersionDir); 1514 return cache_root_path.Append(kGDataCacheVersionDir);
1534 } 1515 }
1535 1516
1536 // static 1517 // static
(...skipping 30 matching lines...) Expand all
1567 } 1548 }
1568 return success; 1549 return success;
1569 } 1550 }
1570 1551
1571 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1572 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1573 global_free_disk_getter_for_testing = getter; 1554 global_free_disk_getter_for_testing = getter;
1574 } 1555 }
1575 1556
1576 } // namespace gdata 1557 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698