| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/browser/value_store/lazy_leveldb.h" | 5 #include "extensions/browser/value_store/lazy_leveldb.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 leveldb::Options repair_options; | 177 leveldb::Options repair_options; |
| 178 repair_options.create_if_missing = true; | 178 repair_options.create_if_missing = true; |
| 179 repair_options.paranoid_checks = true; | 179 repair_options.paranoid_checks = true; |
| 180 | 180 |
| 181 // RepairDB can drop an unbounded number of leveldb tables (key/value sets). | 181 // RepairDB can drop an unbounded number of leveldb tables (key/value sets). |
| 182 s = leveldb::RepairDB(db_path_.AsUTF8Unsafe(), repair_options); | 182 s = leveldb::RepairDB(db_path_.AsUTF8Unsafe(), repair_options); |
| 183 | 183 |
| 184 leveldb::DB* db = nullptr; | 184 leveldb::DB* db = nullptr; |
| 185 if (s.ok()) { | 185 if (s.ok()) { |
| 186 restore_status = ValueStore::DB_RESTORE_REPAIR_SUCCESS; | 186 restore_status = ValueStore::DB_RESTORE_REPAIR_SUCCESS; |
| 187 s = leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); | 187 s = leveldb_env::DBRegistry::Open(open_options_, db_path_.AsUTF8Unsafe(), &d
b); |
| 188 } | 188 } |
| 189 | 189 |
| 190 if (!s.ok()) { | 190 if (!s.ok()) { |
| 191 if (DeleteDbFile()) { | 191 if (DeleteDbFile()) { |
| 192 restore_status = ValueStore::DB_RESTORE_DELETE_SUCCESS; | 192 restore_status = ValueStore::DB_RESTORE_DELETE_SUCCESS; |
| 193 s = leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); | 193 s = leveldb_env::DBRegistry::Open(open_options_, db_path_.AsUTF8Unsafe(),
&db); |
| 194 } else { | 194 } else { |
| 195 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE; | 195 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (s.ok()) | 199 if (s.ok()) |
| 200 db_.reset(db); | 200 db_.reset(db); |
| 201 else | 201 else |
| 202 db_unrecoverable_ = true; | 202 db_unrecoverable_ = true; |
| 203 | 203 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 228 return ValueStore::Status(); | 228 return ValueStore::Status(); |
| 229 | 229 |
| 230 if (db_unrecoverable_) { | 230 if (db_unrecoverable_) { |
| 231 return ValueStore::Status(ValueStore::CORRUPTION, | 231 return ValueStore::Status(ValueStore::CORRUPTION, |
| 232 ValueStore::DB_RESTORE_DELETE_FAILURE, | 232 ValueStore::DB_RESTORE_DELETE_FAILURE, |
| 233 "Database corrupted"); | 233 "Database corrupted"); |
| 234 } | 234 } |
| 235 | 235 |
| 236 leveldb::DB* db = nullptr; | 236 leveldb::DB* db = nullptr; |
| 237 leveldb::Status ldb_status = | 237 leveldb::Status ldb_status = |
| 238 leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); | 238 leveldb_env::DBRegistry::Open(open_options_, db_path_.AsUTF8Unsafe(), &db)
; |
| 239 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(ldb_status)); | 239 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(ldb_status)); |
| 240 ValueStore::Status status = ToValueStoreError(ldb_status); | 240 ValueStore::Status status = ToValueStoreError(ldb_status); |
| 241 if (ldb_status.ok()) { | 241 if (ldb_status.ok()) { |
| 242 db_.reset(db); | 242 db_.reset(db); |
| 243 } else if (ldb_status.IsCorruption()) { | 243 } else if (ldb_status.IsCorruption()) { |
| 244 status.restore_status = FixCorruption(nullptr); | 244 status.restore_status = FixCorruption(nullptr); |
| 245 if (status.restore_status != ValueStore::DB_RESTORE_DELETE_FAILURE) { | 245 if (status.restore_status != ValueStore::DB_RESTORE_DELETE_FAILURE) { |
| 246 status.code = ValueStore::OK; | 246 status.code = ValueStore::OK; |
| 247 status.message = kRestoredDuringOpen; | 247 status.message = kRestoredDuringOpen; |
| 248 } | 248 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 279 | 279 |
| 280 ValueStore::Status LazyLevelDb::CreateIterator( | 280 ValueStore::Status LazyLevelDb::CreateIterator( |
| 281 const leveldb::ReadOptions& read_options, | 281 const leveldb::ReadOptions& read_options, |
| 282 std::unique_ptr<leveldb::Iterator>* iterator) { | 282 std::unique_ptr<leveldb::Iterator>* iterator) { |
| 283 ValueStore::Status status = EnsureDbIsOpen(); | 283 ValueStore::Status status = EnsureDbIsOpen(); |
| 284 if (!status.ok()) | 284 if (!status.ok()) |
| 285 return status; | 285 return status; |
| 286 *iterator = base::WrapUnique(db_->NewIterator(read_options)); | 286 *iterator = base::WrapUnique(db_->NewIterator(read_options)); |
| 287 return ValueStore::Status(); | 287 return ValueStore::Status(); |
| 288 } | 288 } |
| OLD | NEW |