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

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

Issue 10690154: gdata: Remove a werid behavior from GDataCacheMetadata::UpdateCache() (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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 884 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
885 metadata_->UpdateCache(resource_id, new_cache_entry); 885 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
886 } 886 }
887 } 887 }
888 888
889 void GDataCache::Pin(const std::string& resource_id, 889 void GDataCache::Pin(const std::string& resource_id,
890 const std::string& md5, 890 const std::string& md5,
891 FileOperationType file_operation_type, 891 FileOperationType file_operation_type,
892 base::PlatformFileError* error) { 892 base::PlatformFileError* error) {
893 AssertOnSequencedWorkerPool(); 893 AssertOnSequencedWorkerPool();
894 DCHECK(error); 894 DCHECK(error);
895 895
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 *error = ModifyCacheState(source_path, 964 *error = ModifyCacheState(source_path,
965 dest_path, 965 dest_path,
966 file_operation_type, 966 file_operation_type,
967 symlink_path, 967 symlink_path,
968 create_symlink); 968 create_symlink);
969 969
970 if (*error == base::PLATFORM_FILE_OK) { 970 if (*error == base::PLATFORM_FILE_OK) {
971 // Now that file operations have completed, update cache map. 971 // Now that file operations have completed, update cache map.
972 new_cache_entry.SetPinned(true); 972 new_cache_entry.SetPinned(true);
973 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 973 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
974 metadata_->UpdateCache(resource_id, new_cache_entry); 974 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
975 } 975 }
976 } 976 }
977 977
978 void GDataCache::Unpin(const std::string& resource_id, 978 void GDataCache::Unpin(const std::string& resource_id,
979 const std::string& md5, 979 const std::string& md5,
980 FileOperationType file_operation_type, 980 FileOperationType file_operation_type,
981 base::PlatformFileError* error) { 981 base::PlatformFileError* error) {
982 AssertOnSequencedWorkerPool(); 982 AssertOnSequencedWorkerPool();
983 DCHECK(error); 983 DCHECK(error);
984 984
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1042
1043 *error = ModifyCacheState( 1043 *error = ModifyCacheState(
1044 source_path, 1044 source_path,
1045 dest_path, 1045 dest_path,
1046 file_operation_type, 1046 file_operation_type,
1047 symlink_path, // This will be deleted if it exists. 1047 symlink_path, // This will be deleted if it exists.
1048 false /* don't create symlink*/); 1048 false /* don't create symlink*/);
1049 1049
1050 if (*error == base::PLATFORM_FILE_OK) { 1050 if (*error == base::PLATFORM_FILE_OK) {
1051 // Now that file operations have completed, update cache map. 1051 // Now that file operations have completed, update cache map.
1052 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state()); 1052 if (cache_entry->IsPresent()) {
1053 new_cache_entry.SetPinned(false); 1053 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state());
1054 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1054 new_cache_entry.SetPinned(false);
1055 metadata_->UpdateCache(resource_id, new_cache_entry); 1055 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1056 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
1057 } else {
1058 // Remove the existing entry if we are unpinning a non-present file.
1059 metadata_->RemoveCacheEntry(resource_id);
1060 }
1056 } 1061 }
1057 } 1062 }
1058 1063
1059 void GDataCache::SetMountedState(const FilePath& file_path, 1064 void GDataCache::SetMountedState(const FilePath& file_path,
1060 bool to_mount, 1065 bool to_mount,
1061 base::PlatformFileError *error, 1066 base::PlatformFileError *error,
1062 FilePath* cache_file_path) { 1067 FilePath* cache_file_path) {
1063 AssertOnSequencedWorkerPool(); 1068 AssertOnSequencedWorkerPool();
1064 DCHECK(error); 1069 DCHECK(error);
1065 DCHECK(cache_file_path); 1070 DCHECK(cache_file_path);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 dest_subdir = unmounted_subdir; 1115 dest_subdir = unmounted_subdir;
1111 new_cache_entry.SetMounted(false); 1116 new_cache_entry.SetMounted(false);
1112 } 1117 }
1113 1118
1114 // Move cache blob from source path to destination path. 1119 // Move cache blob from source path to destination path.
1115 *error = ModifyCacheState(source_path, *cache_file_path, 1120 *error = ModifyCacheState(source_path, *cache_file_path,
1116 FILE_OPERATION_MOVE, FilePath(), false); 1121 FILE_OPERATION_MOVE, FilePath(), false);
1117 if (*error == base::PLATFORM_FILE_OK) { 1122 if (*error == base::PLATFORM_FILE_OK) {
1118 // Now that cache operation is complete, update cache map 1123 // Now that cache operation is complete, update cache map
1119 new_cache_entry.SetPersistent(dest_subdir == CACHE_TYPE_PERSISTENT); 1124 new_cache_entry.SetPersistent(dest_subdir == CACHE_TYPE_PERSISTENT);
1120 metadata_->UpdateCache(resource_id, new_cache_entry); 1125 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
1121 } 1126 }
1122 } 1127 }
1123 1128
1124 void GDataCache::MarkDirty(const std::string& resource_id, 1129 void GDataCache::MarkDirty(const std::string& resource_id,
1125 const std::string& md5, 1130 const std::string& md5,
1126 FileOperationType file_operation_type, 1131 FileOperationType file_operation_type,
1127 base::PlatformFileError* error, 1132 base::PlatformFileError* error,
1128 FilePath* cache_file_path) { 1133 FilePath* cache_file_path) {
1129 AssertOnSequencedWorkerPool(); 1134 AssertOnSequencedWorkerPool();
1130 DCHECK(error); 1135 DCHECK(error);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 *cache_file_path, 1220 *cache_file_path,
1216 file_operation_type, 1221 file_operation_type,
1217 symlink_path, 1222 symlink_path,
1218 !symlink_path.empty() /* create symlink */); 1223 !symlink_path.empty() /* create symlink */);
1219 1224
1220 if (*error == base::PLATFORM_FILE_OK) { 1225 if (*error == base::PLATFORM_FILE_OK) {
1221 // Now that file operations have completed, update cache map. 1226 // Now that file operations have completed, update cache map.
1222 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state()); 1227 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state());
1223 new_cache_entry.SetDirty(true); 1228 new_cache_entry.SetDirty(true);
1224 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1229 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1225 metadata_->UpdateCache(resource_id, new_cache_entry); 1230 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
1226 } 1231 }
1227 } 1232 }
1228 1233
1229 void GDataCache::CommitDirty(const std::string& resource_id, 1234 void GDataCache::CommitDirty(const std::string& resource_id,
1230 const std::string& md5, 1235 const std::string& md5,
1231 FileOperationType file_operation_type, 1236 FileOperationType file_operation_type,
1232 base::PlatformFileError* error) { 1237 base::PlatformFileError* error) {
1233 AssertOnSequencedWorkerPool(); 1238 AssertOnSequencedWorkerPool();
1234 DCHECK(error); 1239 DCHECK(error);
1235 1240
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 file_operation_type, 1368 file_operation_type,
1364 symlink_path, 1369 symlink_path,
1365 true /* create symlink */); 1370 true /* create symlink */);
1366 } 1371 }
1367 1372
1368 if (*error == base::PLATFORM_FILE_OK) { 1373 if (*error == base::PLATFORM_FILE_OK) {
1369 // Now that file operations have completed, update cache map. 1374 // Now that file operations have completed, update cache map.
1370 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state()); 1375 GDataCacheEntry new_cache_entry(md5, cache_entry->cache_state());
1371 new_cache_entry.SetDirty(false); 1376 new_cache_entry.SetDirty(false);
1372 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); 1377 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT);
1373 metadata_->UpdateCache(resource_id, new_cache_entry); 1378 metadata_->AddOrUpdateCacheEntry(resource_id, new_cache_entry);
1374 } 1379 }
1375 } 1380 }
1376 1381
1377 void GDataCache::Remove(const std::string& resource_id, 1382 void GDataCache::Remove(const std::string& resource_id,
1378 base::PlatformFileError* error) { 1383 base::PlatformFileError* error) {
1379 AssertOnSequencedWorkerPool(); 1384 AssertOnSequencedWorkerPool();
1380 DCHECK(error); 1385 DCHECK(error);
1381 1386
1382 // MD5 is not passed into RemoveFromCache and hence 1387 // MD5 is not passed into RemoveCacheEntry because we would delete all
1383 // RemoveFromCacheOnBlockingPool, because we would delete all cache files 1388 // cache files corresponding to <resource_id> regardless of the md5.
1384 // corresponding to <resource_id> regardless of the md5.
1385 // So, search for entry in cache without taking md5 into account. 1389 // So, search for entry in cache without taking md5 into account.
1386 scoped_ptr<GDataCacheEntry> cache_entry = 1390 scoped_ptr<GDataCacheEntry> cache_entry =
1387 GetCacheEntry(resource_id, std::string()); 1391 GetCacheEntry(resource_id, std::string());
1388 1392
1389 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. 1393 // If entry doesn't exist or is dirty or mounted in cache, nothing to do.
1390 if (!cache_entry.get() || 1394 if (!cache_entry.get() ||
1391 cache_entry->IsDirty() || 1395 cache_entry->IsDirty() ||
1392 cache_entry->IsMounted()) { 1396 cache_entry->IsMounted()) {
1393 DVLOG(1) << "Entry is " 1397 DVLOG(1) << "Entry is "
1394 << (cache_entry.get() ? 1398 << (cache_entry.get() ?
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 FilePath path_to_keep = GetCacheFilePath(resource_id, 1431 FilePath path_to_keep = GetCacheFilePath(resource_id,
1428 std::string(), 1432 std::string(),
1429 CACHE_TYPE_PERSISTENT, 1433 CACHE_TYPE_PERSISTENT,
1430 CACHED_FILE_LOCALLY_MODIFIED); 1434 CACHED_FILE_LOCALLY_MODIFIED);
1431 1435
1432 for (size_t i = 0; i < paths_to_delete.size(); ++i) { 1436 for (size_t i = 0; i < paths_to_delete.size(); ++i) {
1433 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); 1437 DeleteFilesSelectively(paths_to_delete[i], path_to_keep);
1434 } 1438 }
1435 1439
1436 // Now that all file operations have completed, remove from cache map. 1440 // Now that all file operations have completed, remove from cache map.
1437 metadata_->RemoveFromCache(resource_id); 1441 metadata_->RemoveCacheEntry(resource_id);
1438 1442
1439 *error = base::PLATFORM_FILE_OK; 1443 *error = base::PLATFORM_FILE_OK;
1440 } 1444 }
1441 1445
1442 void GDataCache::OnPinned(base::PlatformFileError* error, 1446 void GDataCache::OnPinned(base::PlatformFileError* error,
1443 const std::string& resource_id, 1447 const std::string& resource_id,
1444 const std::string& md5, 1448 const std::string& md5,
1445 const CacheOperationCallback& callback) { 1449 const CacheOperationCallback& callback) {
1446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1447 DCHECK(error); 1451 DCHECK(error);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 const GDataCacheEntry& cache_entry) { 1558 const GDataCacheEntry& cache_entry) {
1555 return cache_entry.IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1559 return cache_entry.IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1556 } 1560 }
1557 1561
1558 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1562 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1559 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1563 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1560 global_free_disk_getter_for_testing = getter; 1564 global_free_disk_getter_for_testing = getter;
1561 } 1565 }
1562 1566
1563 } // namespace gdata 1567 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698