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

Side by Side Diff: content/browser/service_worker/service_worker_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_database.h" 5 #include "content/browser/service_worker/service_worker_database.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 leveldb::Options options; 1223 leveldb::Options options;
1224 options.create_if_missing = create_if_missing; 1224 options.create_if_missing = create_if_missing;
1225 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; 1225 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
1226 if (IsDatabaseInMemory()) { 1226 if (IsDatabaseInMemory()) {
1227 env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); 1227 env_.reset(leveldb::NewMemEnv(leveldb::Env::Default()));
1228 options.env = env_.get(); 1228 options.env = env_.get();
1229 } else { 1229 } else {
1230 options.env = g_service_worker_env.Pointer(); 1230 options.env = g_service_worker_env.Pointer();
1231 } 1231 }
1232 1232
1233 leveldb::DB* db = NULL;
1234 Status status = LevelDBStatusToStatus( 1233 Status status = LevelDBStatusToStatus(
1235 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db)); 1234 leveldb_env::OpenDB(options, path_.AsUTF8Unsafe(), &db_));
1236 HandleOpenResult(FROM_HERE, status); 1235 HandleOpenResult(FROM_HERE, status);
1237 if (status != STATUS_OK) { 1236 if (status != STATUS_OK) {
1238 DCHECK(!db);
1239 // TODO(nhiroki): Should we retry to open the database? 1237 // TODO(nhiroki): Should we retry to open the database?
1240 return status; 1238 return status;
1241 } 1239 }
1242 db_.reset(db);
1243 1240
1244 int64_t db_version; 1241 int64_t db_version;
1245 status = ReadDatabaseVersion(&db_version); 1242 status = ReadDatabaseVersion(&db_version);
1246 if (status != STATUS_OK) 1243 if (status != STATUS_OK)
1247 return status; 1244 return status;
1248 1245
1249 switch (db_version) { 1246 switch (db_version) {
1250 case 0: 1247 case 0:
1251 // This database is new. It will be initialized when something is written. 1248 // This database is new. It will be initialized when something is written.
1252 DCHECK_EQ(UNINITIALIZED, state_); 1249 DCHECK_EQ(UNINITIALIZED, state_);
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 if (status != STATUS_OK) 1825 if (status != STATUS_OK)
1829 Disable(from_here, status); 1826 Disable(from_here, status);
1830 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1827 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1831 } 1828 }
1832 1829
1833 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { 1830 bool ServiceWorkerDatabase::IsDatabaseInMemory() const {
1834 return path_.empty(); 1831 return path_.empty();
1835 } 1832 }
1836 1833
1837 } // namespace content 1834 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/notifications/notification_database.cc ('k') | extensions/browser/value_store/lazy_leveldb.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698