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

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

Issue 10735049: gdata: Take GDataCache::CacheEntry as parameters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish 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 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 UpdateCacheWithSubDirectoryType(resource_id, 883 UpdateCacheWithSubDirectoryType(resource_id,
884 md5,
885 sub_dir_type, 884 sub_dir_type,
886 cache_state); 885 CacheEntry(md5, cache_state));
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 UpdateCacheWithSubDirectoryType(resource_id, 972 UpdateCacheWithSubDirectoryType(resource_id,
974 md5,
975 sub_dir_type, 973 sub_dir_type,
976 cache_state); 974 CacheEntry(md5, cache_state));
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 int cache_state = ClearCachePinned(cache_entry->cache_state); 1052 int cache_state = ClearCachePinned(cache_entry->cache_state);
1055 UpdateCacheWithSubDirectoryType(resource_id, 1053 UpdateCacheWithSubDirectoryType(resource_id,
1056 md5,
1057 sub_dir_type, 1054 sub_dir_type,
1058 cache_state); 1055 CacheEntry(md5, cache_state));
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 dest_subdir = unmounted_subdir; 1110 dest_subdir = unmounted_subdir;
1114 cache_state = ClearCacheMounted(cache_state); 1111 cache_state = ClearCacheMounted(cache_state);
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 UpdateCacheWithSubDirectoryType(resource_id,
1123 md5,
1124 dest_subdir, 1120 dest_subdir,
1125 cache_state); 1121 CacheEntry(md5, cache_state));
1126 } 1122 }
1127 } 1123 }
1128 1124
1129 void GDataCache::MarkDirty(const std::string& resource_id, 1125 void GDataCache::MarkDirty(const std::string& resource_id,
1130 const std::string& md5, 1126 const std::string& md5,
1131 FileOperationType file_operation_type, 1127 FileOperationType file_operation_type,
1132 base::PlatformFileError* error, 1128 base::PlatformFileError* error,
1133 FilePath* cache_file_path) { 1129 FilePath* cache_file_path) {
1134 AssertOnSequencedWorkerPool(); 1130 AssertOnSequencedWorkerPool();
1135 DCHECK(error); 1131 DCHECK(error);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 source_path, 1215 source_path,
1220 *cache_file_path, 1216 *cache_file_path,
1221 file_operation_type, 1217 file_operation_type,
1222 symlink_path, 1218 symlink_path,
1223 !symlink_path.empty() /* create symlink */); 1219 !symlink_path.empty() /* create symlink */);
1224 1220
1225 if (*error == base::PLATFORM_FILE_OK) { 1221 if (*error == base::PLATFORM_FILE_OK) {
1226 // Now that file operations have completed, update cache map. 1222 // Now that file operations have completed, update cache map.
1227 int cache_state = SetCacheDirty(cache_entry->cache_state); 1223 int cache_state = SetCacheDirty(cache_entry->cache_state);
1228 UpdateCacheWithSubDirectoryType(resource_id, 1224 UpdateCacheWithSubDirectoryType(resource_id,
1229 md5,
1230 sub_dir_type, 1225 sub_dir_type,
1231 cache_state); 1226 CacheEntry(md5, cache_state));
1232 } 1227 }
1233 } 1228 }
1234 1229
1235 void GDataCache::CommitDirty(const std::string& resource_id, 1230 void GDataCache::CommitDirty(const std::string& resource_id,
1236 const std::string& md5, 1231 const std::string& md5,
1237 FileOperationType file_operation_type, 1232 FileOperationType file_operation_type,
1238 base::PlatformFileError* error) { 1233 base::PlatformFileError* error) {
1239 AssertOnSequencedWorkerPool(); 1234 AssertOnSequencedWorkerPool();
1240 DCHECK(error); 1235 DCHECK(error);
1241 1236
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 *error = ModifyCacheState(dest_path, // source path 1362 *error = ModifyCacheState(dest_path, // source path
1368 dest_path, // destination path 1363 dest_path, // destination path
1369 file_operation_type, 1364 file_operation_type,
1370 symlink_path, 1365 symlink_path,
1371 true /* create symlink */); 1366 true /* create symlink */);
1372 } 1367 }
1373 1368
1374 if (*error == base::PLATFORM_FILE_OK) { 1369 if (*error == base::PLATFORM_FILE_OK) {
1375 // Now that file operations have completed, update cache map. 1370 // Now that file operations have completed, update cache map.
1376 int cache_state = ClearCacheDirty(cache_entry->cache_state); 1371 int cache_state = ClearCacheDirty(cache_entry->cache_state);
1377 UpdateCacheWithSubDirectoryType(resource_id, 1372 UpdateCacheWithSubDirectoryType(resource_id,
1378 md5,
1379 sub_dir_type, 1373 sub_dir_type,
1380 cache_state); 1374 CacheEntry(md5, cache_state));
1381 } 1375 }
1382 } 1376 }
1383 1377
1384 void GDataCache::Remove(const std::string& resource_id, 1378 void GDataCache::Remove(const std::string& resource_id,
1385 base::PlatformFileError* error) { 1379 base::PlatformFileError* error) {
1386 AssertOnSequencedWorkerPool(); 1380 AssertOnSequencedWorkerPool();
1387 DCHECK(error); 1381 DCHECK(error);
1388 1382
1389 // MD5 is not passed into RemoveFromCache and hence 1383 // MD5 is not passed into RemoveFromCache and hence
1390 // RemoveFromCacheOnBlockingPool, because we would delete all cache files 1384 // RemoveFromCacheOnBlockingPool, because we would delete all cache files
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 DCHECK(cache_entry); 1501 DCHECK(cache_entry);
1508 1502
1509 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); 1503 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5));
1510 *success = value.get(); 1504 *success = value.get();
1511 if (*success) 1505 if (*success)
1512 *cache_entry = *value; 1506 *cache_entry = *value;
1513 } 1507 }
1514 1508
1515 void GDataCache::UpdateCacheWithSubDirectoryType( 1509 void GDataCache::UpdateCacheWithSubDirectoryType(
1516 const std::string& resource_id, 1510 const std::string& resource_id,
1517 const std::string& md5,
1518 CacheSubDirectoryType sub_dir_type, 1511 CacheSubDirectoryType sub_dir_type,
1519 int cache_state) { 1512 const CacheEntry& in_cache_entry) {
1520 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT || 1513 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT ||
1521 sub_dir_type == CACHE_TYPE_TMP); 1514 sub_dir_type == CACHE_TYPE_TMP);
1522 1515
1516 CacheEntry cache_entry = in_cache_entry;
1523 if (sub_dir_type == CACHE_TYPE_PERSISTENT) 1517 if (sub_dir_type == CACHE_TYPE_PERSISTENT)
1524 cache_state = SetCachePersistent(cache_state); 1518 cache_entry.cache_state = SetCachePersistent(cache_entry.cache_state);
1525 else 1519 else
1526 cache_state = ClearCachePersistent(cache_state); 1520 cache_entry.cache_state = ClearCachePersistent(cache_entry.cache_state);
1527 1521
1528 metadata_->UpdateCache(resource_id, md5, cache_state); 1522 metadata_->UpdateCache(resource_id, cache_entry);
1529 } 1523 }
1530 1524
1531 // static 1525 // static
1532 FilePath GDataCache::GetCacheRootPath(Profile* profile) { 1526 FilePath GDataCache::GetCacheRootPath(Profile* profile) {
1533 FilePath cache_base_path; 1527 FilePath cache_base_path;
1534 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 1528 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
1535 FilePath cache_root_path = 1529 FilePath cache_root_path =
1536 cache_base_path.Append(chrome::kGDataCacheDirname); 1530 cache_base_path.Append(chrome::kGDataCacheDirname);
1537 return cache_root_path.Append(kGDataCacheVersionDir); 1531 return cache_root_path.Append(kGDataCacheVersionDir);
1538 } 1532 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 } 1565 }
1572 return success; 1566 return success;
1573 } 1567 }
1574 1568
1575 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1569 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1576 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1570 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1577 global_free_disk_getter_for_testing = getter; 1571 global_free_disk_getter_for_testing = getter;
1578 } 1572 }
1579 1573
1580 } // namespace gdata 1574 } // 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