Chromium Code Reviews| 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 693 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 bool GDataCache::GetCacheEntry(const std::string& resource_id, |
| 715 const std::string& resource_id, | 715 const std::string& md5, |
| 716 const std::string& md5) { | 716 CacheEntry* entry) { |
| 717 DCHECK(entry); | |
| 717 AssertOnSequencedWorkerPool(); | 718 AssertOnSequencedWorkerPool(); |
| 718 return metadata_->GetCacheEntry(resource_id, md5); | 719 return metadata_->GetCacheEntry(resource_id, md5, entry); |
| 719 } | 720 } |
| 720 | 721 |
| 721 // static | 722 // static |
| 722 GDataCache* GDataCache::CreateGDataCacheOnUIThread( | 723 GDataCache* GDataCache::CreateGDataCacheOnUIThread( |
| 723 const FilePath& cache_root_path, | 724 const FilePath& cache_root_path, |
| 724 base::SequencedWorkerPool* pool, | 725 base::SequencedWorkerPool* pool, |
| 725 const base::SequencedWorkerPool::SequenceToken& sequence_token) { | 726 const base::SequencedWorkerPool::SequenceToken& sequence_token) { |
| 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 727 return new GDataCache(cache_root_path, pool, sequence_token); | 728 return new GDataCache(cache_root_path, pool, sequence_token); |
| 728 } | 729 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 } | 774 } |
| 774 | 775 |
| 775 void GDataCache::GetFile(const std::string& resource_id, | 776 void GDataCache::GetFile(const std::string& resource_id, |
| 776 const std::string& md5, | 777 const std::string& md5, |
| 777 base::PlatformFileError* error, | 778 base::PlatformFileError* error, |
| 778 FilePath* cache_file_path) { | 779 FilePath* cache_file_path) { |
| 779 AssertOnSequencedWorkerPool(); | 780 AssertOnSequencedWorkerPool(); |
| 780 DCHECK(error); | 781 DCHECK(error); |
| 781 DCHECK(cache_file_path); | 782 DCHECK(cache_file_path); |
| 782 | 783 |
| 783 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 784 CacheEntry cache_entry; |
| 784 resource_id, md5); | 785 if (GetCacheEntry(resource_id, md5, &cache_entry) && |
| 785 if (cache_entry.get() && cache_entry->IsPresent()) { | 786 cache_entry.IsPresent()) { |
| 786 CachedFileOrigin file_origin; | 787 CachedFileOrigin file_origin; |
| 787 if (cache_entry->IsMounted()) { | 788 if (cache_entry.IsMounted()) { |
| 788 file_origin = CACHED_FILE_MOUNTED; | 789 file_origin = CACHED_FILE_MOUNTED; |
| 789 } else if (cache_entry->IsDirty()) { | 790 } else if (cache_entry.IsDirty()) { |
| 790 file_origin = CACHED_FILE_LOCALLY_MODIFIED; | 791 file_origin = CACHED_FILE_LOCALLY_MODIFIED; |
| 791 } else { | 792 } else { |
| 792 file_origin = CACHED_FILE_FROM_SERVER; | 793 file_origin = CACHED_FILE_FROM_SERVER; |
| 793 } | 794 } |
| 794 *cache_file_path = GetCacheFilePath( | 795 *cache_file_path = GetCacheFilePath( |
| 795 resource_id, | 796 resource_id, |
| 796 md5, | 797 md5, |
| 797 cache_entry->GetSubDirectoryType(), | 798 cache_entry.GetSubDirectoryType(), |
| 798 file_origin); | 799 file_origin); |
| 799 *error = base::PLATFORM_FILE_OK; | 800 *error = base::PLATFORM_FILE_OK; |
| 800 } else { | 801 } else { |
| 801 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 802 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 802 } | 803 } |
| 803 } | 804 } |
| 804 | 805 |
| 805 void GDataCache::Store(const std::string& resource_id, | 806 void GDataCache::Store(const std::string& resource_id, |
| 806 const std::string& md5, | 807 const std::string& md5, |
| 807 const FilePath& source_path, | 808 const FilePath& source_path, |
| 808 FileOperationType file_operation_type, | 809 FileOperationType file_operation_type, |
| 809 base::PlatformFileError* error) { | 810 base::PlatformFileError* error) { |
| 810 AssertOnSequencedWorkerPool(); | 811 AssertOnSequencedWorkerPool(); |
| 811 DCHECK(error); | 812 DCHECK(error); |
| 812 | 813 |
| 813 FilePath dest_path; | 814 FilePath dest_path; |
| 814 FilePath symlink_path; | 815 FilePath symlink_path; |
| 815 int cache_state = CACHE_STATE_PRESENT; | 816 int cache_state = CACHE_STATE_PRESENT; |
| 816 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 817 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 817 | 818 |
| 818 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 819 CacheEntry cache_entry; |
|
achuithb
2012/07/11 19:09:59
nit: Can we move this declaration to right before
hashimoto
2012/07/12 05:15:19
Done.
| |
| 819 | 820 |
| 820 // If file was previously pinned, store it in persistent dir and create | 821 // If file was previously pinned, store it in persistent dir and create |
| 821 // symlink in pinned dir. | 822 // symlink in pinned dir. |
| 822 if (cache_entry.get()) { // File exists in cache. | 823 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. |
| 823 // If file is dirty or mounted, return error. | 824 // If file is dirty or mounted, return error. |
| 824 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 825 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
| 825 LOG(WARNING) << "Can't store a file to replace a " | 826 LOG(WARNING) << "Can't store a file to replace a " |
| 826 << (cache_entry->IsDirty() ? "dirty" : "mounted") | 827 << (cache_entry.IsDirty() ? "dirty" : "mounted") |
| 827 << " file: res_id=" << resource_id | 828 << " file: res_id=" << resource_id |
| 828 << ", md5=" << md5; | 829 << ", md5=" << md5; |
| 829 *error = base::PLATFORM_FILE_ERROR_IN_USE; | 830 *error = base::PLATFORM_FILE_ERROR_IN_USE; |
| 830 return; | 831 return; |
| 831 } | 832 } |
| 832 | 833 |
| 833 cache_state |= cache_entry->cache_state; | 834 cache_state |= cache_entry.cache_state; |
| 834 | 835 |
| 835 // If file is pinned, determines destination path. | 836 // If file is pinned, determines destination path. |
| 836 if (cache_entry->IsPinned()) { | 837 if (cache_entry.IsPinned()) { |
| 837 sub_dir_type = CACHE_TYPE_PERSISTENT; | 838 sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 838 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, | 839 dest_path = GetCacheFilePath(resource_id, md5, sub_dir_type, |
| 839 CACHED_FILE_FROM_SERVER); | 840 CACHED_FILE_FROM_SERVER); |
| 840 symlink_path = GetCacheFilePath( | 841 symlink_path = GetCacheFilePath( |
| 841 resource_id, std::string(), CACHE_TYPE_PINNED, | 842 resource_id, std::string(), CACHE_TYPE_PINNED, |
| 842 CACHED_FILE_FROM_SERVER); | 843 CACHED_FILE_FROM_SERVER); |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 | 846 |
| 846 // File wasn't pinned or doesn't exist in cache, store in tmp dir. | 847 // File wasn't pinned or doesn't exist in cache, store in tmp dir. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 AssertOnSequencedWorkerPool(); | 895 AssertOnSequencedWorkerPool(); |
| 895 DCHECK(error); | 896 DCHECK(error); |
| 896 | 897 |
| 897 FilePath source_path; | 898 FilePath source_path; |
| 898 FilePath dest_path; | 899 FilePath dest_path; |
| 899 FilePath symlink_path; | 900 FilePath symlink_path; |
| 900 bool create_symlink = true; | 901 bool create_symlink = true; |
| 901 int cache_state = CACHE_STATE_PINNED; | 902 int cache_state = CACHE_STATE_PINNED; |
| 902 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 903 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 903 | 904 |
| 904 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 905 CacheEntry cache_entry; |
| 905 | 906 |
|
achuithb
2012/07/11 19:09:59
nit: Don't think this newline is necessary.
hashimoto
2012/07/12 05:15:19
Done.
| |
| 906 if (!cache_entry.get()) { // Entry does not exist in cache. | 907 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
| 908 // Entry does not exist in cache. | |
| 907 // Set both |dest_path| and |source_path| to /dev/null, so that: | 909 // Set both |dest_path| and |source_path| to /dev/null, so that: |
| 908 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| | 910 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| |
| 909 // are the same. | 911 // are the same. |
| 910 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download | 912 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download |
| 911 // pinned files that don't exist in cache. | 913 // pinned files that don't exist in cache. |
| 912 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); | 914 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); |
| 913 source_path = dest_path; | 915 source_path = dest_path; |
| 914 | 916 |
| 915 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', | 917 // Set sub_dir_type to TMP. The file will be first downloaded in 'tmp', |
| 916 // then moved to 'persistent'. | 918 // then moved to 'persistent'. |
| 917 sub_dir_type = CACHE_TYPE_TMP; | 919 sub_dir_type = CACHE_TYPE_TMP; |
| 918 } else { // File exists in cache, determines destination path. | 920 } else { // File exists in cache, determines destination path. |
| 919 cache_state |= cache_entry->cache_state; | 921 cache_state |= cache_entry.cache_state; |
| 920 | 922 |
| 921 // Determine source and destination paths. | 923 // Determine source and destination paths. |
| 922 | 924 |
| 923 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 925 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
| 924 // set |source_path| the same, because ModifyCacheState only moves files if | 926 // set |source_path| the same, because ModifyCacheState only moves files if |
| 925 // source and destination are different. | 927 // source and destination are different. |
| 926 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 928 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
| 927 DCHECK(cache_entry->IsPersistent()); | 929 DCHECK(cache_entry.IsPersistent()); |
| 928 dest_path = GetCacheFilePath(resource_id, | 930 dest_path = GetCacheFilePath(resource_id, |
| 929 md5, | 931 md5, |
| 930 cache_entry->GetSubDirectoryType(), | 932 cache_entry.GetSubDirectoryType(), |
| 931 CACHED_FILE_LOCALLY_MODIFIED); | 933 CACHED_FILE_LOCALLY_MODIFIED); |
| 932 source_path = dest_path; | 934 source_path = dest_path; |
| 933 } else { | 935 } else { |
| 934 // Gets the current path of the file in cache. | 936 // Gets the current path of the file in cache. |
| 935 source_path = GetCacheFilePath(resource_id, | 937 source_path = GetCacheFilePath(resource_id, |
| 936 md5, | 938 md5, |
| 937 cache_entry->GetSubDirectoryType(), | 939 cache_entry.GetSubDirectoryType(), |
| 938 CACHED_FILE_FROM_SERVER); | 940 CACHED_FILE_FROM_SERVER); |
| 939 | 941 |
| 940 // If file was pinned before but actual file blob doesn't exist in cache: | 942 // If file was pinned before but actual file blob doesn't exist in cache: |
| 941 // - don't need to move the file, so set |dest_path| to |source_path|, | 943 // - don't need to move the file, so set |dest_path| to |source_path|, |
| 942 // because ModifyCacheState only moves files if source and destination | 944 // because ModifyCacheState only moves files if source and destination |
| 943 // are different | 945 // are different |
| 944 // - don't create symlink since it already exists. | 946 // - don't create symlink since it already exists. |
| 945 if (!cache_entry->IsPresent()) { | 947 if (!cache_entry.IsPresent()) { |
| 946 dest_path = source_path; | 948 dest_path = source_path; |
| 947 create_symlink = false; | 949 create_symlink = false; |
| 948 } else { // File exists, move it to persistent dir. | 950 } else { // File exists, move it to persistent dir. |
| 949 dest_path = GetCacheFilePath(resource_id, | 951 dest_path = GetCacheFilePath(resource_id, |
| 950 md5, | 952 md5, |
| 951 CACHE_TYPE_PERSISTENT, | 953 CACHE_TYPE_PERSISTENT, |
| 952 CACHED_FILE_FROM_SERVER); | 954 CACHED_FILE_FROM_SERVER); |
| 953 } | 955 } |
| 954 } | 956 } |
| 955 } | 957 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 977 } | 979 } |
| 978 } | 980 } |
| 979 | 981 |
| 980 void GDataCache::Unpin(const std::string& resource_id, | 982 void GDataCache::Unpin(const std::string& resource_id, |
| 981 const std::string& md5, | 983 const std::string& md5, |
| 982 FileOperationType file_operation_type, | 984 FileOperationType file_operation_type, |
| 983 base::PlatformFileError* error) { | 985 base::PlatformFileError* error) { |
| 984 AssertOnSequencedWorkerPool(); | 986 AssertOnSequencedWorkerPool(); |
| 985 DCHECK(error); | 987 DCHECK(error); |
| 986 | 988 |
| 987 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry(resource_id, md5); | 989 CacheEntry cache_entry; |
| 988 | 990 |
|
achuithb
2012/07/11 19:09:59
nit: Move this to right before GetCacheEntry.
hashimoto
2012/07/12 05:15:19
Done.
| |
| 989 // Unpinning a file means its entry must exist in cache. | 991 // Unpinning a file means its entry must exist in cache. |
| 990 if (!cache_entry.get()) { | 992 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
| 991 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" | 993 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" |
| 992 << resource_id | 994 << resource_id |
| 993 << ", md5=" << md5; | 995 << ", md5=" << md5; |
| 994 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 996 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 995 return; | 997 return; |
| 996 } | 998 } |
| 997 | 999 |
| 998 // Entry exists in cache, determines source and destination paths. | 1000 // Entry exists in cache, determines source and destination paths. |
| 999 | 1001 |
| 1000 FilePath source_path; | 1002 FilePath source_path; |
| 1001 FilePath dest_path; | 1003 FilePath dest_path; |
| 1002 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; | 1004 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; |
| 1003 | 1005 |
| 1004 // If file is dirty or mounted, don't move it, so determine |dest_path| and | 1006 // If file is dirty or mounted, don't move it, so determine |dest_path| and |
| 1005 // set |source_path| the same, because ModifyCacheState moves files if source | 1007 // set |source_path| the same, because ModifyCacheState moves files if source |
| 1006 // and destination are different. | 1008 // and destination are different. |
| 1007 if (cache_entry->IsDirty() || cache_entry->IsMounted()) { | 1009 if (cache_entry.IsDirty() || cache_entry.IsMounted()) { |
| 1008 sub_dir_type = CACHE_TYPE_PERSISTENT; | 1010 sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 1009 DCHECK(cache_entry->IsPersistent()); | 1011 DCHECK(cache_entry.IsPersistent()); |
| 1010 dest_path = GetCacheFilePath(resource_id, | 1012 dest_path = GetCacheFilePath(resource_id, |
| 1011 md5, | 1013 md5, |
| 1012 cache_entry->GetSubDirectoryType(), | 1014 cache_entry.GetSubDirectoryType(), |
| 1013 CACHED_FILE_LOCALLY_MODIFIED); | 1015 CACHED_FILE_LOCALLY_MODIFIED); |
| 1014 source_path = dest_path; | 1016 source_path = dest_path; |
| 1015 } else { | 1017 } else { |
| 1016 // Gets the current path of the file in cache. | 1018 // Gets the current path of the file in cache. |
| 1017 source_path = GetCacheFilePath(resource_id, | 1019 source_path = GetCacheFilePath(resource_id, |
| 1018 md5, | 1020 md5, |
| 1019 cache_entry->GetSubDirectoryType(), | 1021 cache_entry.GetSubDirectoryType(), |
| 1020 CACHED_FILE_FROM_SERVER); | 1022 CACHED_FILE_FROM_SERVER); |
| 1021 | 1023 |
| 1022 // If file was pinned but actual file blob still doesn't exist in cache, | 1024 // If file was pinned but actual file blob still doesn't exist in cache, |
| 1023 // don't need to move the file, so set |dest_path| to |source_path|, because | 1025 // don't need to move the file, so set |dest_path| to |source_path|, because |
| 1024 // ModifyCacheState only moves files if source and destination are | 1026 // ModifyCacheState only moves files if source and destination are |
| 1025 // different. | 1027 // different. |
| 1026 if (!cache_entry->IsPresent()) { | 1028 if (!cache_entry.IsPresent()) { |
| 1027 dest_path = source_path; | 1029 dest_path = source_path; |
| 1028 } else { // File exists, move it to tmp dir. | 1030 } else { // File exists, move it to tmp dir. |
| 1029 dest_path = GetCacheFilePath(resource_id, md5, | 1031 dest_path = GetCacheFilePath(resource_id, md5, |
| 1030 CACHE_TYPE_TMP, | 1032 CACHE_TYPE_TMP, |
| 1031 CACHED_FILE_FROM_SERVER); | 1033 CACHED_FILE_FROM_SERVER); |
| 1032 } | 1034 } |
| 1033 } | 1035 } |
| 1034 | 1036 |
| 1035 // If file was pinned, get absolute path of symlink in pinned dir so as to | 1037 // If file was pinned, get absolute path of symlink in pinned dir so as to |
| 1036 // remove it. | 1038 // remove it. |
| 1037 FilePath symlink_path; | 1039 FilePath symlink_path; |
| 1038 if (cache_entry->IsPinned()) { | 1040 if (cache_entry.IsPinned()) { |
| 1039 symlink_path = GetCacheFilePath(resource_id, | 1041 symlink_path = GetCacheFilePath(resource_id, |
| 1040 std::string(), | 1042 std::string(), |
| 1041 CACHE_TYPE_PINNED, | 1043 CACHE_TYPE_PINNED, |
| 1042 CACHED_FILE_FROM_SERVER); | 1044 CACHED_FILE_FROM_SERVER); |
| 1043 } | 1045 } |
| 1044 | 1046 |
| 1045 *error = ModifyCacheState( | 1047 *error = ModifyCacheState( |
| 1046 source_path, | 1048 source_path, |
| 1047 dest_path, | 1049 dest_path, |
| 1048 file_operation_type, | 1050 file_operation_type, |
| 1049 symlink_path, // This will be deleted if it exists. | 1051 symlink_path, // This will be deleted if it exists. |
| 1050 false /* don't create symlink*/); | 1052 false /* don't create symlink*/); |
| 1051 | 1053 |
| 1052 if (*error == base::PLATFORM_FILE_OK) { | 1054 if (*error == base::PLATFORM_FILE_OK) { |
| 1053 // Now that file operations have completed, update cache map. | 1055 // Now that file operations have completed, update cache map. |
| 1054 int cache_state = ClearCachePinned(cache_entry->cache_state); | 1056 int cache_state = ClearCachePinned(cache_entry.cache_state); |
| 1055 UpdateCacheWithSubDirectoryType(resource_id, | 1057 UpdateCacheWithSubDirectoryType(resource_id, |
| 1056 md5, | 1058 md5, |
| 1057 sub_dir_type, | 1059 sub_dir_type, |
| 1058 cache_state); | 1060 cache_state); |
| 1059 } | 1061 } |
| 1060 } | 1062 } |
| 1061 | 1063 |
| 1062 void GDataCache::SetMountedState(const FilePath& file_path, | 1064 void GDataCache::SetMountedState(const FilePath& file_path, |
| 1063 bool to_mount, | 1065 bool to_mount, |
| 1064 base::PlatformFileError *error, | 1066 base::PlatformFileError *error, |
| 1065 FilePath* cache_file_path) { | 1067 FilePath* cache_file_path) { |
| 1066 AssertOnSequencedWorkerPool(); | 1068 AssertOnSequencedWorkerPool(); |
| 1067 DCHECK(error); | 1069 DCHECK(error); |
| 1068 DCHECK(cache_file_path); | 1070 DCHECK(cache_file_path); |
| 1069 | 1071 |
| 1070 // Parse file path to obtain resource_id, md5 and extra_extension. | 1072 // Parse file path to obtain resource_id, md5 and extra_extension. |
| 1071 std::string resource_id; | 1073 std::string resource_id; |
| 1072 std::string md5; | 1074 std::string md5; |
| 1073 std::string extra_extension; | 1075 std::string extra_extension; |
| 1074 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); | 1076 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); |
| 1075 // The extra_extension shall be ".mounted" iff we're unmounting. | 1077 // The extra_extension shall be ".mounted" iff we're unmounting. |
| 1076 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); | 1078 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); |
| 1077 | 1079 |
| 1078 // Get cache entry associated with the resource_id and md5 | 1080 // Get cache entry associated with the resource_id and md5 |
| 1079 scoped_ptr<CacheEntry> cache_entry = GetCacheEntry( | 1081 CacheEntry cache_entry; |
| 1080 resource_id, md5); | 1082 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { |
| 1081 if (!cache_entry.get()) { | |
| 1082 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1083 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1083 return; | 1084 return; |
| 1084 } | 1085 } |
| 1085 if (to_mount == cache_entry->IsMounted()) { | 1086 if (to_mount == cache_entry.IsMounted()) { |
| 1086 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1087 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 1087 return; | 1088 return; |
| 1088 } | 1089 } |
| 1089 | 1090 |
| 1090 // Get the subdir type and path for the unmounted state. | 1091 // Get the subdir type and path for the unmounted state. |
| 1091 CacheSubDirectoryType unmounted_subdir = | 1092 CacheSubDirectoryType unmounted_subdir = |
| 1092 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1093 cache_entry.IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1093 FilePath unmounted_path = GetCacheFilePath( | 1094 FilePath unmounted_path = GetCacheFilePath( |
| 1094 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); | 1095 resource_id, md5, unmounted_subdir, CACHED_FILE_FROM_SERVER); |
| 1095 | 1096 |
| 1096 // Get the subdir type and path for the mounted state. | 1097 // Get the subdir type and path for the mounted state. |
| 1097 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; | 1098 CacheSubDirectoryType mounted_subdir = CACHE_TYPE_PERSISTENT; |
| 1098 FilePath mounted_path = GetCacheFilePath( | 1099 FilePath mounted_path = GetCacheFilePath( |
| 1099 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); | 1100 resource_id, md5, mounted_subdir, CACHED_FILE_MOUNTED); |
| 1100 | 1101 |
| 1101 // Determine the source and destination paths for moving the cache blob. | 1102 // Determine the source and destination paths for moving the cache blob. |
| 1102 FilePath source_path; | 1103 FilePath source_path; |
| 1103 CacheSubDirectoryType dest_subdir; | 1104 CacheSubDirectoryType dest_subdir; |
| 1104 int cache_state = cache_entry->cache_state; | 1105 int cache_state = cache_entry.cache_state; |
| 1105 if (to_mount) { | 1106 if (to_mount) { |
| 1106 source_path = unmounted_path; | 1107 source_path = unmounted_path; |
| 1107 *cache_file_path = mounted_path; | 1108 *cache_file_path = mounted_path; |
| 1108 dest_subdir = mounted_subdir; | 1109 dest_subdir = mounted_subdir; |
| 1109 cache_state = SetCacheMounted(cache_state); | 1110 cache_state = SetCacheMounted(cache_state); |
| 1110 } else { | 1111 } else { |
| 1111 source_path = mounted_path; | 1112 source_path = mounted_path; |
| 1112 *cache_file_path = unmounted_path; | 1113 *cache_file_path = unmounted_path; |
| 1113 dest_subdir = unmounted_subdir; | 1114 dest_subdir = unmounted_subdir; |
| 1114 cache_state = ClearCacheMounted(cache_state); | 1115 cache_state = ClearCacheMounted(cache_state); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1132 base::PlatformFileError* error, | 1133 base::PlatformFileError* error, |
| 1133 FilePath* cache_file_path) { | 1134 FilePath* cache_file_path) { |
| 1134 AssertOnSequencedWorkerPool(); | 1135 AssertOnSequencedWorkerPool(); |
| 1135 DCHECK(error); | 1136 DCHECK(error); |
| 1136 DCHECK(cache_file_path); | 1137 DCHECK(cache_file_path); |
| 1137 | 1138 |
| 1138 // If file has already been marked dirty in previous instance of chrome, we | 1139 // If file has already been marked dirty in previous instance of chrome, we |
| 1139 // would have lost the md5 info during cache initialization, because the file | 1140 // would have lost the md5 info during cache initialization, because the file |
| 1140 // would have been renamed to .local extension. | 1141 // would have been renamed to .local extension. |
| 1141 // So, search for entry in cache without comparing md5. | 1142 // So, search for entry in cache without comparing md5. |
| 1142 scoped_ptr<CacheEntry> cache_entry = | 1143 CacheEntry cache_entry; |
|
achuithb
2012/07/11 19:09:59
same.
hashimoto
2012/07/12 05:15:19
Done.
| |
| 1143 GetCacheEntry(resource_id, std::string()); | |
| 1144 | 1144 |
| 1145 // Marking a file dirty means its entry and actual file blob must exist in | 1145 // Marking a file dirty means its entry and actual file blob must exist in |
| 1146 // cache. | 1146 // cache. |
| 1147 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1147 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1148 !cache_entry.IsPresent()) { | |
| 1148 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" | 1149 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" |
| 1149 << resource_id | 1150 << resource_id |
| 1150 << ", md5=" << md5; | 1151 << ", md5=" << md5; |
| 1151 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1152 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1152 return; | 1153 return; |
| 1153 } | 1154 } |
| 1154 | 1155 |
| 1155 // If a file is already dirty (i.e. MarkDirtyInCache was called before), | 1156 // If a file is already dirty (i.e. MarkDirtyInCache was called before), |
| 1156 // delete outgoing symlink if it exists. | 1157 // delete outgoing symlink if it exists. |
| 1157 // TODO(benchan): We should only delete outgoing symlink if file is currently | 1158 // TODO(benchan): We should only delete outgoing symlink if file is currently |
| 1158 // not being uploaded. However, for now, cache doesn't know if uploading of a | 1159 // not being uploaded. However, for now, cache doesn't know if uploading of a |
| 1159 // file is in progress. Per zel, the upload process should be canceled before | 1160 // file is in progress. Per zel, the upload process should be canceled before |
| 1160 // MarkDirtyInCache is called again. | 1161 // MarkDirtyInCache is called again. |
| 1161 if (cache_entry->IsDirty()) { | 1162 if (cache_entry.IsDirty()) { |
| 1162 // The file must be in persistent dir. | 1163 // The file must be in persistent dir. |
| 1163 DCHECK(cache_entry->IsPersistent()); | 1164 DCHECK(cache_entry.IsPersistent()); |
| 1164 | 1165 |
| 1165 // Determine symlink path in outgoing dir, so as to remove it. | 1166 // Determine symlink path in outgoing dir, so as to remove it. |
| 1166 FilePath symlink_path = GetCacheFilePath( | 1167 FilePath symlink_path = GetCacheFilePath( |
| 1167 resource_id, | 1168 resource_id, |
| 1168 std::string(), | 1169 std::string(), |
| 1169 CACHE_TYPE_OUTGOING, | 1170 CACHE_TYPE_OUTGOING, |
| 1170 CACHED_FILE_FROM_SERVER); | 1171 CACHED_FILE_FROM_SERVER); |
| 1171 | 1172 |
| 1172 // We're not moving files here, so simply use empty FilePath for both | 1173 // We're not moving files here, so simply use empty FilePath for both |
| 1173 // |source_path| and |dest_path| because ModifyCacheState only move files | 1174 // |source_path| and |dest_path| because ModifyCacheState only move files |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1189 } | 1190 } |
| 1190 return; | 1191 return; |
| 1191 } | 1192 } |
| 1192 | 1193 |
| 1193 // Move file to persistent dir with new .local extension. | 1194 // Move file to persistent dir with new .local extension. |
| 1194 | 1195 |
| 1195 // Get the current path of the file in cache. | 1196 // Get the current path of the file in cache. |
| 1196 FilePath source_path = GetCacheFilePath( | 1197 FilePath source_path = GetCacheFilePath( |
| 1197 resource_id, | 1198 resource_id, |
| 1198 md5, | 1199 md5, |
| 1199 cache_entry->GetSubDirectoryType(), | 1200 cache_entry.GetSubDirectoryType(), |
| 1200 CACHED_FILE_FROM_SERVER); | 1201 CACHED_FILE_FROM_SERVER); |
| 1201 | 1202 |
| 1202 // Determine destination path. | 1203 // Determine destination path. |
| 1203 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; | 1204 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; |
| 1204 *cache_file_path = GetCacheFilePath(resource_id, | 1205 *cache_file_path = GetCacheFilePath(resource_id, |
| 1205 md5, | 1206 md5, |
| 1206 sub_dir_type, | 1207 sub_dir_type, |
| 1207 CACHED_FILE_LOCALLY_MODIFIED); | 1208 CACHED_FILE_LOCALLY_MODIFIED); |
| 1208 | 1209 |
| 1209 // If file is pinned, update symlink in pinned dir. | 1210 // If file is pinned, update symlink in pinned dir. |
| 1210 FilePath symlink_path; | 1211 FilePath symlink_path; |
| 1211 if (cache_entry->IsPinned()) { | 1212 if (cache_entry.IsPinned()) { |
| 1212 symlink_path = GetCacheFilePath(resource_id, | 1213 symlink_path = GetCacheFilePath(resource_id, |
| 1213 std::string(), | 1214 std::string(), |
| 1214 CACHE_TYPE_PINNED, | 1215 CACHE_TYPE_PINNED, |
| 1215 CACHED_FILE_FROM_SERVER); | 1216 CACHED_FILE_FROM_SERVER); |
| 1216 } | 1217 } |
| 1217 | 1218 |
| 1218 *error = ModifyCacheState( | 1219 *error = ModifyCacheState( |
| 1219 source_path, | 1220 source_path, |
| 1220 *cache_file_path, | 1221 *cache_file_path, |
| 1221 file_operation_type, | 1222 file_operation_type, |
| 1222 symlink_path, | 1223 symlink_path, |
| 1223 !symlink_path.empty() /* create symlink */); | 1224 !symlink_path.empty() /* create symlink */); |
| 1224 | 1225 |
| 1225 if (*error == base::PLATFORM_FILE_OK) { | 1226 if (*error == base::PLATFORM_FILE_OK) { |
| 1226 // Now that file operations have completed, update cache map. | 1227 // Now that file operations have completed, update cache map. |
| 1227 int cache_state = SetCacheDirty(cache_entry->cache_state); | 1228 int cache_state = SetCacheDirty(cache_entry.cache_state); |
| 1228 UpdateCacheWithSubDirectoryType(resource_id, | 1229 UpdateCacheWithSubDirectoryType(resource_id, |
| 1229 md5, | 1230 md5, |
| 1230 sub_dir_type, | 1231 sub_dir_type, |
| 1231 cache_state); | 1232 cache_state); |
| 1232 } | 1233 } |
| 1233 } | 1234 } |
| 1234 | 1235 |
| 1235 void GDataCache::CommitDirty(const std::string& resource_id, | 1236 void GDataCache::CommitDirty(const std::string& resource_id, |
| 1236 const std::string& md5, | 1237 const std::string& md5, |
| 1237 FileOperationType file_operation_type, | 1238 FileOperationType file_operation_type, |
| 1238 base::PlatformFileError* error) { | 1239 base::PlatformFileError* error) { |
| 1239 AssertOnSequencedWorkerPool(); | 1240 AssertOnSequencedWorkerPool(); |
| 1240 DCHECK(error); | 1241 DCHECK(error); |
| 1241 | 1242 |
| 1242 // If file has already been marked dirty in previous instance of chrome, we | 1243 // If file has already been marked dirty in previous instance of chrome, we |
| 1243 // would have lost the md5 info during cache initialization, because the file | 1244 // would have lost the md5 info during cache initialization, because the file |
| 1244 // would have been renamed to .local extension. | 1245 // would have been renamed to .local extension. |
| 1245 // So, search for entry in cache without comparing md5. | 1246 // So, search for entry in cache without comparing md5. |
| 1246 scoped_ptr<CacheEntry> cache_entry = | 1247 CacheEntry cache_entry; |
|
achuithb
2012/07/11 19:09:59
same
hashimoto
2012/07/12 05:15:19
Done.
| |
| 1247 GetCacheEntry(resource_id, std::string()); | |
| 1248 | 1248 |
| 1249 // Committing a file dirty means its entry and actual file blob must exist in | 1249 // Committing a file dirty means its entry and actual file blob must exist in |
| 1250 // cache. | 1250 // cache. |
| 1251 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1251 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1252 !cache_entry.IsPresent()) { | |
| 1252 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" | 1253 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" |
| 1253 << resource_id | 1254 << resource_id |
| 1254 << ", md5=" << md5; | 1255 << ", md5=" << md5; |
| 1255 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1256 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1256 return; | 1257 return; |
| 1257 } | 1258 } |
| 1258 | 1259 |
| 1259 // If a file is not dirty (it should have been marked dirty via | 1260 // If a file is not dirty (it should have been marked dirty via |
| 1260 // MarkDirtyInCache), committing it dirty is an invalid operation. | 1261 // MarkDirtyInCache), committing it dirty is an invalid operation. |
| 1261 if (!cache_entry->IsDirty()) { | 1262 if (!cache_entry.IsDirty()) { |
| 1262 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" | 1263 LOG(WARNING) << "Can't commit a non-dirty file: res_id=" |
| 1263 << resource_id | 1264 << resource_id |
| 1264 << ", md5=" << md5; | 1265 << ", md5=" << md5; |
| 1265 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1266 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 1266 return; | 1267 return; |
| 1267 } | 1268 } |
| 1268 | 1269 |
| 1269 // Dirty files must be in persistent dir. | 1270 // Dirty files must be in persistent dir. |
| 1270 DCHECK(cache_entry->IsPersistent()); | 1271 DCHECK(cache_entry.IsPersistent()); |
| 1271 | 1272 |
| 1272 // Create symlink in outgoing dir. | 1273 // Create symlink in outgoing dir. |
| 1273 FilePath symlink_path = GetCacheFilePath(resource_id, | 1274 FilePath symlink_path = GetCacheFilePath(resource_id, |
| 1274 std::string(), | 1275 std::string(), |
| 1275 CACHE_TYPE_OUTGOING, | 1276 CACHE_TYPE_OUTGOING, |
| 1276 CACHED_FILE_FROM_SERVER); | 1277 CACHED_FILE_FROM_SERVER); |
| 1277 | 1278 |
| 1278 // Get target path of symlink i.e. current path of the file in cache. | 1279 // Get target path of symlink i.e. current path of the file in cache. |
| 1279 FilePath target_path = GetCacheFilePath(resource_id, | 1280 FilePath target_path = GetCacheFilePath(resource_id, |
| 1280 md5, | 1281 md5, |
| 1281 cache_entry->GetSubDirectoryType(), | 1282 cache_entry.GetSubDirectoryType(), |
| 1282 CACHED_FILE_LOCALLY_MODIFIED); | 1283 CACHED_FILE_LOCALLY_MODIFIED); |
| 1283 | 1284 |
| 1284 // Since there's no need to move files, use |target_path| for both | 1285 // Since there's no need to move files, use |target_path| for both |
| 1285 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1286 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
| 1286 // if source and destination are different. | 1287 // if source and destination are different. |
| 1287 *error = ModifyCacheState(target_path, // source | 1288 *error = ModifyCacheState(target_path, // source |
| 1288 target_path, // destination | 1289 target_path, // destination |
| 1289 file_operation_type, | 1290 file_operation_type, |
| 1290 symlink_path, | 1291 symlink_path, |
| 1291 true /* create symlink */); | 1292 true /* create symlink */); |
| 1292 } | 1293 } |
| 1293 | 1294 |
| 1294 void GDataCache::ClearDirty(const std::string& resource_id, | 1295 void GDataCache::ClearDirty(const std::string& resource_id, |
| 1295 const std::string& md5, | 1296 const std::string& md5, |
| 1296 FileOperationType file_operation_type, | 1297 FileOperationType file_operation_type, |
| 1297 base::PlatformFileError* error) { | 1298 base::PlatformFileError* error) { |
| 1298 AssertOnSequencedWorkerPool(); | 1299 AssertOnSequencedWorkerPool(); |
| 1299 DCHECK(error); | 1300 DCHECK(error); |
| 1300 | 1301 |
| 1301 // |md5| is the new .<md5> extension to rename the file to. | 1302 // |md5| is the new .<md5> extension to rename the file to. |
| 1302 // So, search for entry in cache without comparing md5. | 1303 // So, search for entry in cache without comparing md5. |
| 1303 scoped_ptr<CacheEntry> cache_entry = | 1304 CacheEntry cache_entry; |
| 1304 GetCacheEntry(resource_id, std::string()); | |
| 1305 | 1305 |
| 1306 // Clearing a dirty file means its entry and actual file blob must exist in | 1306 // Clearing a dirty file means its entry and actual file blob must exist in |
| 1307 // cache. | 1307 // cache. |
| 1308 if (!cache_entry.get() || !cache_entry->IsPresent()) { | 1308 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || |
| 1309 !cache_entry.IsPresent()) { | |
| 1309 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " | 1310 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " |
| 1310 << "res_id=" << resource_id | 1311 << "res_id=" << resource_id |
| 1311 << ", md5=" << md5; | 1312 << ", md5=" << md5; |
| 1312 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; | 1313 *error = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 1313 return; | 1314 return; |
| 1314 } | 1315 } |
| 1315 | 1316 |
| 1316 // If a file is not dirty (it should have been marked dirty via | 1317 // If a file is not dirty (it should have been marked dirty via |
| 1317 // MarkDirtyInCache), clearing its dirty state is an invalid operation. | 1318 // MarkDirtyInCache), clearing its dirty state is an invalid operation. |
| 1318 if (!cache_entry->IsDirty()) { | 1319 if (!cache_entry.IsDirty()) { |
| 1319 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" | 1320 LOG(WARNING) << "Can't clear dirty state of a non-dirty file: res_id=" |
| 1320 << resource_id | 1321 << resource_id |
| 1321 << ", md5=" << md5; | 1322 << ", md5=" << md5; |
| 1322 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 1323 *error = base::PLATFORM_FILE_ERROR_INVALID_OPERATION; |
| 1323 return; | 1324 return; |
| 1324 } | 1325 } |
| 1325 | 1326 |
| 1326 // File must be dirty and hence in persistent dir. | 1327 // File must be dirty and hence in persistent dir. |
| 1327 DCHECK(cache_entry->IsPersistent()); | 1328 DCHECK(cache_entry.IsPersistent()); |
| 1328 | 1329 |
| 1329 // Get the current path of the file in cache. | 1330 // Get the current path of the file in cache. |
| 1330 FilePath source_path = GetCacheFilePath(resource_id, | 1331 FilePath source_path = GetCacheFilePath(resource_id, |
| 1331 md5, | 1332 md5, |
| 1332 cache_entry->GetSubDirectoryType(), | 1333 cache_entry.GetSubDirectoryType(), |
| 1333 CACHED_FILE_LOCALLY_MODIFIED); | 1334 CACHED_FILE_LOCALLY_MODIFIED); |
| 1334 | 1335 |
| 1335 // Determine destination path. | 1336 // Determine destination path. |
| 1336 // If file is pinned, move it to persistent dir with .md5 extension; | 1337 // If file is pinned, move it to persistent dir with .md5 extension; |
| 1337 // otherwise, move it to tmp dir with .md5 extension. | 1338 // otherwise, move it to tmp dir with .md5 extension. |
| 1338 CacheSubDirectoryType sub_dir_type = | 1339 CacheSubDirectoryType sub_dir_type = |
| 1339 cache_entry->IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1340 cache_entry.IsPinned() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1340 FilePath dest_path = GetCacheFilePath(resource_id, | 1341 FilePath dest_path = GetCacheFilePath(resource_id, |
| 1341 md5, | 1342 md5, |
| 1342 sub_dir_type, | 1343 sub_dir_type, |
| 1343 CACHED_FILE_FROM_SERVER); | 1344 CACHED_FILE_FROM_SERVER); |
| 1344 | 1345 |
| 1345 // Delete symlink in outgoing dir. | 1346 // Delete symlink in outgoing dir. |
| 1346 FilePath symlink_path = GetCacheFilePath(resource_id, | 1347 FilePath symlink_path = GetCacheFilePath(resource_id, |
| 1347 std::string(), | 1348 std::string(), |
| 1348 CACHE_TYPE_OUTGOING, | 1349 CACHE_TYPE_OUTGOING, |
| 1349 CACHED_FILE_FROM_SERVER); | 1350 CACHED_FILE_FROM_SERVER); |
| 1350 | 1351 |
| 1351 *error = ModifyCacheState(source_path, | 1352 *error = ModifyCacheState(source_path, |
| 1352 dest_path, | 1353 dest_path, |
| 1353 file_operation_type, | 1354 file_operation_type, |
| 1354 symlink_path, | 1355 symlink_path, |
| 1355 false /* don't create symlink */); | 1356 false /* don't create symlink */); |
| 1356 | 1357 |
| 1357 // If file is pinned, update symlink in pinned dir. | 1358 // If file is pinned, update symlink in pinned dir. |
| 1358 if (*error == base::PLATFORM_FILE_OK && cache_entry->IsPinned()) { | 1359 if (*error == base::PLATFORM_FILE_OK && cache_entry.IsPinned()) { |
| 1359 symlink_path = GetCacheFilePath(resource_id, | 1360 symlink_path = GetCacheFilePath(resource_id, |
| 1360 std::string(), | 1361 std::string(), |
| 1361 CACHE_TYPE_PINNED, | 1362 CACHE_TYPE_PINNED, |
| 1362 CACHED_FILE_FROM_SERVER); | 1363 CACHED_FILE_FROM_SERVER); |
| 1363 | 1364 |
| 1364 // Since there's no moving of files here, use |dest_path| for both | 1365 // Since there's no moving of files here, use |dest_path| for both |
| 1365 // |source_path| and |dest_path|, because ModifyCacheState only moves files | 1366 // |source_path| and |dest_path|, because ModifyCacheState only moves files |
| 1366 // if source and destination are different. | 1367 // if source and destination are different. |
| 1367 *error = ModifyCacheState(dest_path, // source path | 1368 *error = ModifyCacheState(dest_path, // source path |
| 1368 dest_path, // destination path | 1369 dest_path, // destination path |
| 1369 file_operation_type, | 1370 file_operation_type, |
| 1370 symlink_path, | 1371 symlink_path, |
| 1371 true /* create symlink */); | 1372 true /* create symlink */); |
| 1372 } | 1373 } |
| 1373 | 1374 |
| 1374 if (*error == base::PLATFORM_FILE_OK) { | 1375 if (*error == base::PLATFORM_FILE_OK) { |
| 1375 // Now that file operations have completed, update cache map. | 1376 // Now that file operations have completed, update cache map. |
| 1376 int cache_state = ClearCacheDirty(cache_entry->cache_state); | 1377 int cache_state = ClearCacheDirty(cache_entry.cache_state); |
| 1377 UpdateCacheWithSubDirectoryType(resource_id, | 1378 UpdateCacheWithSubDirectoryType(resource_id, |
| 1378 md5, | 1379 md5, |
| 1379 sub_dir_type, | 1380 sub_dir_type, |
| 1380 cache_state); | 1381 cache_state); |
| 1381 } | 1382 } |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 void GDataCache::Remove(const std::string& resource_id, | 1385 void GDataCache::Remove(const std::string& resource_id, |
| 1385 base::PlatformFileError* error) { | 1386 base::PlatformFileError* error) { |
| 1386 AssertOnSequencedWorkerPool(); | 1387 AssertOnSequencedWorkerPool(); |
| 1387 DCHECK(error); | 1388 DCHECK(error); |
| 1388 | 1389 |
| 1389 // MD5 is not passed into RemoveFromCache and hence | 1390 // MD5 is not passed into RemoveFromCache and hence |
| 1390 // RemoveFromCacheOnBlockingPool, because we would delete all cache files | 1391 // RemoveFromCacheOnBlockingPool, because we would delete all cache files |
| 1391 // corresponding to <resource_id> regardless of the md5. | 1392 // corresponding to <resource_id> regardless of the md5. |
| 1392 // So, search for entry in cache without taking md5 into account. | 1393 // So, search for entry in cache without taking md5 into account. |
| 1393 scoped_ptr<CacheEntry> cache_entry = | 1394 CacheEntry cache_entry; |
| 1394 GetCacheEntry(resource_id, std::string()); | |
| 1395 | 1395 |
| 1396 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. | 1396 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. |
| 1397 if (!cache_entry.get() || | 1397 const bool entry_found = |
| 1398 cache_entry->IsDirty() || | 1398 GetCacheEntry(resource_id, std::string(), &cache_entry); |
| 1399 cache_entry->IsMounted()) { | 1399 if (!entry_found || cache_entry.IsDirty() || cache_entry.IsMounted()) { |
| 1400 DVLOG(1) << "Entry is " | 1400 DVLOG(1) << "Entry is " |
| 1401 << (cache_entry.get() ? | 1401 << (entry_found ? |
| 1402 (cache_entry->IsDirty() ? "dirty" : "mounted") : | 1402 (cache_entry.IsDirty() ? "dirty" : "mounted") : |
| 1403 "non-existent") | 1403 "non-existent") |
| 1404 << " in cache, not removing"; | 1404 << " in cache, not removing"; |
| 1405 *error = base::PLATFORM_FILE_OK; | 1405 *error = base::PLATFORM_FILE_OK; |
| 1406 return; | 1406 return; |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 // Determine paths to delete all cache versions of |resource_id| in | 1409 // Determine paths to delete all cache versions of |resource_id| in |
| 1410 // persistent, tmp and pinned directories. | 1410 // persistent, tmp and pinned directories. |
| 1411 std::vector<FilePath> paths_to_delete; | 1411 std::vector<FilePath> paths_to_delete; |
| 1412 | 1412 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1499 } | 1499 } |
| 1500 | 1500 |
| 1501 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, | 1501 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, |
| 1502 const std::string& md5, | 1502 const std::string& md5, |
| 1503 bool* success, | 1503 bool* success, |
| 1504 GDataCache::CacheEntry* cache_entry) { | 1504 GDataCache::CacheEntry* cache_entry) { |
| 1505 AssertOnSequencedWorkerPool(); | 1505 AssertOnSequencedWorkerPool(); |
| 1506 DCHECK(success); | 1506 DCHECK(success); |
| 1507 DCHECK(cache_entry); | 1507 DCHECK(cache_entry); |
| 1508 | 1508 |
| 1509 scoped_ptr<GDataCache::CacheEntry> value(GetCacheEntry(resource_id, md5)); | 1509 *success = GetCacheEntry(resource_id, md5, cache_entry); |
| 1510 *success = value.get(); | |
| 1511 if (*success) | |
| 1512 *cache_entry = *value; | |
| 1513 } | 1510 } |
| 1514 | 1511 |
| 1515 void GDataCache::UpdateCacheWithSubDirectoryType( | 1512 void GDataCache::UpdateCacheWithSubDirectoryType( |
| 1516 const std::string& resource_id, | 1513 const std::string& resource_id, |
| 1517 const std::string& md5, | 1514 const std::string& md5, |
| 1518 CacheSubDirectoryType sub_dir_type, | 1515 CacheSubDirectoryType sub_dir_type, |
| 1519 int cache_state) { | 1516 int cache_state) { |
| 1520 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT || | 1517 DCHECK(sub_dir_type == CACHE_TYPE_PERSISTENT || |
| 1521 sub_dir_type == CACHE_TYPE_TMP); | 1518 sub_dir_type == CACHE_TYPE_TMP); |
| 1522 | 1519 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 } | 1568 } |
| 1572 return success; | 1569 return success; |
| 1573 } | 1570 } |
| 1574 | 1571 |
| 1575 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1572 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1576 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1573 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1577 global_free_disk_getter_for_testing = getter; | 1574 global_free_disk_getter_for_testing = getter; |
| 1578 } | 1575 } |
| 1579 | 1576 |
| 1580 } // namespace gdata | 1577 } // namespace gdata |
| OLD | NEW |