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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 if (IsPresent()) | 340 if (IsPresent()) |
341 cache_states.push_back("present"); | 341 cache_states.push_back("present"); |
342 if (IsPinned()) | 342 if (IsPinned()) |
343 cache_states.push_back("pinned"); | 343 cache_states.push_back("pinned"); |
344 if (IsDirty()) | 344 if (IsDirty()) |
345 cache_states.push_back("dirty"); | 345 cache_states.push_back("dirty"); |
346 if (IsPersistent()) | 346 if (IsPersistent()) |
347 cache_states.push_back("persistent"); | 347 cache_states.push_back("persistent"); |
348 | 348 |
349 return base::StringPrintf("md5=%s, cache_state=%s", | 349 return base::StringPrintf("md5=%s, cache_state=%s", |
350 md5.c_str(), | 350 md5_.c_str(), |
351 JoinString(cache_states, ',').c_str()); | 351 JoinString(cache_states, ',').c_str()); |
352 } | 352 } |
353 | 353 |
354 GDataCache::GDataCache( | 354 GDataCache::GDataCache( |
355 const FilePath& cache_root_path, | 355 const FilePath& cache_root_path, |
356 base::SequencedWorkerPool* pool, | 356 base::SequencedWorkerPool* pool, |
357 const base::SequencedWorkerPool::SequenceToken& sequence_token) | 357 const base::SequencedWorkerPool::SequenceToken& sequence_token) |
358 : cache_root_path_(cache_root_path), | 358 : cache_root_path_(cache_root_path), |
359 cache_paths_(GetCachePaths(cache_root_path_)), | 359 cache_paths_(GetCachePaths(cache_root_path_)), |
360 pool_(pool), | 360 pool_(pool), |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 // If file is dirty or mounted, return error. | 823 // If file is dirty or mounted, return error. |
824 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 824 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { |
825 LOG(WARNING) << "Can't store a file to replace a " | 825 LOG(WARNING) << "Can't store a file to replace a " |
826 << (cache_entry->IsDirty() ? "dirty" : "mounted") | 826 << (cache_entry->IsDirty() ? "dirty" : "mounted") |
827 << " file: res_id=" << resource_id | 827 << " file: res_id=" << resource_id |
828 << ", md5=" << md5; | 828 << ", md5=" << md5; |
829 *error = base::PLATFORM_FILE_ERROR_IN_USE; | 829 *error = base::PLATFORM_FILE_ERROR_IN_USE; |
830 return; | 830 return; |
831 } | 831 } |
832 | 832 |
833 new_cache_entry.cache_state = cache_entry->cache_state; | 833 new_cache_entry.set_cache_state(cache_entry->cache_state()); |
834 | 834 |
835 // If file is pinned, determines destination path. | 835 // If file is pinned, determines destination path. |
836 if (cache_entry->IsPinned()) { | 836 if (cache_entry->IsPinned()) { |
837 sub_dir_type = CACHE_TYPE_PERSISTENT; | 837 sub_dir_type = CACHE_TYPE_PERSISTENT; |
838 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | 838 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, |
839 CACHED_FILE_FROM_SERVER); | 839 CACHED_FILE_FROM_SERVER); |
840 symlink_path = GetCacheFilePath( | 840 symlink_path = GetCacheFilePath( |
841 resource_id, std::string(), CACHE_TYPE_PINNED, | 841 resource_id, std::string(), CACHE_TYPE_PINNED, |
842 CACHED_FILE_FROM_SERVER); | 842 CACHED_FILE_FROM_SERVER); |
843 } | 843 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 // are the same. | 908 // are the same. |
909 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download | 909 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download |
910 // pinned files that don't exist in cache. | 910 // pinned files that don't exist in cache. |
911 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); | 911 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); |
912 source_path = dest_path; | 912 source_path = dest_path; |
913 | 913 |
914 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', | 914 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', |
915 // then moved to 'persistent'. | 915 // then moved to 'persistent'. |
916 sub_dir_type = CACHE_TYPE_TMP; | 916 sub_dir_type = CACHE_TYPE_TMP; |
917 } else { // File exists in cache, determines destination path. | 917 } else { // File exists in cache, determines destination path. |
918 new_cache_entry.cache_state = cache_entry->cache_state; | 918 new_cache_entry.set_cache_state(cache_entry->cache_state()); |
919 | 919 |
920 // Determine source and destination paths. | 920 // Determine source and destination paths. |
921 | 921 |
922 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 922 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
923 // set |source_path| the same, because ModifyCacheState only moves files if | 923 // set |source_path| the same, because ModifyCacheState only moves files if |
924 // source and destination are different. | 924 // source and destination are different. |
925 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 925 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { |
926 DCHECK(cache_entry->IsPersistent()); | 926 DCHECK(cache_entry->IsPersistent()); |
927 dest_path = GetCacheFilePath(resource_id, | 927 dest_path = GetCacheFilePath(resource_id, |
928 md5, | 928 md5, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CacheEntry new_cache_entry(md5, cache_entry->cache_state); | 1052 CacheEntry new_cache_entry(md5, cache_entry->cache_state()); |
1053 new_cache_entry.SetPinned(false); | 1053 new_cache_entry.SetPinned(false); |
1054 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1054 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
1055 metadata_->UpdateCache(resource_id, new_cache_entry); | 1055 metadata_->UpdateCache(resource_id, new_cache_entry); |
1056 } | 1056 } |
1057 } | 1057 } |
1058 | 1058 |
1059 void GDataCache::SetMountedState(const FilePath& file_path, | 1059 void GDataCache::SetMountedState(const FilePath& file_path, |
1060 bool to_mount, | 1060 bool to_mount, |
1061 base::PlatformFileError *error, | 1061 base::PlatformFileError *error, |
1062 FilePath* cache_file_path) { | 1062 FilePath* cache_file_path) { |
(...skipping 28 matching lines...) Expand all Loading... |
1091 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); | 1091 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); |
1092 | 1092 |
1093 // Get the subdir type and path for the mounted state. | 1093 // Get the subdir type and path for the mounted state. |
1094 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; | 1094 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; |
1095 FilePath mounted_path = GetCacheFilePath( | 1095 FilePath mounted_path = GetCacheFilePath( |
1096 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); | 1096 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); |
1097 | 1097 |
1098 // Determine the source and destination paths for moving the cache blob. | 1098 // Determine the source and destination paths for moving the cache blob. |
1099 FilePath source_path; | 1099 FilePath source_path; |
1100 CacheSubDirectoryType dest_subdir; | 1100 CacheSubDirectoryType dest_subdir; |
1101 CacheEntry new_cache_entry(md5, cache_entry->cache_state); | 1101 CacheEntry new_cache_entry(md5, cache_entry->cache_state()); |
1102 if (to_mount) { | 1102 if (to_mount) { |
1103 source_path = unmounted_path; | 1103 source_path = unmounted_path; |
1104 *cache_file_path = mounted_path; | 1104 *cache_file_path = mounted_path; |
1105 dest_subdir = mounted_subdir; | 1105 dest_subdir = mounted_subdir; |
1106 new_cache_entry.SetMounted(true); | 1106 new_cache_entry.SetMounted(true); |
1107 } else { | 1107 } else { |
1108 source_path = mounted_path; | 1108 source_path = mounted_path; |
1109 *cache_file_path = unmounted_path; | 1109 *cache_file_path = unmounted_path; |
1110 dest_subdir = unmounted_subdir; | 1110 dest_subdir = unmounted_subdir; |
1111 new_cache_entry.SetMounted(false); | 1111 new_cache_entry.SetMounted(false); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1212 |
1213 *error = ModifyCacheState( | 1213 *error = ModifyCacheState( |
1214 source_path, | 1214 source_path, |
1215 *cache_file_path, | 1215 *cache_file_path, |
1216 file_operation_type, | 1216 file_operation_type, |
1217 symlink_path, | 1217 symlink_path, |
1218 !symlink_path.empty() /* create symlink */); | 1218 !symlink_path.empty() /* create symlink */); |
1219 | 1219 |
1220 if (*error == base::PLATFORM_FILE_OK) { | 1220 if (*error == base::PLATFORM_FILE_OK) { |
1221 // Now that file operations have completed, update cache map. | 1221 // Now that file operations have completed, update cache map. |
1222 CacheEntry new_cache_entry(md5, cache_entry->cache_state); | 1222 CacheEntry new_cache_entry(md5, cache_entry->cache_state()); |
1223 new_cache_entry.SetDirty(true); | 1223 new_cache_entry.SetDirty(true); |
1224 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1224 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
1225 metadata_->UpdateCache(resource_id, new_cache_entry); | 1225 metadata_->UpdateCache(resource_id, new_cache_entry); |
1226 } | 1226 } |
1227 } | 1227 } |
1228 | 1228 |
1229 void GDataCache::CommitDirty(const std::string& resource_id, | 1229 void GDataCache::CommitDirty(const std::string& resource_id, |
1230 const std::string& md5, | 1230 const std::string& md5, |
1231 FileOperationType file_operation_type, | 1231 FileOperationType file_operation_type, |
1232 base::PlatformFileError* error) { | 1232 base::PlatformFileError* error) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 // if source and destination are different. | 1360 // if source and destination are different. |
1361 *error = ModifyCacheState(dest_path, // source path | 1361 *error = ModifyCacheState(dest_path, // source path |
1362 dest_path, // destination path | 1362 dest_path, // destination path |
1363 file_operation_type, | 1363 file_operation_type, |
1364 symlink_path, | 1364 symlink_path, |
1365 true /* create symlink */); | 1365 true /* create symlink */); |
1366 } | 1366 } |
1367 | 1367 |
1368 if (*error == base::PLATFORM_FILE_OK) { | 1368 if (*error == base::PLATFORM_FILE_OK) { |
1369 // Now that file operations have completed, update cache map. | 1369 // Now that file operations have completed, update cache map. |
1370 CacheEntry new_cache_entry(md5, cache_entry->cache_state); | 1370 CacheEntry new_cache_entry(md5, cache_entry->cache_state()); |
1371 new_cache_entry.SetDirty(false); | 1371 new_cache_entry.SetDirty(false); |
1372 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); | 1372 new_cache_entry.SetPersistent(sub_dir_type == CACHE_TYPE_PERSISTENT); |
1373 metadata_->UpdateCache(resource_id, new_cache_entry); | 1373 metadata_->UpdateCache(resource_id, new_cache_entry); |
1374 } | 1374 } |
1375 } | 1375 } |
1376 | 1376 |
1377 void GDataCache::Remove(const std::string& resource_id, | 1377 void GDataCache::Remove(const std::string& resource_id, |
1378 base::PlatformFileError* error) { | 1378 base::PlatformFileError* error) { |
1379 AssertOnSequencedWorkerPool(); | 1379 AssertOnSequencedWorkerPool(); |
1380 DCHECK(error); | 1380 DCHECK(error); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 } | 1548 } |
1549 return success; | 1549 return success; |
1550 } | 1550 } |
1551 | 1551 |
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1554 global_free_disk_getter_for_testing = getter; | 1554 global_free_disk_getter_for_testing = getter; |
1555 } | 1555 } |
1556 | 1556 |
1557 } // namespace gdata | 1557 } // namespace gdata |
OLD | NEW |