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/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 AssertOnSequencedWorkerPool(); | 489 AssertOnSequencedWorkerPool(); |
490 | 490 |
491 // If file has already been marked dirty in previous instance of chrome, we | 491 // If file has already been marked dirty in previous instance of chrome, we |
492 // would have lost the md5 info during cache initialization, because the file | 492 // would have lost the md5 info during cache initialization, because the file |
493 // would have been renamed to .local extension. | 493 // would have been renamed to .local extension. |
494 // So, search for entry in cache without comparing md5. | 494 // So, search for entry in cache without comparing md5. |
495 | 495 |
496 // Marking a file dirty means its entry and actual file blob must exist in | 496 // Marking a file dirty means its entry and actual file blob must exist in |
497 // cache. | 497 // cache. |
498 FileCacheEntry cache_entry; | 498 FileCacheEntry cache_entry; |
499 if (!storage_->GetCacheEntry(resource_id, &cache_entry) || | 499 if (!GetCacheEntry(resource_id, md5, &cache_entry) || |
500 !cache_entry.is_present()) { | 500 !cache_entry.is_present()) { |
501 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" | 501 LOG(WARNING) << "Can't mark dirty a file that wasn't cached: res_id=" |
502 << resource_id | 502 << resource_id |
503 << ", md5=" << md5; | 503 << ", md5=" << md5; |
504 return FILE_ERROR_NOT_FOUND; | 504 return FILE_ERROR_NOT_FOUND; |
505 } | 505 } |
506 | 506 |
507 if (cache_entry.is_dirty()) | 507 if (cache_entry.is_dirty()) |
508 return FILE_ERROR_OK; | 508 return FILE_ERROR_OK; |
509 | 509 |
510 // Get the current path of the file in cache. | 510 // Get the current path of the file in cache. |
511 base::FilePath source_path = GetCacheFilePath(resource_id, md5, | 511 base::FilePath source_path = GetCacheFilePath(resource_id, cache_entry.md5(), |
512 CACHED_FILE_FROM_SERVER); | 512 CACHED_FILE_FROM_SERVER); |
513 // Determine destination path. | 513 // Determine destination path. |
514 base::FilePath cache_file_path = GetCacheFilePath( | 514 base::FilePath cache_file_path = GetCacheFilePath( |
515 resource_id, md5, CACHED_FILE_LOCALLY_MODIFIED); | 515 resource_id, cache_entry.md5(), CACHED_FILE_LOCALLY_MODIFIED); |
516 | 516 |
517 if (!MoveFile(source_path, cache_file_path)) | 517 if (!MoveFile(source_path, cache_file_path)) |
518 return FILE_ERROR_FAILED; | 518 return FILE_ERROR_FAILED; |
519 | 519 |
520 // Now that file operations have completed, update metadata. | 520 // Now that file operations have completed, update metadata. |
521 cache_entry.set_md5(md5); | |
522 cache_entry.set_is_dirty(true); | 521 cache_entry.set_is_dirty(true); |
523 storage_->PutCacheEntry(resource_id, cache_entry); | 522 storage_->PutCacheEntry(resource_id, cache_entry); |
524 return FILE_ERROR_OK; | 523 return FILE_ERROR_OK; |
525 } | 524 } |
526 | 525 |
527 FileError FileCache::ClearDirty(const std::string& resource_id, | 526 FileError FileCache::ClearDirty(const std::string& resource_id, |
528 const std::string& md5) { | 527 const std::string& md5) { |
529 AssertOnSequencedWorkerPool(); | 528 AssertOnSequencedWorkerPool(); |
530 | 529 |
531 // |md5| is the new .<md5> extension to rename the file to. | 530 // |md5| is the new .<md5> extension to rename the file to. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } | 830 } |
832 } | 831 } |
833 | 832 |
834 // Delete old DB. | 833 // Delete old DB. |
835 base::Delete(old_db_path, true /* recursive */ ); | 834 base::Delete(old_db_path, true /* recursive */ ); |
836 return imported; | 835 return imported; |
837 } | 836 } |
838 | 837 |
839 } // namespace internal | 838 } // namespace internal |
840 } // namespace drive | 839 } // namespace drive |
OLD | NEW |