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 "extensions/browser/value_store/leveldb_value_store.h" | 5 #include "extensions/browser/value_store/leveldb_value_store.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/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "extensions/browser/value_store/value_store_util.h" | 15 #include "extensions/browser/value_store/value_store_util.h" |
| 16 #include "third_party/leveldatabase/env_chromium.h" |
16 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" | 17 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" |
17 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
18 | 19 |
19 namespace util = value_store_util; | 20 namespace util = value_store_util; |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kInvalidJson[] = "Invalid JSON"; | 25 const char kInvalidJson[] = "Invalid JSON"; |
25 const char kCannotSerialize[] = "Cannot serialize value to JSON"; | 26 const char kCannotSerialize[] = "Cannot serialize value to JSON"; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 322 |
322 scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() { | 323 scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() { |
323 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 324 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
324 | 325 |
325 if (db_) | 326 if (db_) |
326 return util::NoError(); | 327 return util::NoError(); |
327 | 328 |
328 leveldb::Options options; | 329 leveldb::Options options; |
329 options.max_open_files = 0; // Use minimum. | 330 options.max_open_files = 0; // Use minimum. |
330 options.create_if_missing = true; | 331 options.create_if_missing = true; |
| 332 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
331 | 333 |
332 leveldb::DB* db = NULL; | 334 leveldb::DB* db = NULL; |
333 leveldb::Status status = | 335 leveldb::Status status = |
334 leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db); | 336 leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db); |
335 if (!status.ok()) | 337 if (!status.ok()) |
336 return ToValueStoreError(status, util::NoKey()); | 338 return ToValueStoreError(status, util::NoKey()); |
337 | 339 |
338 CHECK(db); | 340 CHECK(db); |
339 db_.reset(db); | 341 db_.reset(db); |
340 return util::NoError(); | 342 return util::NoError(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 CHECK(!status.ok()); | 435 CHECK(!status.ok()); |
434 CHECK(!status.IsNotFound()); // not an error | 436 CHECK(!status.IsNotFound()); // not an error |
435 | 437 |
436 std::string message = status.ToString(); | 438 std::string message = status.ToString(); |
437 // The message may contain |db_path_|, which may be considered sensitive | 439 // The message may contain |db_path_|, which may be considered sensitive |
438 // data, and those strings are passed to the extension, so strip it out. | 440 // data, and those strings are passed to the extension, so strip it out. |
439 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); | 441 ReplaceSubstringsAfterOffset(&message, 0u, db_path_.AsUTF8Unsafe(), "..."); |
440 | 442 |
441 return Error::Create(CORRUPTION, message, key.Pass()); | 443 return Error::Create(CORRUPTION, message, key.Pass()); |
442 } | 444 } |
OLD | NEW |