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

Unified Diff: components/drive/resource_metadata_storage.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 side-by-side diff with in-line comments
Download patch
Index: components/drive/resource_metadata_storage.cc
diff --git a/components/drive/resource_metadata_storage.cc b/components/drive/resource_metadata_storage.cc
index 0c49407ccf1fb4cd129ea8f343c62c513d9f761c..7d601a1a36517f7fa21b2f3209489ea3ea51edc6 100644
--- a/components/drive/resource_metadata_storage.cc
+++ b/components/drive/resource_metadata_storage.cc
@@ -269,14 +269,15 @@ bool ResourceMetadataStorage::UpgradeOldDB(
return false;
// Open DB.
- leveldb::DB* db = NULL;
+ std::unique_ptr<leveldb::DB> resource_map;
leveldb::Options options;
options.max_open_files = 0; // Use minimum.
options.create_if_missing = false;
options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
- if (!leveldb::DB::Open(options, resource_map_path.AsUTF8Unsafe(), &db).ok())
+ leveldb::Status status = leveldb_env::OpenDB(
+ options, resource_map_path.AsUTF8Unsafe(), &resource_map);
+ if (!status.ok())
return false;
- std::unique_ptr<leveldb::DB> resource_map(db);
// Check DB version.
std::string serialized_header;
@@ -552,7 +553,6 @@ bool ResourceMetadataStorage::Initialize() {
}
// Try to open the existing DB.
- leveldb::DB* db = NULL;
leveldb::Options options;
options.max_open_files = 0; // Use minimum.
options.create_if_missing = false;
@@ -561,13 +561,12 @@ bool ResourceMetadataStorage::Initialize() {
DBInitStatus open_existing_result = DB_INIT_NOT_FOUND;
leveldb::Status status;
if (base::PathExists(resource_map_path)) {
- status = leveldb::DB::Open(options, resource_map_path.AsUTF8Unsafe(), &db);
+ status = leveldb_env::OpenDB(options, resource_map_path.AsUTF8Unsafe(),
+ &resource_map_);
open_existing_result = LevelDBStatusToDBInitStatus(status);
}
if (open_existing_result == DB_INIT_SUCCESS) {
- resource_map_.reset(db);
-
// Check the validity of existing DB.
int db_version = -1;
ResourceMetadataHeader header;
@@ -610,10 +609,9 @@ bool ResourceMetadataStorage::Initialize() {
options.error_if_exists = true;
options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
- status = leveldb::DB::Open(options, resource_map_path.AsUTF8Unsafe(), &db);
+ status = leveldb_env::OpenDB(options, resource_map_path.AsUTF8Unsafe(),
+ &resource_map_);
if (status.ok()) {
- resource_map_.reset(db);
-
// Set up header and trash the old DB.
if (PutHeader(GetDefaultHeaderEntry()) == FILE_ERROR_OK &&
MoveIfPossible(preserved_resource_map_path,
@@ -676,14 +674,13 @@ void ResourceMetadataStorage::RecoverCacheInfoFromTrashedResourceMap(
}
// Open it.
- leveldb::DB* db = NULL;
- status = leveldb::DB::Open(options, trashed_resource_map_path.AsUTF8Unsafe(),
- &db);
+ std::unique_ptr<leveldb::DB> resource_map;
+ status = leveldb_env::OpenDB(
+ options, trashed_resource_map_path.AsUTF8Unsafe(), &resource_map);
if (!status.ok()) {
LOG(ERROR) << "Failed to open trashed DB: " << status.ToString();
return;
}
- std::unique_ptr<leveldb::DB> resource_map(db);
// Check DB version.
std::string serialized_header;
« no previous file with comments | « components/data_reduction_proxy/core/browser/data_store_impl.cc ('k') | components/leveldb/leveldb_database_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698