Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; add comments to CHECK() Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698