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 "components/leveldb_proto/leveldb_database.h" | 5 #include "components/leveldb_proto/leveldb_database.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "third_party/leveldatabase/env_chromium.h" |
15 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/db.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/options.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
18 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
19 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 21 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
21 | 22 |
22 namespace leveldb_proto { | 23 namespace leveldb_proto { |
23 | 24 |
24 LevelDB::LevelDB() {} | 25 LevelDB::LevelDB() {} |
(...skipping 23 matching lines...) Expand all Loading... |
48 | 49 |
49 LOG(WARNING) << "Unable to open " << database_dir.value() << ": " | 50 LOG(WARNING) << "Unable to open " << database_dir.value() << ": " |
50 << status.ToString(); | 51 << status.ToString(); |
51 return false; | 52 return false; |
52 } | 53 } |
53 | 54 |
54 bool LevelDB::Init(const base::FilePath& database_dir) { | 55 bool LevelDB::Init(const base::FilePath& database_dir) { |
55 leveldb::Options options; | 56 leveldb::Options options; |
56 options.create_if_missing = true; | 57 options.create_if_missing = true; |
57 options.max_open_files = 0; // Use minimum. | 58 options.max_open_files = 0; // Use minimum. |
| 59 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
58 return InitWithOptions(database_dir, options); | 60 return InitWithOptions(database_dir, options); |
59 } | 61 } |
60 | 62 |
61 bool LevelDB::Save(const base::StringPairs& entries_to_save, | 63 bool LevelDB::Save(const base::StringPairs& entries_to_save, |
62 const std::vector<std::string>& keys_to_remove) { | 64 const std::vector<std::string>& keys_to_remove) { |
63 DFAKE_SCOPED_LOCK(thread_checker_); | 65 DFAKE_SCOPED_LOCK(thread_checker_); |
64 if (!db_) { | 66 if (!db_) { |
65 return false; | 67 return false; |
66 } | 68 } |
67 | 69 |
(...skipping 28 matching lines...) Expand all Loading... |
96 scoped_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); | 98 scoped_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); |
97 for (db_iterator->SeekToFirst(); db_iterator->Valid(); db_iterator->Next()) { | 99 for (db_iterator->SeekToFirst(); db_iterator->Valid(); db_iterator->Next()) { |
98 leveldb::Slice value_slice = db_iterator->value(); | 100 leveldb::Slice value_slice = db_iterator->value(); |
99 std::string entry(value_slice.data(), value_slice.size()); | 101 std::string entry(value_slice.data(), value_slice.size()); |
100 entries->push_back(entry); | 102 entries->push_back(entry); |
101 } | 103 } |
102 return true; | 104 return true; |
103 } | 105 } |
104 | 106 |
105 } // namespace leveldb_proto | 107 } // namespace leveldb_proto |
OLD | NEW |