Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: components/leveldb_proto/leveldb_database.cc

Issue 735823004: Make ProtoDatabase properly handle failed Init (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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));
« no previous file with comments | « components/leveldb_proto/leveldb_database.h ('k') | components/leveldb_proto/proto_database_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698