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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 DVLOG(1) << "Deleted " << current.value(); | 224 DVLOG(1) << "Deleted " << current.value(); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 // Appends |resource_id| ID to |to_fetch| if the file is pinned but not | 228 // Appends |resource_id| ID to |to_fetch| if the file is pinned but not |
229 // fetched (not present locally), or to |to_upload| if the file is dirty | 229 // fetched (not present locally), or to |to_upload| if the file is dirty |
230 // but not uploaded. | 230 // but not uploaded. |
231 void CollectBacklog(std::vector<std::string>* to_fetch, | 231 void CollectBacklog(std::vector<std::string>* to_fetch, |
232 std::vector<std::string>* to_upload, | 232 std::vector<std::string>* to_upload, |
233 const std::string& resource_id, | 233 const std::string& resource_id, |
234 const GDataCache::CacheEntry& cache_entry) { | 234 const GDataCacheEntry& cache_entry) { |
235 DCHECK(to_fetch); | 235 DCHECK(to_fetch); |
236 DCHECK(to_upload); | 236 DCHECK(to_upload); |
237 | 237 |
238 if (cache_entry.IsPinned() && !cache_entry.IsPresent()) | 238 if (cache_entry.IsPinned() && !cache_entry.IsPresent()) |
239 to_fetch->push_back(resource_id); | 239 to_fetch->push_back(resource_id); |
240 | 240 |
241 if (cache_entry.IsDirty()) | 241 if (cache_entry.IsDirty()) |
242 to_upload->push_back(resource_id); | 242 to_upload->push_back(resource_id); |
243 } | 243 } |
244 | 244 |
245 // Appends |resource_id| ID to |resource_ids| if the file is pinned and | 245 // Appends |resource_id| ID to |resource_ids| if the file is pinned and |
246 // present (cached locally). | 246 // present (cached locally). |
247 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids, | 247 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids, |
248 const std::string& resource_id, | 248 const std::string& resource_id, |
249 const GDataCache::CacheEntry& cache_entry) { | 249 const GDataCacheEntry& cache_entry) { |
250 DCHECK(resource_ids); | 250 DCHECK(resource_ids); |
251 | 251 |
252 if (cache_entry.IsPinned() && cache_entry.IsPresent()) | 252 if (cache_entry.IsPinned() && cache_entry.IsPresent()) |
253 resource_ids->push_back(resource_id); | 253 resource_ids->push_back(resource_id); |
254 } | 254 } |
255 | 255 |
256 // Runs callback with pointers dereferenced. | 256 // Runs callback with pointers dereferenced. |
257 // Used to implement SetMountedStateOnUIThread. | 257 // Used to implement SetMountedStateOnUIThread. |
258 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, | 258 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, |
259 base::PlatformFileError* error, | 259 base::PlatformFileError* error, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
317 DCHECK(resource_ids); | 317 DCHECK(resource_ids); |
318 | 318 |
319 if (!callback.is_null()) | 319 if (!callback.is_null()) |
320 callback.Run(*resource_ids); | 320 callback.Run(*resource_ids); |
321 } | 321 } |
322 | 322 |
323 // Runs callback with pointers dereferenced. | 323 // Runs callback with pointers dereferenced. |
324 // Used to implement GetCacheEntryOnUIThread(). | 324 // Used to implement GetCacheEntryOnUIThread(). |
325 void RunGetCacheEntryCallback( | 325 void RunGetCacheEntryCallback( |
326 const GDataCache::GetCacheEntryCallback& callback, | 326 const GetCacheEntryCallback& callback, |
327 bool* success, | 327 bool* success, |
328 GDataCache::CacheEntry* cache_entry) { | 328 GDataCacheEntry* cache_entry) { |
329 DCHECK(success); | 329 DCHECK(success); |
330 DCHECK(cache_entry); | 330 DCHECK(cache_entry); |
331 | 331 |
332 if (!callback.is_null()) | 332 if (!callback.is_null()) |
333 callback.Run(*success, *cache_entry); | 333 callback.Run(*success, *cache_entry); |
334 } | 334 } |
335 | 335 |
336 } // namespace | 336 } // namespace |
337 | 337 |
338 std::string GDataCache::CacheEntry::ToString() const { | 338 std::string GDataCacheEntry::ToString() const { |
339 std::vector<std::string> cache_states; | 339 std::vector<std::string> cache_states; |
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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 observers_.RemoveObserver(observer); | 421 observers_.RemoveObserver(observer); |
422 } | 422 } |
423 | 423 |
424 void GDataCache::GetCacheEntryOnUIThread( | 424 void GDataCache::GetCacheEntryOnUIThread( |
425 const std::string& resource_id, | 425 const std::string& resource_id, |
426 const std::string& md5, | 426 const std::string& md5, |
427 const GetCacheEntryCallback& callback) { | 427 const GetCacheEntryCallback& callback) { |
428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
429 | 429 |
430 bool* success = new bool(false); | 430 bool* success = new bool(false); |
431 GDataCache::CacheEntry* cache_entry = new GDataCache::CacheEntry; | 431 GDataCacheEntry* cache_entry = new GDataCacheEntry; |
432 pool_->GetSequencedTaskRunner(sequence_token_)->PostTaskAndReply( | 432 pool_->GetSequencedTaskRunner(sequence_token_)->PostTaskAndReply( |
433 FROM_HERE, | 433 FROM_HERE, |
434 base::Bind(&GDataCache::GetCacheEntryHelper, | 434 base::Bind(&GDataCache::GetCacheEntryHelper, |
435 base::Unretained(this), | 435 base::Unretained(this), |
436 resource_id, | 436 resource_id, |
437 md5, | 437 md5, |
438 success, | 438 success, |
439 cache_entry), | 439 cache_entry), |
440 base::Bind(&RunGetCacheEntryCallback, | 440 base::Bind(&RunGetCacheEntryCallback, |
441 callback, | 441 callback, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } | 704 } |
705 | 705 |
706 void GDataCache::RequestInitializeOnUIThread() { | 706 void GDataCache::RequestInitializeOnUIThread() { |
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
708 | 708 |
709 pool_->GetSequencedTaskRunner(sequence_token_)->PostTask( | 709 pool_->GetSequencedTaskRunner(sequence_token_)->PostTask( |
710 FROM_HERE, | 710 FROM_HERE, |
711 base::Bind(&GDataCache::Initialize, base::Unretained(this))); | 711 base::Bind(&GDataCache::Initialize, base::Unretained(this))); |
712 } | 712 } |
713 | 713 |
714 scoped_ptr<GDataCache::CacheEntry> GDataCache::GetCacheEntry( | 714 scoped_ptr<GDataCacheEntry> GDataCache::GetCacheEntry( |
715 const std::string& resource_id, | 715 const std::string& resource_id, |
716 const std::string& md5) { | 716 const std::string& md5) { |
717 AssertOnSequencedWorkerPool(); | 717 AssertOnSequencedWorkerPool(); |
718 return metadata_->GetCacheEntry(resource_id, md5); | 718 return metadata_->GetCacheEntry(resource_id, md5); |
719 } | 719 } |
720 | 720 |
721 // static | 721 // static |
722 GDataCache* GDataCache::CreateGDataCacheOnUIThread( | 722 GDataCache* GDataCache::CreateGDataCacheOnUIThread( |
723 const FilePath& cache_root_path, | 723 const FilePath& cache_root_path, |
724 base::SequencedWorkerPool* pool, | 724 base::SequencedWorkerPool* pool, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 } | 773 } |
774 | 774 |
775 void GDataCache::GetFile(const std::string& resource_id, | 775 void GDataCache::GetFile(const std::string& resource_id, |
776 const std::string& md5, | 776 const std::string& md5, |
777 base::PlatformFileError* error, | 777 base::PlatformFileError* error, |
778 FilePath* cache_file_path) { | 778 FilePath* cache_file_path) { |
779 AssertOnSequencedWorkerPool(); | 779 AssertOnSequencedWorkerPool(); |
780 DCHECK(error); | 780 DCHECK(error); |
781 DCHECK(cache_file_path); | 781 DCHECK(cache_file_path); |
782 | 782 |
783 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 783 scoped_ptr<GDataCacheEntry> cache_entry = GetCacheEntry( |
784 resource_id, md5); | 784 resource_id, md5); |
785 if (cache_entry.get() && cache_entry->IsPresent()) { | 785 if (cache_entry.get() && cache_entry->IsPresent()) { |
786 CachedFileOrigin file_origin; | 786 CachedFileOrigin file_origin; |
787 if (cache_entry->IsMounted()) { | 787 if (cache_entry->IsMounted()) { |
788 file_origin = CACHED_FILE_MOUNTED; | 788 file_origin = CACHED_FILE_MOUNTED; |
789 } else if (cache_entry->IsDirty()) { | 789 } else if (cache_entry->IsDirty()) { |
790 file_origin = CACHED_FILE_LOCALLY_MODIFIED; | 790 file_origin = CACHED_FILE_LOCALLY_MODIFIED; |
791 } else { | 791 } else { |
792 file_origin = CACHED_FILE_FROM_SERVER; | 792 file_origin = CACHED_FILE_FROM_SERVER; |
793 } | 793 } |
794 *cache_file_path = GetCacheFilePath( | 794 *cache_file_path = GetCacheFilePath( |
795 resource_id, | 795 resource_id, |
796 md5, | 796 md5, |
797 cache_entry->GetSubDirectoryType(), | 797 GetSubDirectoryType(*cache_entry), |
798 file_origin); | 798 file_origin); |
799 *error = base::PLATFORM_FILE_OK; | 799 *error = base::PLATFORM_FILE_OK; |
800 } else { | 800 } else { |
801 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 801 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
802 } | 802 } |
803 } | 803 } |
804 | 804 |
805 void GDataCache::Store(const std::string& resource_id, | 805 void GDataCache::Store(const std::string& resource_id, |
806 const std::string& md5, | 806 const std::string& md5, |
807 const FilePath& source_path, | 807 const FilePath& source_path, |
808 FileOperationType file_operation_type, | 808 FileOperationType file_operation_type, |
809 base::PlatformFileError* error) { | 809 base::PlatformFileError* error) { |
810 AssertOnSequencedWorkerPool(); | 810 AssertOnSequencedWorkerPool(); |
811 DCHECK(error); | 811 DCHECK(error); |
812 | 812 |
813 FilePath dest_path; | 813 FilePath dest_path; |
814 FilePath symlink_path; | 814 FilePath symlink_path; |
815 CacheEntry new_cache_entry(md5, CACHE_STATE_NONE); | 815 GDataCacheEntry new_cache_entry(md5, CACHE_STATE_NONE); |
816 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 816 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
817 | 817 |
818 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 818 scoped_ptr<GDataCacheEntry> cache_entry = GetCacheEntry(resource_id, md5); |
819 | 819 |
820 // If file was previously pinned, store it in persistent dir and create | 820 // If file was previously pinned, store it in persistent dir and create |
821 // symlink in pinned dir. | 821 // symlink in pinned dir. |
822 if (cache_entry.get()) { // File exists in cache. | 822 if (cache_entry.get()) { // File exists in cache. |
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; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
896 FilePath source_path; | 896 FilePath source_path; |
897 FilePath dest_path; | 897 FilePath dest_path; |
898 FilePath symlink_path; | 898 FilePath symlink_path; |
899 bool create_symlink = true; | 899 bool create_symlink = true; |
900 CacheEntry new_cache_entry(md5, CACHE_STATE_NONE); | 900 GDataCacheEntry new_cache_entry(md5, CACHE_STATE_NONE); |
901 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 901 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
902 | 902 |
903 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 903 scoped_ptr<GDataCacheEntry> cache_entry = GetCacheEntry(resource_id, md5); |
904 | 904 |
905 if (!cache_entry.get()) { // Entry does not exist in cache. | 905 if (!cache_entry.get()) { // Entry does not exist in cache. |
906 // Set both |dest_path| and |source_path| to /dev/null, so that: | 906 // Set both |dest_path| and |source_path| to /dev/null, so that: |
907 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| | 907 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| |
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.set_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, |
929 cache_entry->GetSubDirectoryType(), | 929 GetSubDirectoryType(*cache_entry), |
930 CACHED_FILE_LOCALLY_MODIFIED); | 930 CACHED_FILE_LOCALLY_MODIFIED); |
931 source_path = dest_path; | 931 source_path = dest_path; |
932 } else { | 932 } else { |
933 // Gets the current path of the file in cache. | 933 // Gets the current path of the file in cache. |
934 source_path = GetCacheFilePath(resource_id, | 934 source_path = GetCacheFilePath(resource_id, |
935 md5, | 935 md5, |
936 cache_entry->GetSubDirectoryType(), | 936 GetSubDirectoryType(*cache_entry), |
937 CACHED_FILE_FROM_SERVER); | 937 CACHED_FILE_FROM_SERVER); |
938 | 938 |
939 // If file was pinned before but actual file blob doesn't exist in cache: | 939 // If file was pinned before but actual file blob doesn't exist in cache: |
940 // - don't need to move the file, so set |dest_path| to |source_path|, | 940 // - don't need to move the file, so set |dest_path| to |source_path|, |
941 // because ModifyCacheState only moves files if source and destination | 941 // because ModifyCacheState only moves files if source and destination |
942 // are different | 942 // are different |
943 // - don't create symlink since it already exists. | 943 // - don't create symlink since it already exists. |
944 if (!cache_entry->IsPresent()) { | 944 if (!cache_entry->IsPresent()) { |
945 dest_path = source_path; | 945 dest_path = source_path; |
946 create_symlink = false; | 946 create_symlink = false; |
(...skipping 28 matching lines...) Expand all Loading... |
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 |
985 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 985 scoped_ptr<GDataCacheEntry> cache_entry = GetCacheEntry(resource_id, md5); |
986 | 986 |
987 // Unpinning a file means its entry must exist in cache. | 987 // Unpinning a file means its entry must exist in cache. |
988 if (!cache_entry.get()) { | 988 if (!cache_entry.get()) { |
989 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" | 989 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" |
990 << resource_id | 990 << resource_id |
991 << ", md5=" << md5; | 991 << ", md5=" << md5; |
992 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 992 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
993 return; | 993 return; |
994 } | 994 } |
995 | 995 |
996 // Entry exists in cache, determines source and destination paths. | 996 // Entry exists in cache, determines source and destination paths. |
997 | 997 |
998 FilePath source_path; | 998 FilePath source_path; |
999 FilePath dest_path; | 999 FilePath dest_path; |
1000 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 1000 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
1001 | 1001 |
1002 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 1002 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
1003 // set |source_path| the same, because ModifyCacheState moves files if source | 1003 // set |source_path| the same, because ModifyCacheState moves files if source |
1004 // and destination are different. | 1004 // and destination are different. |
1005 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 1005 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { |
1006 sub_dir_type = CACHE_TYPE_PERSISTENT; | 1006 sub_dir_type = CACHE_TYPE_PERSISTENT; |
1007 DCHECK(cache_entry->IsPersistent()); | 1007 DCHECK(cache_entry->IsPersistent()); |
1008 dest_path = GetCacheFilePath(resource_id, | 1008 dest_path = GetCacheFilePath(resource_id, |
1009 md5, | 1009 md5, |
1010 cache_entry->GetSubDirectoryType(), | 1010 GetSubDirectoryType(*cache_entry), |
1011 CACHED_FILE_LOCALLY_MODIFIED); | 1011 CACHED_FILE_LOCALLY_MODIFIED); |
1012 source_path = dest_path; | 1012 source_path = dest_path; |
1013 } else { | 1013 } else { |
1014 // Gets the current path of the file in cache. | 1014 // Gets the current path of the file in cache. |
1015 source_path = GetCacheFilePath(resource_id, | 1015 source_path = GetCacheFilePath(resource_id, |
1016 md5, | 1016 md5, |
1017 cache_entry->GetSubDirectoryType(), | 1017 GetSubDirectoryType(*cache_entry), |
1018 CACHED_FILE_FROM_SERVER); | 1018 CACHED_FILE_FROM_SERVER); |
1019 | 1019 |
1020 // If file was pinned but actual file blob still doesn't exist in cache, | 1020 // If file was pinned but actual file blob still doesn't exist in cache, |
1021 // don't need to move the file, so set |dest_path| to |source_path|, because | 1021 // don't need to move the file, so set |dest_path| to |source_path|, because |
1022 // ModifyCacheState only moves files if source and destination are | 1022 // ModifyCacheState only moves files if source and destination are |
1023 // different. | 1023 // different. |
1024 if (!cache_entry->IsPresent()) { | 1024 if (!cache_entry->IsPresent()) { |
1025 dest_path = source_path; | 1025 dest_path = source_path; |
1026 } else { // File exists, move it to tmp dir. | 1026 } else { // File exists, move it to tmp dir. |
1027 dest_path = GetCacheFilePath(resource_id, md5, | 1027 dest_path = GetCacheFilePath(resource_id, md5, |
(...skipping 14 matching lines...) Expand all 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 GDataCacheEntry 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) { |
1063 AssertOnSequencedWorkerPool(); | 1063 AssertOnSequencedWorkerPool(); |
1064 DCHECK(error); | 1064 DCHECK(error); |
1065 DCHECK(cache_file_path); | 1065 DCHECK(cache_file_path); |
1066 | 1066 |
1067 // Parse file path to obtain resource_id, md5 and extra_extension. | 1067 // Parse file path to obtain resource_id, md5 and extra_extension. |
1068 std::string resource_id; | 1068 std::string resource_id; |
1069 std::string md5; | 1069 std::string md5; |
1070 std::string extra_extension; | 1070 std::string extra_extension; |
1071 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); | 1071 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); |
1072 // The extra_extension shall be ".mounted" iff we're unmounting. | 1072 // The extra_extension shall be ".mounted" iff we're unmounting. |
1073 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); | 1073 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); |
1074 | 1074 |
1075 // Get cache entry associated with the resource_id and md5 | 1075 // Get cache entry associated with the resource_id and md5 |
1076 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 1076 scoped_ptr<GDataCacheEntry> cache_entry = GetCacheEntry( |
1077 resource_id, md5); | 1077 resource_id, md5); |
1078 if (!cache_entry.get()) { | 1078 if (!cache_entry.get()) { |
1079 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1079 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1080 return; | 1080 return; |
1081 } | 1081 } |
1082 if (to_mount == cache_entry->IsMounted()) { | 1082 if (to_mount == cache_entry->IsMounted()) { |
1083 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1083 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
1084 return; | 1084 return; |
1085 } | 1085 } |
1086 | 1086 |
1087 // Get the subdir type and path for the unmounted state. | 1087 // Get the subdir type and path for the unmounted state. |
1088 CacheSubDirectoryType unmounted_subdir = | 1088 CacheSubDirectoryType unmounted_subdir = |
1089 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1089 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1090 FilePath unmounted_path = GetCacheFilePath( | 1090 FilePath unmounted_path = GetCacheFilePath( |
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 GDataCacheEntry 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 15 matching lines...) Expand all Loading... |
1127 base::PlatformFileError* error, | 1127 base::PlatformFileError* error, |
1128 FilePath* cache_file_path) { | 1128 FilePath* cache_file_path) { |
1129 AssertOnSequencedWorkerPool(); | 1129 AssertOnSequencedWorkerPool(); |
1130 DCHECK(error); | 1130 DCHECK(error); |
1131 DCHECK(cache_file_path); | 1131 DCHECK(cache_file_path); |
1132 | 1132 |
1133 // If file has already been marked dirty in previous instance of chrome, we | 1133 // If file has already been marked dirty in previous instance of chrome, we |
1134 // would have lost the md5 info during cache initialization, because the file | 1134 // would have lost the md5 info during cache initialization, because the file |
1135 // would have been renamed to .local extension. | 1135 // would have been renamed to .local extension. |
1136 // So, search for entry in cache without comparing md5. | 1136 // So, search for entry in cache without comparing md5. |
1137 scoped_ptr<CacheEntry> cache_entry = | 1137 scoped_ptr<GDataCacheEntry> cache_entry = |
1138 GetCacheEntry(resource_id, std::string()); | 1138 GetCacheEntry(resource_id, std::string()); |
1139 | 1139 |
1140 // Marking a file dirty means its entry and actual file blob must exist in | 1140 // Marking a file dirty means its entry and actual file blob must exist in |
1141 // cache. | 1141 // cache. |
1142 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1142 if (!cache_entry.get() || !cache_entry->IsPresent()) { |
1143 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" | 1143 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" |
1144 << resource_id | 1144 << resource_id |
1145 << ", md5=" << md5; | 1145 << ", md5=" << md5; |
1146 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1146 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1147 return; | 1147 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 } | 1184 } |
1185 return; | 1185 return; |
1186 } | 1186 } |
1187 | 1187 |
1188 // Move file to persistent dir with new .local extension. | 1188 // Move file to persistent dir with new .local extension. |
1189 | 1189 |
1190 // Get the current path of the file in cache. | 1190 // Get the current path of the file in cache. |
1191 FilePath source_path = GetCacheFilePath( | 1191 FilePath source_path = GetCacheFilePath( |
1192 resource_id, | 1192 resource_id, |
1193 md5, | 1193 md5, |
1194 cache_entry->GetSubDirectoryType(), | 1194 GetSubDirectoryType(*cache_entry), |
1195 CACHED_FILE_FROM_SERVER); | 1195 CACHED_FILE_FROM_SERVER); |
1196 | 1196 |
1197 // Determine destination path. | 1197 // Determine destination path. |
1198 const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 1198 const CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
1199 *cache_file_path = GetCacheFilePath(resource_id, | 1199 *cache_file_path = GetCacheFilePath(resource_id, |
1200 md5, | 1200 md5, |
1201 sub_dir_type, | 1201 sub_dir_type, |
1202 CACHED_FILE_LOCALLY_MODIFIED); | 1202 CACHED_FILE_LOCALLY_MODIFIED); |
1203 | 1203 |
1204 // If file is pinned, update symlink in pinned dir. | 1204 // If file is pinned, update symlink in pinned dir. |
1205 FilePath symlink_path; | 1205 FilePath symlink_path; |
1206 if (cache_entry->IsPinned()) { | 1206 if (cache_entry->IsPinned()) { |
1207 symlink_path = GetCacheFilePath(resource_id, | 1207 symlink_path = GetCacheFilePath(resource_id, |
1208 std::string(), | 1208 std::string(), |
1209 CACHE_TYPE_PINNED, | 1209 CACHE_TYPE_PINNED, |
1210 CACHED_FILE_FROM_SERVER); | 1210 CACHED_FILE_FROM_SERVER); |
1211 } | 1211 } |
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 GDataCacheEntry 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) { |
1233 AssertOnSequencedWorkerPool(); | 1233 AssertOnSequencedWorkerPool(); |
1234 DCHECK(error); | 1234 DCHECK(error); |
1235 | 1235 |
1236 // If file has already been marked dirty in previous instance of chrome, we | 1236 // If file has already been marked dirty in previous instance of chrome, we |
1237 // would have lost the md5 info during cache initialization, because the file | 1237 // would have lost the md5 info during cache initialization, because the file |
1238 // would have been renamed to .local extension. | 1238 // would have been renamed to .local extension. |
1239 // So, search for entry in cache without comparing md5. | 1239 // So, search for entry in cache without comparing md5. |
1240 scoped_ptr<CacheEntry> cache_entry = | 1240 scoped_ptr<GDataCacheEntry> cache_entry = |
1241 GetCacheEntry(resource_id, std::string()); | 1241 GetCacheEntry(resource_id, std::string()); |
1242 | 1242 |
1243 // Committing a file dirty means its entry and actual file blob must exist in | 1243 // Committing a file dirty means its entry and actual file blob must exist in |
1244 // cache. | 1244 // cache. |
1245 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1245 if (!cache_entry.get() || !cache_entry->IsPresent()) { |
1246 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" | 1246 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" |
1247 << resource_id | 1247 << resource_id |
1248 << ", md5=" << md5; | 1248 << ", md5=" << md5; |
1249 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1249 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1250 return; | 1250 return; |
(...skipping 14 matching lines...) Expand all Loading... |
1265 | 1265 |
1266 // Create symlink in outgoing dir. | 1266 // Create symlink in outgoing dir. |
1267 FilePath symlink_path = GetCacheFilePath(resource_id, | 1267 FilePath symlink_path = GetCacheFilePath(resource_id, |
1268 std::string(), | 1268 std::string(), |
1269 CACHE_TYPE_OUTGOING, | 1269 CACHE_TYPE_OUTGOING, |
1270 CACHED_FILE_FROM_SERVER); | 1270 CACHED_FILE_FROM_SERVER); |
1271 | 1271 |
1272 // Get target path of symlink i.e. current path of the file in cache. | 1272 // Get target path of symlink i.e. current path of the file in cache. |
1273 FilePath target_path = GetCacheFilePath(resource_id, | 1273 FilePath target_path = GetCacheFilePath(resource_id, |
1274 md5, | 1274 md5, |
1275 cache_entry->GetSubDirectoryType(), | 1275 GetSubDirectoryType(*cache_entry), |
1276 CACHED_FILE_LOCALLY_MODIFIED); | 1276 CACHED_FILE_LOCALLY_MODIFIED); |
1277 | 1277 |
1278 // Since there's no need to move files, use |target_path| for both | 1278 // Since there's no need to move files, use |target_path| for both |
1279 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1279 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
1280 // if source and destination are different. | 1280 // if source and destination are different. |
1281 *error = ModifyCacheState(target_path, // source | 1281 *error = ModifyCacheState(target_path, // source |
1282 target_path, // destination | 1282 target_path, // destination |
1283 file_operation_type, | 1283 file_operation_type, |
1284 symlink_path, | 1284 symlink_path, |
1285 true /* create symlink */); | 1285 true /* create symlink */); |
1286 } | 1286 } |
1287 | 1287 |
1288 void GDataCache::ClearDirty(const std::string& resource_id, | 1288 void GDataCache::ClearDirty(const std::string& resource_id, |
1289 const std::string& md5, | 1289 const std::string& md5, |
1290 FileOperationType file_operation_type, | 1290 FileOperationType file_operation_type, |
1291 base::PlatformFileError* error) { | 1291 base::PlatformFileError* error) { |
1292 AssertOnSequencedWorkerPool(); | 1292 AssertOnSequencedWorkerPool(); |
1293 DCHECK(error); | 1293 DCHECK(error); |
1294 | 1294 |
1295 // |md5| is the new .<md5> extension to rename the file to. | 1295 // |md5| is the new .<md5> extension to rename the file to. |
1296 // So, search for entry in cache without comparing md5. | 1296 // So, search for entry in cache without comparing md5. |
1297 scoped_ptr<CacheEntry> cache_entry = | 1297 scoped_ptr<GDataCacheEntry> cache_entry = |
1298 GetCacheEntry(resource_id, std::string()); | 1298 GetCacheEntry(resource_id, std::string()); |
1299 | 1299 |
1300 // Clearing a dirty file means its entry and actual file blob must exist in | 1300 // Clearing a dirty file means its entry and actual file blob must exist in |
1301 // cache. | 1301 // cache. |
1302 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1302 if (!cache_entry.get() || !cache_entry->IsPresent()) { |
1303 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " | 1303 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " |
1304 << "res_id=" << resource_id | 1304 << "res_id=" << resource_id |
1305 << ", md5=" << md5; | 1305 << ", md5=" << md5; |
1306 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1306 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
1307 return; | 1307 return; |
1308 } | 1308 } |
1309 | 1309 |
1310 // If a file is not dirty (it should have been marked dirty via | 1310 // If a file is not dirty (it should have been marked dirty via |
1311 // MarkDirtyInCache), clearing its dirty state is an invalid operation. | 1311 // MarkDirtyInCache), clearing its dirty state is an invalid operation. |
1312 if (!cache_entry->IsDirty()) { | 1312 if (!cache_entry->IsDirty()) { |
1313 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" | 1313 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" |
1314 << resource_id | 1314 << resource_id |
1315 << ", md5=" << md5; | 1315 << ", md5=" << md5; |
1316 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1316 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
1317 return; | 1317 return; |
1318 } | 1318 } |
1319 | 1319 |
1320 // File must be dirty and hence in persistent dir. | 1320 // File must be dirty and hence in persistent dir. |
1321 DCHECK(cache_entry->IsPersistent()); | 1321 DCHECK(cache_entry->IsPersistent()); |
1322 | 1322 |
1323 // Get the current path of the file in cache. | 1323 // Get the current path of the file in cache. |
1324 FilePath source_path = GetCacheFilePath(resource_id, | 1324 FilePath source_path = GetCacheFilePath(resource_id, |
1325 md5, | 1325 md5, |
1326 cache_entry->GetSubDirectoryType(), | 1326 GetSubDirectoryType(*cache_entry), |
1327 CACHED_FILE_LOCALLY_MODIFIED); | 1327 CACHED_FILE_LOCALLY_MODIFIED); |
1328 | 1328 |
1329 // Determine destination path. | 1329 // Determine destination path. |
1330 // 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; |
1331 // otherwise, move it to tmp dir with .md5 extension. | 1331 // otherwise, move it to tmp dir with .md5 extension. |
1332 const CacheSubDirectoryType sub_dir_type = | 1332 const CacheSubDirectoryType sub_dir_type = |
1333 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1333 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1334 FilePath dest_path = GetCacheFilePath(resource_id, | 1334 FilePath dest_path = GetCacheFilePath(resource_id, |
1335 md5, | 1335 md5, |
1336 sub_dir_type, | 1336 sub_dir_type, |
(...skipping 23 matching lines...) Expand all 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 GDataCacheEntry 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); |
1381 | 1381 |
1382 // MD5 is not passed into RemoveFromCache and hence | 1382 // MD5 is not passed into RemoveFromCache and hence |
1383 // RemoveFromCacheOnBlockingPool, because we would delete all cache files | 1383 // RemoveFromCacheOnBlockingPool, because we would delete all cache files |
1384 // 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. | 1385 // So, search for entry in cache without taking md5 into account. |
1386 scoped_ptr<CacheEntry> cache_entry = | 1386 scoped_ptr<GDataCacheEntry> cache_entry = |
1387 GetCacheEntry(resource_id, std::string()); | 1387 GetCacheEntry(resource_id, std::string()); |
1388 | 1388 |
1389 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. | 1389 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. |
1390 if (!cache_entry.get() || | 1390 if (!cache_entry.get() || |
1391 cache_entry->IsDirty() || | 1391 cache_entry->IsDirty() || |
1392 cache_entry->IsMounted()) { | 1392 cache_entry->IsMounted()) { |
1393 DVLOG(1) << "Entry is " | 1393 DVLOG(1) << "Entry is " |
1394 << (cache_entry.get() ? | 1394 << (cache_entry.get() ? |
1395 (cache_entry->IsDirty() ? "dirty" : "mounted") : | 1395 (cache_entry->IsDirty() ? "dirty" : "mounted") : |
1396 "non-existent") | 1396 "non-existent") |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 if (!callback.is_null()) | 1487 if (!callback.is_null()) |
1488 callback.Run(*error, resource_id, md5); | 1488 callback.Run(*error, resource_id, md5); |
1489 | 1489 |
1490 if (*error == base::PLATFORM_FILE_OK) | 1490 if (*error == base::PLATFORM_FILE_OK) |
1491 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); | 1491 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); |
1492 } | 1492 } |
1493 | 1493 |
1494 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, | 1494 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, |
1495 const std::string& md5, | 1495 const std::string& md5, |
1496 bool* success, | 1496 bool* success, |
1497 GDataCache::CacheEntry* cache_entry) { | 1497 GDataCacheEntry* cache_entry) { |
1498 AssertOnSequencedWorkerPool(); | 1498 AssertOnSequencedWorkerPool(); |
1499 DCHECK(success); | 1499 DCHECK(success); |
1500 DCHECK(cache_entry); | 1500 DCHECK(cache_entry); |
1501 | 1501 |
1502 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); | 1502 scoped_ptr<GDataCacheEntry> value(GetCacheEntry(resource_id, md5)); |
1503 *success = value.get(); | 1503 *success = value.get(); |
1504 if (*success) | 1504 if (*success) |
1505 *cache_entry = *value; | 1505 *cache_entry = *value; |
1506 } | 1506 } |
1507 | 1507 |
1508 // static | 1508 // static |
1509 FilePath GDataCache::GetCacheRootPath(Profile* profile) { | 1509 FilePath GDataCache::GetCacheRootPath(Profile* profile) { |
1510 FilePath cache_base_path; | 1510 FilePath cache_base_path; |
1511 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); | 1511 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); |
1512 FilePath cache_root_path = | 1512 FilePath cache_root_path = |
(...skipping 29 matching lines...) Expand all Loading... |
1542 // Error creating this directory, record error and proceed with next one. | 1542 // Error creating this directory, record error and proceed with next one. |
1543 success = false; | 1543 success = false; |
1544 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value(); | 1544 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value(); |
1545 } else { | 1545 } else { |
1546 DVLOG(1) << "Created directory " << paths_to_create[i].value(); | 1546 DVLOG(1) << "Created directory " << paths_to_create[i].value(); |
1547 } | 1547 } |
1548 } | 1548 } |
1549 return success; | 1549 return success; |
1550 } | 1550 } |
1551 | 1551 |
| 1552 // static |
| 1553 GDataCache::CacheSubDirectoryType GDataCache::GetSubDirectoryType( |
| 1554 const GDataCacheEntry& cache_entry) { |
| 1555 return cache_entry.IsPersistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1556 } |
| 1557 |
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1558 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1559 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1554 global_free_disk_getter_for_testing = getter; | 1560 global_free_disk_getter_for_testing = getter; |
1555 } | 1561 } |
1556 | 1562 |
1557 } // namespace gdata | 1563 } // namespace gdata |
OLD | NEW |