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

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

Issue 10836354: Rename GData* to Drive* in gdata.proto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/chromeos/chromeos_version.h" 9 #include "base/chromeos/chromeos_version.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/sys_info.h" 15 #include "base/sys_info.h"
16 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 16 #include "chrome/browser/chromeos/gdata/drive.pb.h"
17 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" 17 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h"
18 #include "chrome/browser/chromeos/gdata/gdata_util.h" 18 #include "chrome/browser/chromeos/gdata/gdata_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_paths_internal.h" 21 #include "chrome/common/chrome_paths_internal.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace gdata { 26 namespace gdata {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DVLOG(1) << "Deleted " << current.value(); 188 DVLOG(1) << "Deleted " << current.value();
189 } 189 }
190 } 190 }
191 191
192 // Appends |resource_id| ID to |to_fetch| if the file is pinned but not 192 // Appends |resource_id| ID to |to_fetch| if the file is pinned but not
193 // fetched (not present locally), or to |to_upload| if the file is dirty 193 // fetched (not present locally), or to |to_upload| if the file is dirty
194 // but not uploaded. 194 // but not uploaded.
195 void CollectBacklog(std::vector<std::string>* to_fetch, 195 void CollectBacklog(std::vector<std::string>* to_fetch,
196 std::vector<std::string>* to_upload, 196 std::vector<std::string>* to_upload,
197 const std::string& resource_id, 197 const std::string& resource_id,
198 const GDataCacheEntry& cache_entry) { 198 const DriveCacheEntry& cache_entry) {
199 DCHECK(to_fetch); 199 DCHECK(to_fetch);
200 DCHECK(to_upload); 200 DCHECK(to_upload);
201 201
202 if (cache_entry.is_pinned() && !cache_entry.is_present()) 202 if (cache_entry.is_pinned() && !cache_entry.is_present())
203 to_fetch->push_back(resource_id); 203 to_fetch->push_back(resource_id);
204 204
205 if (cache_entry.is_dirty()) 205 if (cache_entry.is_dirty())
206 to_upload->push_back(resource_id); 206 to_upload->push_back(resource_id);
207 } 207 }
208 208
209 // Appends |resource_id| ID to |resource_ids| if the file is pinned and 209 // Appends |resource_id| ID to |resource_ids| if the file is pinned and
210 // present (cached locally). 210 // present (cached locally).
211 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids, 211 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids,
212 const std::string& resource_id, 212 const std::string& resource_id,
213 const GDataCacheEntry& cache_entry) { 213 const DriveCacheEntry& cache_entry) {
214 DCHECK(resource_ids); 214 DCHECK(resource_ids);
215 215
216 if (cache_entry.is_pinned() && cache_entry.is_present()) 216 if (cache_entry.is_pinned() && cache_entry.is_present())
217 resource_ids->push_back(resource_id); 217 resource_ids->push_back(resource_id);
218 } 218 }
219 219
220 // Appends |resource_id| ID to |resource_ids| unconditionally. 220 // Appends |resource_id| ID to |resource_ids| unconditionally.
221 void CollectAnyFile(std::vector<std::string>* resource_ids, 221 void CollectAnyFile(std::vector<std::string>* resource_ids,
222 const std::string& resource_id, 222 const std::string& resource_id,
223 const GDataCacheEntry& /* cache_entry */) { 223 const DriveCacheEntry& /* cache_entry */) {
224 DCHECK(resource_ids); 224 DCHECK(resource_ids);
225 225
226 resource_ids->push_back(resource_id); 226 resource_ids->push_back(resource_id);
227 } 227 }
228 228
229 // Runs callback with pointers dereferenced. 229 // Runs callback with pointers dereferenced.
230 // Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread. 230 // Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread.
231 void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, 231 void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback,
232 const GDataFileError* error, 232 const GDataFileError* error,
233 const FilePath* cache_file_path) { 233 const FilePath* cache_file_path) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 if (!callback.is_null()) 292 if (!callback.is_null())
293 callback.Run(*resource_ids); 293 callback.Run(*resource_ids);
294 } 294 }
295 295
296 // Runs callback with pointers dereferenced. 296 // Runs callback with pointers dereferenced.
297 // Used to implement GetCacheEntryOnUIThread(). 297 // Used to implement GetCacheEntryOnUIThread().
298 void RunGetCacheEntryCallback( 298 void RunGetCacheEntryCallback(
299 const GetCacheEntryCallback& callback, 299 const GetCacheEntryCallback& callback,
300 bool* success, 300 bool* success,
301 GDataCacheEntry* cache_entry) { 301 DriveCacheEntry* cache_entry) {
302 DCHECK(success); 302 DCHECK(success);
303 DCHECK(cache_entry); 303 DCHECK(cache_entry);
304 304
305 if (!callback.is_null()) 305 if (!callback.is_null())
306 callback.Run(*success, *cache_entry); 306 callback.Run(*success, *cache_entry);
307 } 307 }
308 308
309 } // namespace 309 } // namespace
310 310
311 GDataCache::GDataCache(const FilePath& cache_root_path, 311 GDataCache::GDataCache(const FilePath& cache_root_path,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 observers_.RemoveObserver(observer); 375 observers_.RemoveObserver(observer);
376 } 376 }
377 377
378 void GDataCache::GetCacheEntryOnUIThread( 378 void GDataCache::GetCacheEntryOnUIThread(
379 const std::string& resource_id, 379 const std::string& resource_id,
380 const std::string& md5, 380 const std::string& md5,
381 const GetCacheEntryCallback& callback) { 381 const GetCacheEntryCallback& callback) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 383
384 bool* success = new bool(false); 384 bool* success = new bool(false);
385 GDataCacheEntry* cache_entry = new GDataCacheEntry; 385 DriveCacheEntry* cache_entry = new DriveCacheEntry;
386 blocking_task_runner_->PostTaskAndReply( 386 blocking_task_runner_->PostTaskAndReply(
387 FROM_HERE, 387 FROM_HERE,
388 base::Bind(&GDataCache::GetCacheEntryHelper, 388 base::Bind(&GDataCache::GetCacheEntryHelper,
389 base::Unretained(this), 389 base::Unretained(this),
390 resource_id, 390 resource_id,
391 md5, 391 md5,
392 success, 392 success,
393 cache_entry), 393 cache_entry),
394 base::Bind(&RunGetCacheEntryCallback, 394 base::Bind(&RunGetCacheEntryCallback,
395 callback, 395 callback,
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 void GDataCache::ForceRescanOnUIThreadForTesting() { 706 void GDataCache::ForceRescanOnUIThreadForTesting() {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708 708
709 blocking_task_runner_->PostTask( 709 blocking_task_runner_->PostTask(
710 FROM_HERE, 710 FROM_HERE,
711 base::Bind(&GDataCache::ForceRescanForTesting, base::Unretained(this))); 711 base::Bind(&GDataCache::ForceRescanForTesting, base::Unretained(this)));
712 } 712 }
713 713
714 bool GDataCache::GetCacheEntry(const std::string& resource_id, 714 bool GDataCache::GetCacheEntry(const std::string& resource_id,
715 const std::string& md5, 715 const std::string& md5,
716 GDataCacheEntry* entry) { 716 DriveCacheEntry* entry) {
717 DCHECK(entry); 717 DCHECK(entry);
718 AssertOnSequencedWorkerPool(); 718 AssertOnSequencedWorkerPool();
719 return metadata_->GetCacheEntry(resource_id, md5, entry); 719 return metadata_->GetCacheEntry(resource_id, md5, entry);
720 } 720 }
721 721
722 // static 722 // static
723 GDataCache* GDataCache::CreateGDataCacheOnUIThread( 723 GDataCache* GDataCache::CreateGDataCacheOnUIThread(
724 const FilePath& cache_root_path, 724 const FilePath& cache_root_path,
725 base::SequencedTaskRunner* blocking_task_runner) { 725 base::SequencedTaskRunner* blocking_task_runner) {
726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 } 795 }
796 796
797 void GDataCache::GetFile(const std::string& resource_id, 797 void GDataCache::GetFile(const std::string& resource_id,
798 const std::string& md5, 798 const std::string& md5,
799 GDataFileError* error, 799 GDataFileError* error,
800 FilePath* cache_file_path) { 800 FilePath* cache_file_path) {
801 AssertOnSequencedWorkerPool(); 801 AssertOnSequencedWorkerPool();
802 DCHECK(error); 802 DCHECK(error);
803 DCHECK(cache_file_path); 803 DCHECK(cache_file_path);
804 804
805 GDataCacheEntry cache_entry; 805 DriveCacheEntry cache_entry;
806 if (GetCacheEntry(resource_id, md5, &cache_entry) && 806 if (GetCacheEntry(resource_id, md5, &cache_entry) &&
807 cache_entry.is_present()) { 807 cache_entry.is_present()) {
808 CachedFileOrigin file_origin; 808 CachedFileOrigin file_origin;
809 if (cache_entry.is_mounted()) { 809 if (cache_entry.is_mounted()) {
810 file_origin = CACHED_FILE_MOUNTED; 810 file_origin = CACHED_FILE_MOUNTED;
811 } else if (cache_entry.is_dirty()) { 811 } else if (cache_entry.is_dirty()) {
812 file_origin = CACHED_FILE_LOCALLY_MODIFIED; 812 file_origin = CACHED_FILE_LOCALLY_MODIFIED;
813 } else { 813 } else {
814 file_origin = CACHED_FILE_FROM_SERVER; 814 file_origin = CACHED_FILE_FROM_SERVER;
815 } 815 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 return; 847 return;
848 } 848 }
849 } 849 }
850 850
851 FilePath dest_path; 851 FilePath dest_path;
852 FilePath symlink_path; 852 FilePath symlink_path;
853 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP; 853 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_TMP;
854 854
855 // If file was previously pinned, store it in persistent dir and create 855 // If file was previously pinned, store it in persistent dir and create
856 // symlink in pinned dir. 856 // symlink in pinned dir.
857 GDataCacheEntry cache_entry; 857 DriveCacheEntry cache_entry;
858 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache. 858 if (GetCacheEntry(resource_id, md5, &cache_entry)) { // File exists in cache.
859 // If file is dirty or mounted, return error. 859 // If file is dirty or mounted, return error.
860 if (cache_entry.is_dirty() || cache_entry.is_mounted()) { 860 if (cache_entry.is_dirty() || cache_entry.is_mounted()) {
861 LOG(WARNING) << "Can't store a file to replace a " 861 LOG(WARNING) << "Can't store a file to replace a "
862 << (cache_entry.is_dirty() ? "dirty" : "mounted") 862 << (cache_entry.is_dirty() ? "dirty" : "mounted")
863 << " file: res_id=" << resource_id 863 << " file: res_id=" << resource_id
864 << ", md5=" << md5; 864 << ", md5=" << md5;
865 *error = GDATA_FILE_ERROR_IN_USE; 865 *error = GDATA_FILE_ERROR_IN_USE;
866 return; 866 return;
867 } 867 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 GDataFileError* error) { 927 GDataFileError* error) {
928 AssertOnSequencedWorkerPool(); 928 AssertOnSequencedWorkerPool();
929 DCHECK(error); 929 DCHECK(error);
930 930
931 FilePath source_path; 931 FilePath source_path;
932 FilePath dest_path; 932 FilePath dest_path;
933 FilePath symlink_path; 933 FilePath symlink_path;
934 bool create_symlink = true; 934 bool create_symlink = true;
935 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT; 935 CacheSubDirectoryType sub_dir_type = CACHE_TYPE_PERSISTENT;
936 936
937 GDataCacheEntry cache_entry; 937 DriveCacheEntry cache_entry;
938 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { 938 if (!GetCacheEntry(resource_id, md5, &cache_entry)) {
939 // Entry does not exist in cache. 939 // Entry does not exist in cache.
940 // Set both |dest_path| and |source_path| to /dev/null, so that: 940 // Set both |dest_path| and |source_path| to /dev/null, so that:
941 // 1) ModifyCacheState won't move files when |source_path| and |dest_path| 941 // 1) ModifyCacheState won't move files when |source_path| and |dest_path|
942 // are the same. 942 // are the same.
943 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download 943 // 2) symlinks to /dev/null will be picked up by GDataSyncClient to download
944 // pinned files that don't exist in cache. 944 // pinned files that don't exist in cache.
945 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull); 945 dest_path = FilePath::FromUTF8Unsafe(util::kSymLinkToDevNull);
946 source_path = dest_path; 946 source_path = dest_path;
947 947
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 } 1009 }
1010 1010
1011 void GDataCache::Unpin(const std::string& resource_id, 1011 void GDataCache::Unpin(const std::string& resource_id,
1012 const std::string& md5, 1012 const std::string& md5,
1013 FileOperationType file_operation_type, 1013 FileOperationType file_operation_type,
1014 GDataFileError* error) { 1014 GDataFileError* error) {
1015 AssertOnSequencedWorkerPool(); 1015 AssertOnSequencedWorkerPool();
1016 DCHECK(error); 1016 DCHECK(error);
1017 1017
1018 // Unpinning a file means its entry must exist in cache. 1018 // Unpinning a file means its entry must exist in cache.
1019 GDataCacheEntry cache_entry; 1019 DriveCacheEntry cache_entry;
1020 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { 1020 if (!GetCacheEntry(resource_id, md5, &cache_entry)) {
1021 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id=" 1021 LOG(WARNING) << "Can't unpin a file that wasn't pinned or cached: res_id="
1022 << resource_id 1022 << resource_id
1023 << ", md5=" << md5; 1023 << ", md5=" << md5;
1024 *error = GDATA_FILE_ERROR_NOT_FOUND; 1024 *error = GDATA_FILE_ERROR_NOT_FOUND;
1025 return; 1025 return;
1026 } 1026 }
1027 1027
1028 // Entry exists in cache, determines source and destination paths. 1028 // Entry exists in cache, determines source and destination paths.
1029 1029
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 1103
1104 // Parse file path to obtain resource_id, md5 and extra_extension. 1104 // Parse file path to obtain resource_id, md5 and extra_extension.
1105 std::string resource_id; 1105 std::string resource_id;
1106 std::string md5; 1106 std::string md5;
1107 std::string extra_extension; 1107 std::string extra_extension;
1108 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension); 1108 util::ParseCacheFilePath(file_path, &resource_id, &md5, &extra_extension);
1109 // The extra_extension shall be ".mounted" iff we're unmounting. 1109 // The extra_extension shall be ".mounted" iff we're unmounting.
1110 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension)); 1110 DCHECK(!to_mount == (extra_extension == util::kMountedArchiveFileExtension));
1111 1111
1112 // Get cache entry associated with the resource_id and md5 1112 // Get cache entry associated with the resource_id and md5
1113 GDataCacheEntry cache_entry; 1113 DriveCacheEntry cache_entry;
1114 if (!GetCacheEntry(resource_id, md5, &cache_entry)) { 1114 if (!GetCacheEntry(resource_id, md5, &cache_entry)) {
1115 *error = GDATA_FILE_ERROR_NOT_FOUND; 1115 *error = GDATA_FILE_ERROR_NOT_FOUND;
1116 return; 1116 return;
1117 } 1117 }
1118 if (to_mount == cache_entry.is_mounted()) { 1118 if (to_mount == cache_entry.is_mounted()) {
1119 *error = GDATA_FILE_ERROR_INVALID_OPERATION; 1119 *error = GDATA_FILE_ERROR_INVALID_OPERATION;
1120 return; 1120 return;
1121 } 1121 }
1122 1122
1123 // Get the subdir type and path for the unmounted state. 1123 // Get the subdir type and path for the unmounted state.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 DCHECK(error); 1166 DCHECK(error);
1167 DCHECK(cache_file_path); 1167 DCHECK(cache_file_path);
1168 1168
1169 // If file has already been marked dirty in previous instance of chrome, we 1169 // If file has already been marked dirty in previous instance of chrome, we
1170 // would have lost the md5 info during cache initialization, because the file 1170 // would have lost the md5 info during cache initialization, because the file
1171 // would have been renamed to .local extension. 1171 // would have been renamed to .local extension.
1172 // So, search for entry in cache without comparing md5. 1172 // So, search for entry in cache without comparing md5.
1173 1173
1174 // Marking a file dirty means its entry and actual file blob must exist in 1174 // Marking a file dirty means its entry and actual file blob must exist in
1175 // cache. 1175 // cache.
1176 GDataCacheEntry cache_entry; 1176 DriveCacheEntry cache_entry;
1177 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || 1177 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) ||
1178 !cache_entry.is_present()) { 1178 !cache_entry.is_present()) {
1179 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" 1179 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id="
1180 << resource_id 1180 << resource_id
1181 << ", md5=" << md5; 1181 << ", md5=" << md5;
1182 *error = GDATA_FILE_ERROR_NOT_FOUND; 1182 *error = GDATA_FILE_ERROR_NOT_FOUND;
1183 return; 1183 return;
1184 } 1184 }
1185 1185
1186 // If a file is already dirty (i.e. MarkDirtyInCache was called before), 1186 // If a file is already dirty (i.e. MarkDirtyInCache was called before),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 AssertOnSequencedWorkerPool(); 1269 AssertOnSequencedWorkerPool();
1270 DCHECK(error); 1270 DCHECK(error);
1271 1271
1272 // If file has already been marked dirty in previous instance of chrome, we 1272 // If file has already been marked dirty in previous instance of chrome, we
1273 // would have lost the md5 info during cache initialization, because the file 1273 // would have lost the md5 info during cache initialization, because the file
1274 // would have been renamed to .local extension. 1274 // would have been renamed to .local extension.
1275 // So, search for entry in cache without comparing md5. 1275 // So, search for entry in cache without comparing md5.
1276 1276
1277 // Committing a file dirty means its entry and actual file blob must exist in 1277 // Committing a file dirty means its entry and actual file blob must exist in
1278 // cache. 1278 // cache.
1279 GDataCacheEntry cache_entry; 1279 DriveCacheEntry cache_entry;
1280 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || 1280 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) ||
1281 !cache_entry.is_present()) { 1281 !cache_entry.is_present()) {
1282 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id=" 1282 LOG(WARNING) << "Can't commit dirty a file that wasn't cached: res_id="
1283 << resource_id 1283 << resource_id
1284 << ", md5=" << md5; 1284 << ", md5=" << md5;
1285 *error = GDATA_FILE_ERROR_NOT_FOUND; 1285 *error = GDATA_FILE_ERROR_NOT_FOUND;
1286 return; 1286 return;
1287 } 1287 }
1288 1288
1289 // If a file is not dirty (it should have been marked dirty via 1289 // If a file is not dirty (it should have been marked dirty via
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1323
1324 void GDataCache::ClearDirty(const std::string& resource_id, 1324 void GDataCache::ClearDirty(const std::string& resource_id,
1325 const std::string& md5, 1325 const std::string& md5,
1326 FileOperationType file_operation_type, 1326 FileOperationType file_operation_type,
1327 GDataFileError* error) { 1327 GDataFileError* error) {
1328 AssertOnSequencedWorkerPool(); 1328 AssertOnSequencedWorkerPool();
1329 DCHECK(error); 1329 DCHECK(error);
1330 1330
1331 // |md5| is the new .<md5> extension to rename the file to. 1331 // |md5| is the new .<md5> extension to rename the file to.
1332 // So, search for entry in cache without comparing md5. 1332 // So, search for entry in cache without comparing md5.
1333 GDataCacheEntry cache_entry; 1333 DriveCacheEntry cache_entry;
1334 1334
1335 // Clearing a dirty file means its entry and actual file blob must exist in 1335 // Clearing a dirty file means its entry and actual file blob must exist in
1336 // cache. 1336 // cache.
1337 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) || 1337 if (!GetCacheEntry(resource_id, std::string(), &cache_entry) ||
1338 !cache_entry.is_present()) { 1338 !cache_entry.is_present()) {
1339 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: " 1339 LOG(WARNING) << "Can't clear dirty state of a file that wasn't cached: "
1340 << "res_id=" << resource_id 1340 << "res_id=" << resource_id
1341 << ", md5=" << md5; 1341 << ", md5=" << md5;
1342 *error = GDATA_FILE_ERROR_NOT_FOUND; 1342 *error = GDATA_FILE_ERROR_NOT_FOUND;
1343 return; 1343 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 } 1411 }
1412 1412
1413 void GDataCache::Remove(const std::string& resource_id, 1413 void GDataCache::Remove(const std::string& resource_id,
1414 GDataFileError* error) { 1414 GDataFileError* error) {
1415 AssertOnSequencedWorkerPool(); 1415 AssertOnSequencedWorkerPool();
1416 DCHECK(error); 1416 DCHECK(error);
1417 1417
1418 // MD5 is not passed into RemoveCacheEntry because we would delete all 1418 // MD5 is not passed into RemoveCacheEntry because we would delete all
1419 // cache files corresponding to <resource_id> regardless of the md5. 1419 // cache files corresponding to <resource_id> regardless of the md5.
1420 // So, search for entry in cache without taking md5 into account. 1420 // So, search for entry in cache without taking md5 into account.
1421 GDataCacheEntry cache_entry; 1421 DriveCacheEntry cache_entry;
1422 1422
1423 // If entry doesn't exist or is dirty or mounted in cache, nothing to do. 1423 // If entry doesn't exist or is dirty or mounted in cache, nothing to do.
1424 const bool entry_found = 1424 const bool entry_found =
1425 GetCacheEntry(resource_id, std::string(), &cache_entry); 1425 GetCacheEntry(resource_id, std::string(), &cache_entry);
1426 if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) { 1426 if (!entry_found || cache_entry.is_dirty() || cache_entry.is_mounted()) {
1427 DVLOG(1) << "Entry is " 1427 DVLOG(1) << "Entry is "
1428 << (entry_found ? 1428 << (entry_found ?
1429 (cache_entry.is_dirty() ? "dirty" : "mounted") : 1429 (cache_entry.is_dirty() ? "dirty" : "mounted") :
1430 "non-existent") 1430 "non-existent")
1431 << " in cache, not removing"; 1431 << " in cache, not removing";
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 if (!callback.is_null()) 1531 if (!callback.is_null())
1532 callback.Run(*error, resource_id, md5); 1532 callback.Run(*error, resource_id, md5);
1533 1533
1534 if (*error == GDATA_FILE_OK) 1534 if (*error == GDATA_FILE_OK)
1535 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); 1535 FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id));
1536 } 1536 }
1537 1537
1538 void GDataCache::GetCacheEntryHelper(const std::string& resource_id, 1538 void GDataCache::GetCacheEntryHelper(const std::string& resource_id,
1539 const std::string& md5, 1539 const std::string& md5,
1540 bool* success, 1540 bool* success,
1541 GDataCacheEntry* cache_entry) { 1541 DriveCacheEntry* cache_entry) {
1542 AssertOnSequencedWorkerPool(); 1542 AssertOnSequencedWorkerPool();
1543 DCHECK(success); 1543 DCHECK(success);
1544 DCHECK(cache_entry); 1544 DCHECK(cache_entry);
1545 1545
1546 *success = GetCacheEntry(resource_id, md5, cache_entry); 1546 *success = GetCacheEntry(resource_id, md5, cache_entry);
1547 } 1547 }
1548 1548
1549 // static 1549 // static
1550 FilePath GDataCache::GetCacheRootPath(Profile* profile) { 1550 FilePath GDataCache::GetCacheRootPath(Profile* profile) {
1551 FilePath cache_base_path; 1551 FilePath cache_base_path;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value(); 1585 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value();
1586 } else { 1586 } else {
1587 DVLOG(1) << "Created directory " << paths_to_create[i].value(); 1587 DVLOG(1) << "Created directory " << paths_to_create[i].value();
1588 } 1588 }
1589 } 1589 }
1590 return success; 1590 return success;
1591 } 1591 }
1592 1592
1593 // static 1593 // static
1594 GDataCache::CacheSubDirectoryType GDataCache::GetSubDirectoryType( 1594 GDataCache::CacheSubDirectoryType GDataCache::GetSubDirectoryType(
1595 const GDataCacheEntry& cache_entry) { 1595 const DriveCacheEntry& cache_entry) {
1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; 1596 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP;
1597 } 1597 }
1598 1598
1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 1599 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 1600 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
1601 global_free_disk_getter_for_testing = getter; 1601 global_free_disk_getter_for_testing = getter;
1602 } 1602 }
1603 1603
1604 } // namespace gdata 1604 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache.h ('k') | chrome/browser/chromeos/gdata/gdata_cache_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698