| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 resource_id_.assign(it_->key().data(), id_length); | 194 resource_id_.assign(it_->key().data(), id_length); |
| 195 break; | 195 break; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 ResourceMetadataStorage::ResourceMetadataStorage( | 200 ResourceMetadataStorage::ResourceMetadataStorage( |
| 201 const base::FilePath& directory_path, | 201 const base::FilePath& directory_path, |
| 202 base::SequencedTaskRunner* blocking_task_runner) | 202 base::SequencedTaskRunner* blocking_task_runner) |
| 203 : directory_path_(directory_path), | 203 : directory_path_(directory_path), |
| 204 opened_existing_db_(false), |
| 204 blocking_task_runner_(blocking_task_runner) { | 205 blocking_task_runner_(blocking_task_runner) { |
| 205 } | 206 } |
| 206 | 207 |
| 207 void ResourceMetadataStorage::Destroy() { | 208 void ResourceMetadataStorage::Destroy() { |
| 208 blocking_task_runner_->PostTask( | 209 blocking_task_runner_->PostTask( |
| 209 FROM_HERE, | 210 FROM_HERE, |
| 210 base::Bind(&ResourceMetadataStorage::DestroyOnBlockingPool, | 211 base::Bind(&ResourceMetadataStorage::DestroyOnBlockingPool, |
| 211 base::Unretained(this))); | 212 base::Unretained(this))); |
| 212 } | 213 } |
| 213 | 214 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 241 // Check the validity of existing DB. | 242 // Check the validity of existing DB. |
| 242 ResourceMetadataHeader header; | 243 ResourceMetadataHeader header; |
| 243 if (!GetHeader(&header) || header.version() != kDBVersion) { | 244 if (!GetHeader(&header) || header.version() != kDBVersion) { |
| 244 open_existing_result = DB_INIT_INCOMPATIBLE; | 245 open_existing_result = DB_INIT_INCOMPATIBLE; |
| 245 LOG(INFO) << "Reject incompatible DB."; | 246 LOG(INFO) << "Reject incompatible DB."; |
| 246 } else if (!CheckValidity()) { | 247 } else if (!CheckValidity()) { |
| 247 open_existing_result = DB_INIT_BROKEN; | 248 open_existing_result = DB_INIT_BROKEN; |
| 248 LOG(ERROR) << "Reject invalid DB."; | 249 LOG(ERROR) << "Reject invalid DB."; |
| 249 } | 250 } |
| 250 | 251 |
| 251 if (open_existing_result != DB_INIT_SUCCESS) | 252 if (open_existing_result == DB_INIT_SUCCESS) |
| 253 opened_existing_db_ = true; |
| 254 else |
| 252 resource_map_.reset(); | 255 resource_map_.reset(); |
| 253 } | 256 } |
| 254 | 257 |
| 255 UMA_HISTOGRAM_ENUMERATION("Drive.MetadataDBOpenExistingResult", | 258 UMA_HISTOGRAM_ENUMERATION("Drive.MetadataDBOpenExistingResult", |
| 256 open_existing_result, | 259 open_existing_result, |
| 257 DB_INIT_MAX_VALUE); | 260 DB_INIT_MAX_VALUE); |
| 258 | 261 |
| 259 DBInitStatus init_result = DB_INIT_SUCCESS; | 262 DBInitStatus init_result = DB_INIT_SUCCESS; |
| 260 | 263 |
| 261 // Failed to open the existing DB, create new DB. | 264 // Failed to open the existing DB, create new DB. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { | 608 if (!it->status().ok() || num_child_entries != num_entries_with_parent) { |
| 606 DLOG(ERROR) << "Error during checking resource map. status = " | 609 DLOG(ERROR) << "Error during checking resource map. status = " |
| 607 << it->status().ToString(); | 610 << it->status().ToString(); |
| 608 return false; | 611 return false; |
| 609 } | 612 } |
| 610 return true; | 613 return true; |
| 611 } | 614 } |
| 612 | 615 |
| 613 } // namespace internal | 616 } // namespace internal |
| 614 } // namespace drive | 617 } // namespace drive |
| OLD | NEW |