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

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

Issue 10765020: gdata: Simplify semantics of sub_dir_type in CacheEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "chrome/browser/chromeos/gdata/gdata_util.h" 8 #include "chrome/browser/chromeos/gdata/gdata_util.h"
9 9
10 namespace gdata { 10 namespace gdata {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 file_util::FileEnumerator enumerator( 288 file_util::FileEnumerator enumerator(
289 cache_paths[sub_dir_type], 289 cache_paths[sub_dir_type],
290 false, // not recursive 290 false, // not recursive
291 static_cast<file_util::FileEnumerator::FileType>( 291 static_cast<file_util::FileEnumerator::FileType>(
292 file_util::FileEnumerator::FILES | 292 file_util::FileEnumerator::FILES |
293 file_util::FileEnumerator::SHOW_SYM_LINKS), 293 file_util::FileEnumerator::SHOW_SYM_LINKS),
294 util::kWildCard); 294 util::kWildCard);
295 for (FilePath current = enumerator.Next(); !current.empty(); 295 for (FilePath current = enumerator.Next(); !current.empty();
296 current = enumerator.Next()) { 296 current = enumerator.Next()) {
297 GDataCache::CacheSubDirectoryType real_sub_dir_type =
298 sub_dir_type;
297 // Extract resource_id and md5 from filename. 299 // Extract resource_id and md5 from filename.
298 std::string resource_id; 300 std::string resource_id;
299 std::string md5; 301 std::string md5;
300 std::string extra_extension; 302 std::string extra_extension;
301 util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension); 303 util::ParseCacheFilePath(current, &resource_id, &md5, &extra_extension);
302 304
303 // Determine cache state. 305 // Determine cache state.
304 int cache_state = GDataCache::CACHE_STATE_NONE; 306 int cache_state = GDataCache::CACHE_STATE_NONE;
305 // If we're scanning pinned directory and if entry already exists, just 307 // If we're scanning pinned directory and if entry already exists, just
306 // update its pinned state. 308 // update its pinned state.
(...skipping 11 matching lines...) Expand all
318 iter->second.cache_state = 320 iter->second.cache_state =
319 GDataCache::SetCachePinned(iter->second.cache_state); 321 GDataCache::SetCachePinned(iter->second.cache_state);
320 322
321 processed_file_map->insert(std::make_pair(resource_id, current)); 323 processed_file_map->insert(std::make_pair(resource_id, current));
322 continue; 324 continue;
323 } 325 }
324 // Entry doesn't exist, this is a special symlink that refers to 326 // Entry doesn't exist, this is a special symlink that refers to
325 // /dev/null; follow through to create an entry with the PINNED but not 327 // /dev/null; follow through to create an entry with the PINNED but not
326 // PRESENT state. 328 // PRESENT state.
327 cache_state = GDataCache::SetCachePinned(cache_state); 329 cache_state = GDataCache::SetCachePinned(cache_state);
330 // Change the real sub directory type to TMP, as the downloaded file
331 // will be stored in 'tmp' directory first.
332 real_sub_dir_type = GDataCache::CACHE_TYPE_TMP;
328 } else if (sub_dir_type == GDataCache::CACHE_TYPE_OUTGOING) { 333 } else if (sub_dir_type == GDataCache::CACHE_TYPE_OUTGOING) {
329 std::string reason; 334 std::string reason;
330 if (!IsValidSymbolicLink(current, sub_dir_type, cache_paths, &reason)) { 335 if (!IsValidSymbolicLink(current, sub_dir_type, cache_paths, &reason)) {
331 LOG(WARNING) << "Removing an invalid symlink: " << current.value() 336 LOG(WARNING) << "Removing an invalid symlink: " << current.value()
332 << ": " << reason; 337 << ": " << reason;
333 file_util::Delete(current, false); 338 file_util::Delete(current, false);
334 continue; 339 continue;
335 } 340 }
336 341
337 // If we're scanning outgoing directory, entry must exist and be dirty. 342 // If we're scanning outgoing directory, entry must exist and be dirty.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 continue; 382 continue;
378 } 383 }
379 } 384 }
380 } 385 }
381 } else { 386 } else {
382 NOTREACHED() << "Unexpected sub directory type: " << sub_dir_type; 387 NOTREACHED() << "Unexpected sub directory type: " << sub_dir_type;
383 } 388 }
384 389
385 // Create and insert new entry into cache map. 390 // Create and insert new entry into cache map.
386 cache_map->insert(std::make_pair( 391 cache_map->insert(std::make_pair(
387 resource_id, GDataCache::CacheEntry(md5, sub_dir_type, cache_state))); 392 resource_id, GDataCache::CacheEntry(
393 md5, real_sub_dir_type, cache_state)));
388 processed_file_map->insert(std::make_pair(resource_id, current)); 394 processed_file_map->insert(std::make_pair(resource_id, current));
389 } 395 }
390 } 396 }
391 397
392 // static 398 // static
393 bool GDataCacheMetadataMap::CheckIfMd5Matches( 399 bool GDataCacheMetadataMap::CheckIfMd5Matches(
394 const std::string& md5, 400 const std::string& md5,
395 const GDataCache::CacheEntry& cache_entry) { 401 const GDataCache::CacheEntry& cache_entry) {
396 if (cache_entry.IsDirty()) { 402 if (cache_entry.IsDirty()) {
397 // If the entry is dirty, its MD5 may have been replaced by "local" 403 // If the entry is dirty, its MD5 may have been replaced by "local"
398 // during cache initialization, so we don't compare MD5. 404 // during cache initialization, so we don't compare MD5.
399 return true; 405 return true;
400 } else if (cache_entry.IsPinned() && cache_entry.md5.empty()) { 406 } else if (cache_entry.IsPinned() && cache_entry.md5.empty()) {
401 // If the entry is pinned, it's ok for the entry to have an empty 407 // If the entry is pinned, it's ok for the entry to have an empty
402 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned 408 // MD5. This can happen if the pinned file is not fetched. MD5 for pinned
403 // files are collected from files in "persistent" directory, but the 409 // files are collected from files in "persistent" directory, but the
404 // persistent files do not exisit if these are not fetched yet. 410 // persistent files do not exisit if these are not fetched yet.
405 return true; 411 return true;
406 } else if (md5.empty()) { 412 } else if (md5.empty()) {
407 // If the MD5 matching is not requested, don't check MD5. 413 // If the MD5 matching is not requested, don't check MD5.
408 return true; 414 return true;
409 } else if (md5 == cache_entry.md5) { 415 } else if (md5 == cache_entry.md5) {
410 // Otherwise, compare the MD5. 416 // Otherwise, compare the MD5.
411 return true; 417 return true;
412 } 418 }
413 return false; 419 return false;
414 } 420 }
415 421
416 } // namespace gdata 422 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698