diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 10:05:33 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 10:05:33 +0000 |
commit | 0e719d5145f93900b9c9111272de5e2b23e464bc (patch) | |
tree | f934109051b81c53fce86afe9d50dffe063c224e | |
parent | 8a6abd133d36460597a5ac321ffceecc6949f4ca (diff) | |
download | chromium_src-0e719d5145f93900b9c9111272de5e2b23e464bc.zip chromium_src-0e719d5145f93900b9c9111272de5e2b23e464bc.tar.gz chromium_src-0e719d5145f93900b9c9111272de5e2b23e464bc.tar.bz2 |
SessionStorageDatabase: Readability changes.
BUG=NONE
TEST=NONE
Review URL: https://chromiumcodereview.appspot.com/10356014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137392 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/dom_storage/session_storage_database.cc | 18 | ||||
-rw-r--r-- | webkit/dom_storage/session_storage_database.h | 15 | ||||
-rw-r--r-- | webkit/dom_storage/session_storage_database_unittest.cc | 1 |
3 files changed, 23 insertions, 11 deletions
diff --git a/webkit/dom_storage/session_storage_database.cc b/webkit/dom_storage/session_storage_database.cc index 11db6e5..66e502f 100644 --- a/webkit/dom_storage/session_storage_database.cc +++ b/webkit/dom_storage/session_storage_database.cc @@ -41,7 +41,8 @@ SessionStorageDatabase::SessionStorageDatabase(const FilePath& file_path) : file_path_(file_path), db_error_(false), is_inconsistent_(false), - namespace_offset_(0) { } + namespace_offset_(0) { +} SessionStorageDatabase::~SessionStorageDatabase() { } @@ -205,7 +206,7 @@ bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { } leveldb::DB* db; - leveldb::Status s = TryToOpen(file_path_, &db); + leveldb::Status s = TryToOpen(&db); if (!s.ok()) { LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() << ", error: " << s.ToString(); @@ -213,7 +214,7 @@ bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { // Clear the directory and try again. file_util::Delete(file_path_, true); - s = TryToOpen(file_path_, &db); + s = TryToOpen(&db); if (!s.ok()) { LOG(WARNING) << "Failed to open leveldb in " << file_path_.value() << ", error: " << s.ToString(); @@ -227,17 +228,16 @@ bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { return GetNextNamespaceId(&namespace_offset_); } -leveldb::Status SessionStorageDatabase::TryToOpen(const FilePath& file_path, - leveldb::DB** db) { +leveldb::Status SessionStorageDatabase::TryToOpen(leveldb::DB** db) { leveldb::Options options; // The directory exists but a valid leveldb database might not exist inside it // (e.g., a subset of the needed files might be missing). Handle this // situation gracefully by creating the database now. options.create_if_missing = true; #if defined(OS_WIN) - return leveldb::DB::Open(options, WideToUTF8(file_path.value()), db); + return leveldb::DB::Open(options, WideToUTF8(file_path_.value()), db); #elif defined(OS_POSIX) - return leveldb::DB::Open(options, file_path.value(), db); + return leveldb::DB::Open(options, file_path_.value(), db); #endif } @@ -275,7 +275,7 @@ bool SessionStorageDatabase::DatabaseErrorCheck(bool ok) { bool SessionStorageDatabase::CreateNamespace(int64 namespace_id, bool ok_if_exists, leveldb::WriteBatch* batch) { - std::string namespace_prefix = NamespacePrefix(); + leveldb::Slice namespace_prefix = NamespacePrefix(); std::string dummy; leveldb::Status s = db_->Get(leveldb::ReadOptions(), namespace_prefix, &dummy); @@ -419,7 +419,7 @@ bool SessionStorageDatabase::CreateMapForArea(int64 namespace_id, const GURL& origin, std::string* map_id, leveldb::WriteBatch* batch) { - std::string next_map_id_key = NextMapIdKey(); + leveldb::Slice next_map_id_key = NextMapIdKey(); leveldb::Status s = db_->Get(leveldb::ReadOptions(), next_map_id_key, map_id); if (!DatabaseErrorCheck(s.ok() || s.IsNotFound())) return false; diff --git a/webkit/dom_storage/session_storage_database.h b/webkit/dom_storage/session_storage_database.h index 5b427fd..822dbc3 100644 --- a/webkit/dom_storage/session_storage_database.h +++ b/webkit/dom_storage/session_storage_database.h @@ -29,7 +29,7 @@ namespace dom_storage { // origins. All DomStorageAreas for session storage share the same // SessionStorageDatabase. class SessionStorageDatabase : - public base::RefCountedThreadSafe<SessionStorageDatabase> { + public base::RefCountedThreadSafe<SessionStorageDatabase> { public: explicit SessionStorageDatabase(const FilePath& file_path); @@ -68,8 +68,19 @@ class SessionStorageDatabase : ~SessionStorageDatabase(); + // Opens the database at file_path_ if it exists already and creates it if + // |create_if_needed| is true. Returns true if the database was opened, false + // if the opening failed or was not necessary (the database doesn't exist and + // |create_if_needed| is false). The possible failures are: + // - leveldb cannot open the database. + // - The database is in an inconsistent or errored state. bool LazyOpen(bool create_if_needed); - leveldb::Status TryToOpen(const FilePath& file_path, leveldb::DB** db); + + // Tries to open the database at file_path_, assigns |db| to point to the + // opened leveldb::DB instance. + leveldb::Status TryToOpen(leveldb::DB** db); + + // Returns true if the database is already open, false otherwise. bool IsOpen() const; // Helpers for checking caller erros, invariants and database errors. All diff --git a/webkit/dom_storage/session_storage_database_unittest.cc b/webkit/dom_storage/session_storage_database_unittest.cc index 150b9a4..a9d159c 100644 --- a/webkit/dom_storage/session_storage_database_unittest.cc +++ b/webkit/dom_storage/session_storage_database_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + #include "webkit/dom_storage/session_storage_database.h" #include <algorithm> |