| 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/sync_file_system/drive_backend/metadata_database.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <stack> | 8 #include <stack> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 DCHECK(created); | 215 DCHECK(created); |
| 216 DCHECK(path.IsAbsolute()); | 216 DCHECK(path.IsAbsolute()); |
| 217 | 217 |
| 218 leveldb::Options options; | 218 leveldb::Options options; |
| 219 options.max_open_files = 0; // Use minimum. | 219 options.max_open_files = 0; // Use minimum. |
| 220 options.create_if_missing = true; | 220 options.create_if_missing = true; |
| 221 options.paranoid_checks = true; | 221 options.paranoid_checks = true; |
| 222 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; | 222 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
| 223 if (env_override) | 223 if (env_override) |
| 224 options.env = env_override; | 224 options.env = env_override; |
| 225 leveldb::DB* db = nullptr; | 225 std::unique_ptr<leveldb::DB> db; |
| 226 leveldb::Status db_status = | 226 leveldb::Status db_status = |
| 227 leveldb::DB::Open(options, path.AsUTF8Unsafe(), &db); | 227 leveldb_env::OpenDB(options, path.AsUTF8Unsafe(), &db); |
| 228 UMA_HISTOGRAM_ENUMERATION("SyncFileSystem.Database.Open", | 228 UMA_HISTOGRAM_ENUMERATION("SyncFileSystem.Database.Open", |
| 229 leveldb_env::GetLevelDBStatusUMAValue(db_status), | 229 leveldb_env::GetLevelDBStatusUMAValue(db_status), |
| 230 leveldb_env::LEVELDB_STATUS_MAX); | 230 leveldb_env::LEVELDB_STATUS_MAX); |
| 231 SyncStatusCode status = LevelDBStatusToSyncStatusCode(db_status); | 231 SyncStatusCode status = LevelDBStatusToSyncStatusCode(db_status); |
| 232 if (status != SYNC_STATUS_OK) { | 232 if (status != SYNC_STATUS_OK) { |
| 233 delete db; | |
| 234 return status; | 233 return status; |
| 235 } | 234 } |
| 236 | 235 |
| 237 db_out->reset(new LevelDBWrapper(base::WrapUnique(db))); | 236 db_out->reset(new LevelDBWrapper(std::move(db))); |
| 238 *created = IsDatabaseEmpty(db_out->get()); | 237 *created = IsDatabaseEmpty(db_out->get()); |
| 239 return status; | 238 return status; |
| 240 } | 239 } |
| 241 | 240 |
| 242 SyncStatusCode MigrateDatabaseIfNeeded(LevelDBWrapper* db) { | 241 SyncStatusCode MigrateDatabaseIfNeeded(LevelDBWrapper* db) { |
| 243 // See metadata_database_index.cc for the database schema. | 242 // See metadata_database_index.cc for the database schema. |
| 244 base::ThreadRestrictions::AssertIOAllowed(); | 243 base::ThreadRestrictions::AssertIOAllowed(); |
| 245 DCHECK(db); | 244 DCHECK(db); |
| 246 std::string value; | 245 std::string value; |
| 247 leveldb::Status status = db->Get(kDatabaseVersionKey, &value); | 246 leveldb::Status status = db->Get(kDatabaseVersionKey, &value); |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 return false; | 1804 return false; |
| 1806 | 1805 |
| 1807 if (!parents.empty()) | 1806 if (!parents.empty()) |
| 1808 return false; | 1807 return false; |
| 1809 | 1808 |
| 1810 return true; | 1809 return true; |
| 1811 } | 1810 } |
| 1812 | 1811 |
| 1813 } // namespace drive_backend | 1812 } // namespace drive_backend |
| 1814 } // namespace sync_file_system | 1813 } // namespace sync_file_system |
| OLD | NEW |