| 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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 leveldb::Options options; | 1224 leveldb::Options options; |
| 1225 options.create_if_missing = create_if_missing; | 1225 options.create_if_missing = create_if_missing; |
| 1226 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; | 1226 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
| 1227 if (IsDatabaseInMemory()) { | 1227 if (IsDatabaseInMemory()) { |
| 1228 env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); | 1228 env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); |
| 1229 options.env = env_.get(); | 1229 options.env = env_.get(); |
| 1230 } else { | 1230 } else { |
| 1231 options.env = g_service_worker_env.Pointer(); | 1231 options.env = g_service_worker_env.Pointer(); |
| 1232 } | 1232 } |
| 1233 | 1233 |
| 1234 leveldb::DB* db = NULL; | |
| 1235 Status status = LevelDBStatusToStatus( | 1234 Status status = LevelDBStatusToStatus( |
| 1236 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db)); | 1235 leveldb_env::OpenDB(options, path_.AsUTF8Unsafe(), &db_)); |
| 1237 HandleOpenResult(FROM_HERE, status); | 1236 HandleOpenResult(FROM_HERE, status); |
| 1238 if (status != STATUS_OK) { | 1237 if (status != STATUS_OK) { |
| 1239 DCHECK(!db); | |
| 1240 // TODO(nhiroki): Should we retry to open the database? | 1238 // TODO(nhiroki): Should we retry to open the database? |
| 1241 return status; | 1239 return status; |
| 1242 } | 1240 } |
| 1243 db_.reset(db); | |
| 1244 | 1241 |
| 1245 int64_t db_version; | 1242 int64_t db_version; |
| 1246 status = ReadDatabaseVersion(&db_version); | 1243 status = ReadDatabaseVersion(&db_version); |
| 1247 if (status != STATUS_OK) | 1244 if (status != STATUS_OK) |
| 1248 return status; | 1245 return status; |
| 1249 | 1246 |
| 1250 switch (db_version) { | 1247 switch (db_version) { |
| 1251 case 0: | 1248 case 0: |
| 1252 // This database is new. It will be initialized when something is written. | 1249 // This database is new. It will be initialized when something is written. |
| 1253 DCHECK_EQ(UNINITIALIZED, state_); | 1250 DCHECK_EQ(UNINITIALIZED, state_); |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 if (status != STATUS_OK) | 1826 if (status != STATUS_OK) |
| 1830 Disable(from_here, status); | 1827 Disable(from_here, status); |
| 1831 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1828 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1832 } | 1829 } |
| 1833 | 1830 |
| 1834 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1831 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1835 return path_.empty(); | 1832 return path_.empty(); |
| 1836 } | 1833 } |
| 1837 | 1834 |
| 1838 } // namespace content | 1835 } // namespace content |
| OLD | NEW |