Index: components/leveldb_proto/leveldb_database.cc |
diff --git a/components/leveldb_proto/leveldb_database.cc b/components/leveldb_proto/leveldb_database.cc |
index 65d68a9d138da76dbfd6274abb05e4b1d19f2f2f..45f220e9576c565e6dfcbbdec81d34def93849c5 100644 |
--- a/components/leveldb_proto/leveldb_database.cc |
+++ b/components/leveldb_proto/leveldb_database.cc |
@@ -23,14 +23,13 @@ namespace leveldb_proto { |
LevelDB::LevelDB() {} |
-LevelDB::~LevelDB() { DFAKE_SCOPED_LOCK(thread_checker_); } |
- |
-bool LevelDB::Init(const base::FilePath& database_dir) { |
+LevelDB::~LevelDB() { |
DFAKE_SCOPED_LOCK(thread_checker_); |
+} |
- leveldb::Options options; |
- options.create_if_missing = true; |
- options.max_open_files = 0; // Use minimum. |
+bool LevelDB::InitWithOptions(const base::FilePath& database_dir, |
+ const leveldb::Options& options) { |
+ DFAKE_SCOPED_LOCK(thread_checker_); |
std::string path = database_dir.AsUTF8Unsafe(); |
@@ -52,9 +51,19 @@ bool LevelDB::Init(const base::FilePath& database_dir) { |
return false; |
} |
+bool LevelDB::Init(const base::FilePath& database_dir) { |
+ leveldb::Options options; |
+ options.create_if_missing = true; |
+ options.max_open_files = 0; // Use minimum. |
+ return InitWithOptions(database_dir, options); |
+} |
+ |
bool LevelDB::Save(const base::StringPairs& entries_to_save, |
const std::vector<std::string>& keys_to_remove) { |
DFAKE_SCOPED_LOCK(thread_checker_); |
+ if (!db_) { |
+ return false; |
+ } |
leveldb::WriteBatch updates; |
for (base::StringPairs::const_iterator it = entries_to_save.begin(); |
@@ -79,6 +88,9 @@ bool LevelDB::Save(const base::StringPairs& entries_to_save, |
bool LevelDB::Load(std::vector<std::string>* entries) { |
DFAKE_SCOPED_LOCK(thread_checker_); |
+ if (!db_) { |
+ return false; |
+ } |
leveldb::ReadOptions options; |
scoped_ptr<leveldb::Iterator> db_iterator(db_->NewIterator(options)); |