| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 FROM_HERE, | 210 FROM_HERE, |
| 211 base::Bind(&ResourceMetadataStorage::DestroyOnBlockingPool, | 211 base::Bind(&ResourceMetadataStorage::DestroyOnBlockingPool, |
| 212 base::Unretained(this))); | 212 base::Unretained(this))); |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool ResourceMetadataStorage::Initialize() { | 215 bool ResourceMetadataStorage::Initialize() { |
| 216 base::ThreadRestrictions::AssertIOAllowed(); | 216 base::ThreadRestrictions::AssertIOAllowed(); |
| 217 | 217 |
| 218 // Remove unused child map DB. | 218 // Remove unused child map DB. |
| 219 const base::FilePath child_map_path = directory_path_.Append(kChildMapDBName); | 219 const base::FilePath child_map_path = directory_path_.Append(kChildMapDBName); |
| 220 file_util::Delete(child_map_path, true /* recursive */); | 220 base::Delete(child_map_path, true /* recursive */); |
| 221 | 221 |
| 222 resource_map_.reset(); | 222 resource_map_.reset(); |
| 223 | 223 |
| 224 const base::FilePath resource_map_path = | 224 const base::FilePath resource_map_path = |
| 225 directory_path_.Append(kResourceMapDBName); | 225 directory_path_.Append(kResourceMapDBName); |
| 226 | 226 |
| 227 // Try to open the existing DB. | 227 // Try to open the existing DB. |
| 228 leveldb::DB* db = NULL; | 228 leveldb::DB* db = NULL; |
| 229 leveldb::Options options; | 229 leveldb::Options options; |
| 230 options.create_if_missing = false; | 230 options.create_if_missing = false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 260 DB_INIT_MAX_VALUE); | 260 DB_INIT_MAX_VALUE); |
| 261 | 261 |
| 262 DBInitStatus init_result = DB_INIT_SUCCESS; | 262 DBInitStatus init_result = DB_INIT_SUCCESS; |
| 263 | 263 |
| 264 // Failed to open the existing DB, create new DB. | 264 // Failed to open the existing DB, create new DB. |
| 265 if (!resource_map_) { | 265 if (!resource_map_) { |
| 266 resource_map_.reset(); | 266 resource_map_.reset(); |
| 267 | 267 |
| 268 // Clean up the destination. | 268 // Clean up the destination. |
| 269 const bool kRecursive = true; | 269 const bool kRecursive = true; |
| 270 file_util::Delete(resource_map_path, kRecursive); | 270 base::Delete(resource_map_path, kRecursive); |
| 271 | 271 |
| 272 // Create DB. | 272 // Create DB. |
| 273 options.create_if_missing = true; | 273 options.create_if_missing = true; |
| 274 | 274 |
| 275 leveldb::Status status = | 275 leveldb::Status status = |
| 276 leveldb::DB::Open(options, resource_map_path.AsUTF8Unsafe(), &db); | 276 leveldb::DB::Open(options, resource_map_path.AsUTF8Unsafe(), &db); |
| 277 if (status.ok()) { | 277 if (status.ok()) { |
| 278 resource_map_.reset(db); | 278 resource_map_.reset(db); |
| 279 | 279 |
| 280 // Set up header. | 280 // Set up header. |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { | 608 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { |
| 609 DLOG(ERROR) << "Error during checking resource map. status = " | 609 DLOG(ERROR) << "Error during checking resource map. status = " |
| 610 << it->status().ToString(); | 610 << it->status().ToString(); |
| 611 return false; | 611 return false; |
| 612 } | 612 } |
| 613 return true; | 613 return true; |
| 614 } | 614 } |
| 615 | 615 |
| 616 } // namespace internal | 616 } // namespace internal |
| 617 } // namespace drive | 617 } // namespace drive |
| OLD | NEW |