| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 base::ThreadRestrictions::AssertIOAllowed(); | 114 base::ThreadRestrictions::AssertIOAllowed(); |
| 115 return !it_->Valid(); | 115 return !it_->Valid(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 const ResourceEntry& ResourceMetadataStorage::Iterator::Get() const { | 118 const ResourceEntry& ResourceMetadataStorage::Iterator::Get() const { |
| 119 base::ThreadRestrictions::AssertIOAllowed(); | 119 base::ThreadRestrictions::AssertIOAllowed(); |
| 120 DCHECK(!IsAtEnd()); | 120 DCHECK(!IsAtEnd()); |
| 121 return entry_; | 121 return entry_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool ResourceMetadataStorage::Iterator::GetCacheEntry( |
| 125 FileCacheEntry* cache_entry) { |
| 126 base::ThreadRestrictions::AssertIOAllowed(); |
| 127 DCHECK(!IsAtEnd()); |
| 128 |
| 129 // Try to seek to the cache entry. |
| 130 std::string current_key = it_->key().ToString(); |
| 131 std::string cache_entry_key = GetCacheEntryKey(current_key); |
| 132 it_->Seek(leveldb::Slice(cache_entry_key)); |
| 133 |
| 134 bool success = it_->Valid() && |
| 135 it_->key().compare(cache_entry_key) == 0 && |
| 136 cache_entry->ParseFromArray(it_->value().data(), it_->value().size()); |
| 137 |
| 138 // Seek back to the original position. |
| 139 it_->Seek(leveldb::Slice(current_key)); |
| 140 DCHECK(!IsAtEnd()); |
| 141 DCHECK_EQ(current_key, it_->key().ToString()); |
| 142 |
| 143 return success; |
| 144 } |
| 145 |
| 124 void ResourceMetadataStorage::Iterator::Advance() { | 146 void ResourceMetadataStorage::Iterator::Advance() { |
| 125 base::ThreadRestrictions::AssertIOAllowed(); | 147 base::ThreadRestrictions::AssertIOAllowed(); |
| 126 DCHECK(!IsAtEnd()); | 148 DCHECK(!IsAtEnd()); |
| 127 | 149 |
| 128 for (it_->Next() ; it_->Valid(); it_->Next()) { | 150 for (it_->Next() ; it_->Valid(); it_->Next()) { |
| 129 if (!IsChildEntryKey(it_->key()) && | 151 if (!IsChildEntryKey(it_->key()) && |
| 130 !IsCacheEntryKey(it_->key()) && | 152 !IsCacheEntryKey(it_->key()) && |
| 131 entry_.ParseFromArray(it_->value().data(), it_->value().size())) | 153 entry_.ParseFromArray(it_->value().data(), it_->value().size())) |
| 132 break; | 154 break; |
| 133 } | 155 } |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { | 632 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { |
| 611 DLOG(ERROR) << "Error during checking resource map. status = " | 633 DLOG(ERROR) << "Error during checking resource map. status = " |
| 612 << it->status().ToString(); | 634 << it->status().ToString(); |
| 613 return false; | 635 return false; |
| 614 } | 636 } |
| 615 return true; | 637 return true; |
| 616 } | 638 } |
| 617 | 639 |
| 618 } // namespace internal | 640 } // namespace internal |
| 619 } // namespace drive | 641 } // namespace drive |
| OLD | NEW |