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

Unified Diff: content/browser/dom_storage/local_storage_context_mojo.cc

Issue 2847013002: Switch to mojo localstorage backend by default. (Closed)
Patch Set: minor cleanup Created 3 years, 7 months 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: content/browser/dom_storage/local_storage_context_mojo.cc
diff --git a/content/browser/dom_storage/local_storage_context_mojo.cc b/content/browser/dom_storage/local_storage_context_mojo.cc
index 2be6213f8ce2f40c4be1d0821cb30765217a20f4..e32a02479cb1cacbcffc06a5165c84c027a93a80 100644
--- a/content/browser/dom_storage/local_storage_context_mojo.cc
+++ b/content/browser/dom_storage/local_storage_context_mojo.cc
@@ -388,7 +388,14 @@ void LocalStorageContextMojo::RunWhenConnected(base::OnceClosure callback) {
void LocalStorageContextMojo::InitiateConnection(bool in_memory_only) {
DCHECK_EQ(connection_state_, CONNECTION_IN_PROGRESS);
- CHECK(connector_);
+
+ // Unit tests might not always have a Connector, use in-memory only if that
+ // happens.
+ if (!connector_) {
+ OnDatabaseOpened(false, leveldb::mojom::DatabaseError::OK);
+ return;
+ }
+
if (!subdirectory_.empty() && !in_memory_only) {
// We were given a subdirectory to write to. Get it and use a disk backed
// database.
@@ -607,6 +614,13 @@ LevelDBWrapperImpl* LocalStorageContextMojo::GetOrCreateDBWrapper(
void LocalStorageContextMojo::RetrieveStorageUsage(
GetStorageUsageCallback callback) {
+ if (!database_) {
+ // If for whatever reason no leveldb database is available, no storage is
+ // used, so return an empty array.
+ std::move(callback).Run(std::vector<LocalStorageUsageInfo>());
+ return;
+ }
+
database_->GetPrefixed(
std::vector<uint8_t>(kMetaPrefix, kMetaPrefix + arraysize(kMetaPrefix)),
base::Bind(&LocalStorageContextMojo::OnGotMetaData,

Powered by Google App Engine
This is Rietveld 408576698