OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/resource_metadata_storage.h" | 5 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 init_result = LevelDBStatusToDBInitStatus(status); | 470 init_result = LevelDBStatusToDBInitStatus(status); |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 UMA_HISTOGRAM_ENUMERATION("Drive.MetadataDBInitResult", | 474 UMA_HISTOGRAM_ENUMERATION("Drive.MetadataDBInitResult", |
475 init_result, | 475 init_result, |
476 DB_INIT_MAX_VALUE); | 476 DB_INIT_MAX_VALUE); |
477 return resource_map_; | 477 return resource_map_; |
478 } | 478 } |
479 | 479 |
480 void ResourceMetadataStorage::RecoverCacheEntriesFromTrashedResourceMap( | 480 void ResourceMetadataStorage::RecoverCacheInfoFromTrashedResourceMap( |
481 std::map<std::string, FileCacheEntry>* out_entries) { | 481 RecoveredCacheInfoMap* out_info) { |
482 const base::FilePath trashed_resource_map_path = | 482 const base::FilePath trashed_resource_map_path = |
483 directory_path_.Append(kTrashedResourceMapDBName); | 483 directory_path_.Append(kTrashedResourceMapDBName); |
484 | 484 |
485 if (!base::PathExists(trashed_resource_map_path)) | 485 if (!base::PathExists(trashed_resource_map_path)) |
486 return; | 486 return; |
487 | 487 |
488 leveldb::Options options; | 488 leveldb::Options options; |
489 options.max_open_files = 0; // Use minimum. | 489 options.max_open_files = 0; // Use minimum. |
490 options.create_if_missing = false; | 490 options.create_if_missing = false; |
491 | 491 |
(...skipping 27 matching lines...) Expand all Loading... |
519 return; | 519 return; |
520 } | 520 } |
521 | 521 |
522 // Collect cache entries. | 522 // Collect cache entries. |
523 scoped_ptr<leveldb::Iterator> it( | 523 scoped_ptr<leveldb::Iterator> it( |
524 resource_map->NewIterator(leveldb::ReadOptions())); | 524 resource_map->NewIterator(leveldb::ReadOptions())); |
525 for (it->SeekToFirst(); it->Valid(); it->Next()) { | 525 for (it->SeekToFirst(); it->Valid(); it->Next()) { |
526 if (IsCacheEntryKey(it->key())) { | 526 if (IsCacheEntryKey(it->key())) { |
527 const std::string& id = GetIdFromCacheEntryKey(it->key()); | 527 const std::string& id = GetIdFromCacheEntryKey(it->key()); |
528 FileCacheEntry cache_entry; | 528 FileCacheEntry cache_entry; |
529 if (cache_entry.ParseFromArray(it->value().data(), it->value().size())) | 529 if (cache_entry.ParseFromArray(it->value().data(), it->value().size())) { |
530 (*out_entries)[id] = cache_entry; | 530 RecoveredCacheInfo* info = &(*out_info)[id]; |
| 531 info->is_dirty = cache_entry.is_dirty(); |
| 532 info->md5 = cache_entry.md5(); |
| 533 |
| 534 // Get title from ResourceEntry if available. |
| 535 std::string serialized_entry; |
| 536 ResourceEntry entry; |
| 537 if (resource_map->Get(leveldb::ReadOptions(), |
| 538 leveldb::Slice(id), |
| 539 &serialized_entry).ok() && |
| 540 entry.ParseFromString(serialized_entry)) |
| 541 info->title = entry.title(); |
| 542 } |
531 } | 543 } |
532 } | 544 } |
533 } | 545 } |
534 | 546 |
535 bool ResourceMetadataStorage::SetLargestChangestamp( | 547 bool ResourceMetadataStorage::SetLargestChangestamp( |
536 int64 largest_changestamp) { | 548 int64 largest_changestamp) { |
537 base::ThreadRestrictions::AssertIOAllowed(); | 549 base::ThreadRestrictions::AssertIOAllowed(); |
538 | 550 |
539 ResourceMetadataHeader header; | 551 ResourceMetadataHeader header; |
540 if (!GetHeader(&header)) { | 552 if (!GetHeader(&header)) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 739 |
728 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator> | 740 scoped_ptr<ResourceMetadataStorage::CacheEntryIterator> |
729 ResourceMetadataStorage::GetCacheEntryIterator() { | 741 ResourceMetadataStorage::GetCacheEntryIterator() { |
730 base::ThreadRestrictions::AssertIOAllowed(); | 742 base::ThreadRestrictions::AssertIOAllowed(); |
731 | 743 |
732 scoped_ptr<leveldb::Iterator> it( | 744 scoped_ptr<leveldb::Iterator> it( |
733 resource_map_->NewIterator(leveldb::ReadOptions())); | 745 resource_map_->NewIterator(leveldb::ReadOptions())); |
734 return make_scoped_ptr(new CacheEntryIterator(it.Pass())); | 746 return make_scoped_ptr(new CacheEntryIterator(it.Pass())); |
735 } | 747 } |
736 | 748 |
| 749 ResourceMetadataStorage::RecoveredCacheInfo::RecoveredCacheInfo() |
| 750 : is_dirty(false) {} |
| 751 |
| 752 ResourceMetadataStorage::RecoveredCacheInfo::~RecoveredCacheInfo() {} |
| 753 |
737 bool ResourceMetadataStorage::GetIdByResourceId( | 754 bool ResourceMetadataStorage::GetIdByResourceId( |
738 const std::string& resource_id, | 755 const std::string& resource_id, |
739 std::string* out_id) { | 756 std::string* out_id) { |
740 base::ThreadRestrictions::AssertIOAllowed(); | 757 base::ThreadRestrictions::AssertIOAllowed(); |
741 DCHECK(!resource_id.empty()); | 758 DCHECK(!resource_id.empty()); |
742 | 759 |
743 const leveldb::Status status = resource_map_->Get( | 760 const leveldb::Status status = resource_map_->Get( |
744 leveldb::ReadOptions(), | 761 leveldb::ReadOptions(), |
745 leveldb::Slice(GetIdEntryKey(resource_id)), | 762 leveldb::Slice(GetIdEntryKey(resource_id)), |
746 out_id); | 763 out_id); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { | 920 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { |
904 DLOG(ERROR) << "Error during checking resource map. status = " | 921 DLOG(ERROR) << "Error during checking resource map. status = " |
905 << it->status().ToString(); | 922 << it->status().ToString(); |
906 return false; | 923 return false; |
907 } | 924 } |
908 return true; | 925 return true; |
909 } | 926 } |
910 | 927 |
911 } // namespace internal | 928 } // namespace internal |
912 } // namespace drive | 929 } // namespace drive |
OLD | NEW |