Commit e534d9c2 authored by Austin Sullivan's avatar Austin Sullivan Committed by Chromium LUCI CQ

GetDatabaseInfo: don't create a new database if one doesn't exist

GetDatabaseNames was refactored to use GetDatabaseInfo here [1].
GetDatabaseNames was formerly special-cased to not create the database
if one didn't exist, but this was lost in the refactor.

[1] https://crrev.com/c/2557571

Bug: 1163336
Change-Id: I61f1fb0e6ab60c00143ca1471690bf869119aaec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622988Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Austin Sullivan <asully@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845680}
parent f87f3433
...@@ -197,13 +197,18 @@ void IndexedDBFactoryImpl::GetDatabaseInfo( ...@@ -197,13 +197,18 @@ void IndexedDBFactoryImpl::GetDatabaseInfo(
IndexedDBOriginStateHandle origin_state_handle; IndexedDBOriginStateHandle origin_state_handle;
leveldb::Status s; leveldb::Status s;
IndexedDBDatabaseError error; IndexedDBDatabaseError error;
std::vector<blink::mojom::IDBNameAndVersionPtr> names_and_versions;
// Note: Any data loss information here is not piped up to the renderer, and // Note: Any data loss information here is not piped up to the renderer, and
// will be lost. // will be lost.
std::tie(origin_state_handle, s, error, std::ignore, std::ignore) = std::tie(origin_state_handle, s, error, std::ignore, std::ignore) =
GetOrOpenOriginFactory(origin, data_directory, GetOrOpenOriginFactory(origin, data_directory,
/*create_if_missing=*/true); /*create_if_missing=*/false);
if (!origin_state_handle.IsHeld() || !origin_state_handle.origin_state()) { if (!origin_state_handle.IsHeld() || !origin_state_handle.origin_state()) {
if (s.IsNotFound()) {
callbacks->OnSuccess(std::move(names_and_versions));
} else {
callbacks->OnError(error); callbacks->OnError(error);
}
if (s.IsCorruption()) if (s.IsCorruption())
HandleBackingStoreCorruption(origin, error); HandleBackingStoreCorruption(origin, error);
return; return;
...@@ -211,7 +216,6 @@ void IndexedDBFactoryImpl::GetDatabaseInfo( ...@@ -211,7 +216,6 @@ void IndexedDBFactoryImpl::GetDatabaseInfo(
IndexedDBOriginState* factory = origin_state_handle.origin_state(); IndexedDBOriginState* factory = origin_state_handle.origin_state();
IndexedDBMetadataCoding metadata_coding; IndexedDBMetadataCoding metadata_coding;
std::vector<blink::mojom::IDBNameAndVersionPtr> names_and_versions;
s = metadata_coding.ReadDatabaseNamesAndVersions( s = metadata_coding.ReadDatabaseNamesAndVersions(
factory->backing_store_->db(), factory->backing_store_->db(),
factory->backing_store_->origin_identifier(), &names_and_versions); factory->backing_store_->origin_identifier(), &names_and_versions);
......
...@@ -671,7 +671,7 @@ TEST_F(IndexedDBFactoryTest, DeleteDatabaseWithForceClose) { ...@@ -671,7 +671,7 @@ TEST_F(IndexedDBFactoryTest, DeleteDatabaseWithForceClose) {
EXPECT_TRUE(factory()->GetOriginFactory(origin)->IsClosing()); EXPECT_TRUE(factory()->GetOriginFactory(origin)->IsClosing());
} }
TEST_F(IndexedDBFactoryTest, GetDatabaseNames) { TEST_F(IndexedDBFactoryTest, GetDatabaseNames_NoFactory) {
SetupContext(); SetupContext();
auto callbacks = base::MakeRefCounted<MockIndexedDBCallbacks>( auto callbacks = base::MakeRefCounted<MockIndexedDBCallbacks>(
...@@ -682,9 +682,32 @@ TEST_F(IndexedDBFactoryTest, GetDatabaseNames) { ...@@ -682,9 +682,32 @@ TEST_F(IndexedDBFactoryTest, GetDatabaseNames) {
factory()->GetDatabaseInfo(callbacks, origin, context()->data_path()); factory()->GetDatabaseInfo(callbacks, origin, context()->data_path());
EXPECT_TRUE(callbacks->info_called()); EXPECT_TRUE(callbacks->info_called());
// Since there are no more references the factory should be closing. // Don't create a factory if one doesn't exist.
EXPECT_FALSE(factory()->GetOriginFactory(origin));
}
TEST_F(IndexedDBFactoryTest, GetDatabaseNames_ExistingFactory) {
SetupContext();
auto callbacks = base::MakeRefCounted<MockIndexedDBCallbacks>(
/*expect_connection=*/false);
const Origin origin = Origin::Create(GURL("http://localhost:81"));
IndexedDBOriginStateHandle origin_state_handle;
leveldb::Status s;
std::tie(origin_state_handle, s, std::ignore, std::ignore, std::ignore) =
factory()->GetOrOpenOriginFactory(origin, context()->data_path(),
/*create_if_missing=*/true);
EXPECT_TRUE(origin_state_handle.IsHeld()) << s.ToString();
factory()->GetDatabaseInfo(callbacks, origin, context()->data_path());
EXPECT_TRUE(callbacks->info_called());
EXPECT_TRUE(factory()->GetOriginFactory(origin)); EXPECT_TRUE(factory()->GetOriginFactory(origin));
EXPECT_TRUE(factory()->GetOriginFactory(origin)->IsClosing()); // GetDatabaseInfo didn't create the factory, so it shouldn't close it.
EXPECT_FALSE(factory()->GetOriginFactory(origin)->IsClosing());
} }
class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks { class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment