| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 16 #include "chrome/browser/drive/drive_api_util.h" |
| 16 #include "third_party/leveldatabase/env_chromium.h" | 17 #include "third_party/leveldatabase/env_chromium.h" |
| 17 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| 19 | 20 |
| 20 namespace drive { | 21 namespace drive { |
| 21 namespace internal { | 22 namespace internal { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Enum to describe DB initialization status. | 26 // Enum to describe DB initialization status. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 | 212 |
| 212 bool ResourceMetadataStorage::Iterator::HasError() const { | 213 bool ResourceMetadataStorage::Iterator::HasError() const { |
| 213 base::ThreadRestrictions::AssertIOAllowed(); | 214 base::ThreadRestrictions::AssertIOAllowed(); |
| 214 return !it_->status().ok(); | 215 return !it_->status().ok(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 // static | 218 // static |
| 218 bool ResourceMetadataStorage::UpgradeOldDB( | 219 bool ResourceMetadataStorage::UpgradeOldDB( |
| 219 const base::FilePath& directory_path, | 220 const base::FilePath& directory_path) { |
| 220 const ResourceIdCanonicalizer& id_canonicalizer) { | |
| 221 base::ThreadRestrictions::AssertIOAllowed(); | 221 base::ThreadRestrictions::AssertIOAllowed(); |
| 222 COMPILE_ASSERT( | 222 COMPILE_ASSERT( |
| 223 kDBVersion == 13, | 223 kDBVersion == 13, |
| 224 db_version_and_this_function_should_be_updated_at_the_same_time); | 224 db_version_and_this_function_should_be_updated_at_the_same_time); |
| 225 | 225 |
| 226 const base::FilePath resource_map_path = | 226 const base::FilePath resource_map_path = |
| 227 directory_path.Append(kResourceMapDBName); | 227 directory_path.Append(kResourceMapDBName); |
| 228 const base::FilePath preserved_resource_map_path = | 228 const base::FilePath preserved_resource_map_path = |
| 229 directory_path.Append(kPreservedResourceMapDBName); | 229 directory_path.Append(kPreservedResourceMapDBName); |
| 230 | 230 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // Put ID entries and cache entries. | 302 // Put ID entries and cache entries. |
| 303 for (it->SeekToFirst(); it->Valid(); it->Next()) { | 303 for (it->SeekToFirst(); it->Valid(); it->Next()) { |
| 304 if (IsCacheEntryKey(it->key())) { | 304 if (IsCacheEntryKey(it->key())) { |
| 305 FileCacheEntry cache_entry; | 305 FileCacheEntry cache_entry; |
| 306 if (!cache_entry.ParseFromArray(it->value().data(), it->value().size())) | 306 if (!cache_entry.ParseFromArray(it->value().data(), it->value().size())) |
| 307 return false; | 307 return false; |
| 308 | 308 |
| 309 // The resource ID might be in old WAPI format. We need to canonicalize | 309 // The resource ID might be in old WAPI format. We need to canonicalize |
| 310 // to the format of API service currently in use. | 310 // to the format of API service currently in use. |
| 311 const std::string& id = GetIdFromCacheEntryKey(it->key()); | 311 const std::string& id = GetIdFromCacheEntryKey(it->key()); |
| 312 const std::string& id_new = id_canonicalizer.Run(id); | 312 const std::string& id_new = util::CanonicalizeResourceId(id); |
| 313 | 313 |
| 314 // Before v11, resource ID was directly used as local ID. Such entries | 314 // Before v11, resource ID was directly used as local ID. Such entries |
| 315 // can be migrated by adding an identity ID mapping. | 315 // can be migrated by adding an identity ID mapping. |
| 316 batch.Put(GetIdEntryKey(id_new), id_new); | 316 batch.Put(GetIdEntryKey(id_new), id_new); |
| 317 | 317 |
| 318 // Put cache state into a ResourceEntry. | 318 // Put cache state into a ResourceEntry. |
| 319 ResourceEntry entry; | 319 ResourceEntry entry; |
| 320 entry.set_local_id(id_new); | 320 entry.set_local_id(id_new); |
| 321 entry.set_resource_id(id_new); | 321 entry.set_resource_id(id_new); |
| 322 *entry.mutable_file_specific_info()->mutable_cache_state() = | 322 *entry.mutable_file_specific_info()->mutable_cache_state() = |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { | 1005 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { |
| 1006 DLOG(ERROR) << "Error during checking resource map. status = " | 1006 DLOG(ERROR) << "Error during checking resource map. status = " |
| 1007 << it->status().ToString(); | 1007 << it->status().ToString(); |
| 1008 return false; | 1008 return false; |
| 1009 } | 1009 } |
| 1010 return true; | 1010 return true; |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 } // namespace internal | 1013 } // namespace internal |
| 1014 } // namespace drive | 1014 } // namespace drive |
| OLD | NEW |