Chromium Code Reviews| 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..3d9c807c9b628dcd5b6419dd386eba893ec49911 100644 |
| --- a/content/browser/dom_storage/local_storage_context_mojo.cc |
| +++ b/content/browser/dom_storage/local_storage_context_mojo.cc |
| @@ -341,14 +341,12 @@ void LocalStorageContextMojo::PurgeMemory() { |
| it.second->level_db_wrapper()->PurgeMemory(); |
| } |
| -leveldb::mojom::LevelDBDatabaseAssociatedRequest |
| -LocalStorageContextMojo::DatabaseRequestForTesting() { |
| +void LocalStorageContextMojo::SetDatabaseForTesting( |
| + leveldb::mojom::LevelDBDatabaseAssociatedPtr database) { |
| DCHECK_EQ(connection_state_, NO_CONNECTION); |
| connection_state_ = CONNECTION_IN_PROGRESS; |
| - leveldb::mojom::LevelDBDatabaseAssociatedRequest request = |
| - MakeIsolatedRequest(&database_); |
| + database_ = std::move(database); |
| OnDatabaseOpened(true, leveldb::mojom::DatabaseError::OK); |
| - return request; |
| } |
| // static |
| @@ -388,7 +386,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. |
|
dcheng
2017/06/06 22:22:55
I think I've mentioned it elsewhere but it'd be ni
Marijn Kruisselbrink
2017/06/06 22:52:35
It is definitely possible to do so. All of the Loc
dcheng
2017/06/06 23:02:44
Meh. I'll turn my eye the other way and pretend th
|
| + 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 +612,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. |
|
dcheng
2017/06/06 22:22:55
Does this mean the renderer did something bad?
Marijn Kruisselbrink
2017/06/06 22:52:35
No, this is not related to connections to the rend
|
| + std::move(callback).Run(std::vector<LocalStorageUsageInfo>()); |
| + return; |
| + } |
| + |
| database_->GetPrefixed( |
| std::vector<uint8_t>(kMetaPrefix, kMetaPrefix + arraysize(kMetaPrefix)), |
| base::Bind(&LocalStorageContextMojo::OnGotMetaData, |