| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |