0

Quota: Cleanup StorageType from QuotaClients

This change removes usages of StorageType in QuotaClient methods.
After StorageType::kSyncable deprecation, all other storage types
except kTemporary are deprecated. So we no longer need to specify
StorageType. Data that was previously associated with kSyncable
is now part of kTemporary.

Main part of this change is in quota_client.mojom and updates
all overrides and callers of impacted methods.

Bug: 40211051
Change-Id: I000a457346dd1e383c6252dfa22c75cfd3c6e721
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6368800
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1435031}
This commit is contained in:
Ayu Ishii
2025-03-19 12:47:33 -07:00
committed by Chromium LUCI CQ
parent 78051cb92c
commit 09f67035b2
27 changed files with 112 additions and 213 deletions

@ -12,7 +12,6 @@
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
@ -37,14 +36,13 @@ void QuotaClientCallbackWrapper::GetBucketUsage(
mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(callback), 0));
}
void QuotaClientCallbackWrapper::GetStorageKeysForType(
blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) {
void QuotaClientCallbackWrapper::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
wrapped_client_->GetStorageKeysForType(
type, mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), std::vector<blink::StorageKey>()));
wrapped_client_->GetDefaultStorageKeys(
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), std::vector<blink::StorageKey>()));
}
void QuotaClientCallbackWrapper::DeleteBucketData(
@ -59,12 +57,11 @@ void QuotaClientCallbackWrapper::DeleteBucketData(
}
void QuotaClientCallbackWrapper::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
wrapped_client_->PerformStorageCleanup(
type, mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(callback)));
mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(callback)));
}
} // namespace storage

@ -54,12 +54,10 @@ class COMPONENT_EXPORT(STORAGE_SERVICE_PUBLIC) QuotaClientCallbackWrapper
// mojom::QuotaClient.
void GetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
private:
SEQUENCE_CHECKER(sequence_checker_);

@ -25,8 +25,7 @@ interface QuotaClient {
// all tracks of a `bucket`.
GetBucketUsage(BucketLocator bucket) => (int64 usage);
// Returns a list of storage keys that have data in the default bucket for
// `type` storage.
// Returns a list of storage keys that have data in the default bucket.
//
// This method is currently used to bootstrap the buckets table in the quota
// database with data produced by old code. No other uses should be added.
@ -36,17 +35,16 @@ interface QuotaClient {
//
// WARNING: Implementations of this interface method must not use the
// QuotaManager or else a deadlock could result. The QuotaManager waits until
// all QuotaClient::GetStorageKeysForType calls have finished before
// all QuotaClient::GetDefaultStorageKeys calls have finished before
// processing other tasks, and a deadlock would occur if a
// QuotaClient::GetStorageKeysForType implementation waits for a QuotaManager
// QuotaClient::GetDefaultStorageKeys implementation waits for a QuotaManager
// task to finish.
GetStorageKeysForType(blink.mojom.StorageType type)
=> (array<blink.mojom.StorageKey> storage_keys);
GetDefaultStorageKeys() => (array<blink.mojom.StorageKey> storage_keys);
// Returns after all data belonging to `bucket` has been deleted.
DeleteBucketData(BucketLocator bucket)
=> (blink.mojom.QuotaStatusCode status);
// An opportunity to perform a cleanup step after major deletions.
PerformStorageCleanup(blink.mojom.StorageType type) => ();
PerformStorageCleanup() => ();
};

@ -528,7 +528,7 @@ void CacheStorageManager::GetBucketUsageDidGetExists(
// default bucket.
void CacheStorageManager::GetStorageKeys(
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback) {
storage::mojom::QuotaClient::GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (IsMemoryBacked()) {
@ -842,7 +842,7 @@ base::FilePath CacheStorageManager::ConstructThirdPartyAndNonDefaultRootPath(
// default bucket. Keep this function to return a vector of StorageKeys, instead
// of buckets.
void CacheStorageManager::ListStorageKeysOnTaskRunner(
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback,
storage::mojom::QuotaClient::GetDefaultStorageKeysCallback callback,
std::vector<storage::BucketLocator> buckets) {
// Note that bucket IDs will not be populated in the `buckets` entries.
std::vector<blink::StorageKey> out_storage_keys;

@ -88,7 +88,7 @@ class CONTENT_EXPORT CacheStorageManager
storage::mojom::QuotaClient::GetBucketUsageCallback callback);
void GetStorageKeys(
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback);
storage::mojom::QuotaClient::GetDefaultStorageKeysCallback callback);
void DeleteOriginData(
const std::set<url::Origin>& origins,
storage::mojom::CacheStorageOwner owner,
@ -173,7 +173,7 @@ class CONTENT_EXPORT CacheStorageManager
}
void ListStorageKeysOnTaskRunner(
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback,
storage::mojom::QuotaClient::GetDefaultStorageKeysCallback callback,
std::vector<storage::BucketLocator> buckets);
bool IsMemoryBacked() const { return profile_path_.empty(); }

@ -2820,10 +2820,9 @@ class CacheStorageQuotaClientTest : public CacheStorageManagerTest {
return future.Get();
}
size_t QuotaGetStorageKeysForType() {
size_t QuotaGetDefaultStorageKeys() {
base::RunLoop loop;
quota_client_->GetStorageKeysForType(
StorageType::kTemporary,
quota_client_->GetDefaultStorageKeys(
base::BindOnce(&CacheStorageQuotaClientTest::StorageKeysCallback,
base::Unretained(this), base::Unretained(&loop)));
loop.Run();
@ -2862,23 +2861,23 @@ TEST_P(CacheStorageQuotaClientTestP, QuotaGetBucketUsage) {
EXPECT_LT(0, QuotaGetBucketUsage(bucket_locator1_));
}
TEST_P(CacheStorageQuotaClientTestP, QuotaGetStorageKeysForType) {
EXPECT_EQ(0u, QuotaGetStorageKeysForType());
TEST_P(CacheStorageQuotaClientTestP, QuotaGetDefaultStorageKeys) {
EXPECT_EQ(0u, QuotaGetDefaultStorageKeys());
EXPECT_TRUE(Open(bucket_locator1_, u"foo"));
EXPECT_TRUE(Open(bucket_locator1_, u"bar"));
EXPECT_TRUE(Open(bucket_locator2_, u"foo"));
EXPECT_EQ(2u, QuotaGetStorageKeysForType());
EXPECT_EQ(2u, QuotaGetDefaultStorageKeys());
}
TEST_P(CacheStorageQuotaClientTestP,
QuotaGetStorageKeysForTypeDifferentOwners) {
EXPECT_EQ(0u, QuotaGetStorageKeysForType());
QuotaGetDefaultStorageKeysDifferentOwners) {
EXPECT_EQ(0u, QuotaGetDefaultStorageKeys());
EXPECT_TRUE(Open(bucket_locator1_, u"foo"));
// The |quota_client_| is registered for
// storage::mojom::CacheStorageOwner::kCacheAPI, so this Open is ignored.
EXPECT_TRUE(Open(bucket_locator2_, u"bar",
storage::mojom::CacheStorageOwner::kBackgroundFetch));
EXPECT_EQ(1u, QuotaGetStorageKeysForType());
EXPECT_EQ(1u, QuotaGetDefaultStorageKeys());
}
TEST_P(CacheStorageQuotaClientTestP, QuotaDeleteBucketData) {

@ -7,7 +7,6 @@
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "content/browser/cache_storage/cache_storage_manager.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace content {
@ -26,7 +25,6 @@ void CacheStorageQuotaClient::GetBucketUsage(
const storage::BucketLocator& bucket,
GetBucketUsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(bucket.type, blink::mojom::StorageType::kTemporary);
if (!CacheStorageManager::IsValidQuotaStorageKey(bucket.storage_key)) {
std::move(callback).Run(0);
@ -36,11 +34,9 @@ void CacheStorageQuotaClient::GetBucketUsage(
cache_manager_->GetBucketUsage(bucket, owner_, std::move(callback));
}
void CacheStorageQuotaClient::GetStorageKeysForType(
blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) {
void CacheStorageQuotaClient::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
cache_manager_->GetStorageKeys(owner_, std::move(callback));
}
@ -49,7 +45,6 @@ void CacheStorageQuotaClient::DeleteBucketData(
const storage::BucketLocator& bucket,
DeleteBucketDataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(bucket.type, blink::mojom::StorageType::kTemporary);
if (!CacheStorageManager::IsValidQuotaStorageKey(bucket.storage_key)) {
std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk);
@ -60,7 +55,6 @@ void CacheStorageQuotaClient::DeleteBucketData(
}
void CacheStorageQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::move(callback).Run();

@ -10,7 +10,6 @@
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "content/common/content_export.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
struct BucketLocator;
@ -39,12 +38,10 @@ class CONTENT_EXPORT CacheStorageQuotaClient
// storage::mojom::QuotaClient method overrides.
void GetBucketUsage(const storage::BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const storage::BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
static storage::QuotaClientType GetClientTypeFromOwner(
storage::mojom::CacheStorageOwner owner);

@ -1180,10 +1180,8 @@ void IndexedDBContextImpl::GetBucketUsage(const BucketLocator& bucket,
}
}
void IndexedDBContextImpl::GetStorageKeysForType(
blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) {
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
void IndexedDBContextImpl::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
std::vector<StorageKey> storage_keys;
storage_keys.reserve(bucket_set_.size());
for (const BucketLocator& bucket_locator : bucket_set_) {
@ -1193,9 +1191,7 @@ void IndexedDBContextImpl::GetStorageKeysForType(
}
void IndexedDBContextImpl::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_EQ(type, blink::mojom::StorageType::kTemporary);
std::move(callback).Run();
}

@ -138,12 +138,10 @@ class CONTENT_EXPORT IndexedDBContextImpl
// storage::mojom::QuotaClient implementation:
void GetBucketUsage(const storage::BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const storage::BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
// Exposed for testing.
bool BucketContextExists(storage::BucketId bucket_id);

@ -37,10 +37,6 @@
#include "url/origin.h"
using ::blink::StorageKey;
using ::blink::mojom::StorageType;
// Declared to shorten the line lengths.
static const StorageType kTemp = StorageType::kTemporary;
namespace content::indexed_db {
@ -114,18 +110,16 @@ class IndexedDBQuotaClientTest : public testing::Test,
return result;
}
std::vector<StorageKey> GetStorageKeysForType(
StorageType type,
std::vector<StorageKey> GetDefaultStorageKeys(
IndexedDBContextImpl* context = nullptr) {
std::vector<StorageKey> result;
base::RunLoop loop;
(context ? context : idb_context_.get())
->GetStorageKeysForType(
type, base::BindLambdaForTesting(
[&](const std::vector<StorageKey>& storage_keys) {
result = storage_keys;
loop.Quit();
}));
->GetDefaultStorageKeys(base::BindLambdaForTesting(
[&](const std::vector<StorageKey>& storage_keys) {
result = storage_keys;
loop.Quit();
}));
loop.Run();
return result;
}
@ -295,20 +289,20 @@ TEST_P(IndexedDBQuotaClientTest, GetBucketUsageCustom) {
EXPECT_EQ(3, GetBucketUsage(bucket_b));
}
TEST_P(IndexedDBQuotaClientTest, GetStorageKeysForTypeFirstParty) {
EXPECT_TRUE(GetStorageKeysForType(kTemp).empty());
TEST_P(IndexedDBQuotaClientTest, GetDefaultStorageKeysFirstParty) {
EXPECT_TRUE(GetDefaultStorageKeys().empty());
AddFakeIndexedDB(kStorageKeyFirstPartyA, 1000);
std::vector<StorageKey> storage_keys = GetStorageKeysForType(kTemp);
std::vector<StorageKey> storage_keys = GetDefaultStorageKeys();
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyFirstPartyA));
}
TEST_P(IndexedDBQuotaClientTest, GetStorageKeysForTypeThirdParty) {
EXPECT_TRUE(GetStorageKeysForType(kTemp).empty());
TEST_P(IndexedDBQuotaClientTest, GetDefaultStorageKeysThirdParty) {
EXPECT_TRUE(GetDefaultStorageKeys().empty());
AddFakeIndexedDB(kStorageKeyThirdPartyA, 1000);
std::vector<StorageKey> storage_keys = GetStorageKeysForType(kTemp);
std::vector<StorageKey> storage_keys = GetDefaultStorageKeys();
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyThirdPartyA));
}
@ -413,7 +407,7 @@ TEST_P(IndexedDBQuotaClientTest, NonDefaultBucketThirdParty) {
TEST_P(IndexedDBQuotaClientTest,
GetStorageKeyUsageForNonexistentKeyFirstParty) {
AddFakeIndexedDB(kStorageKeyFirstPartyA, 1000);
std::vector<StorageKey> storage_keys = GetStorageKeysForType(kTemp);
std::vector<StorageKey> storage_keys = GetDefaultStorageKeys();
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyFirstPartyA));
@ -426,7 +420,7 @@ TEST_P(IndexedDBQuotaClientTest,
TEST_P(IndexedDBQuotaClientTest,
GetStorageKeyUsageForNonexistentKeyThirdParty) {
AddFakeIndexedDB(kStorageKeyThirdPartyA, 1000);
std::vector<StorageKey> storage_keys = GetStorageKeysForType(kTemp);
std::vector<StorageKey> storage_keys = GetDefaultStorageKeys();
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyThirdPartyA));
@ -439,7 +433,7 @@ TEST_P(IndexedDBQuotaClientTest,
TEST_P(IndexedDBQuotaClientTest,
GetStorageKeyUsageForNonexistentKeyMixedParty) {
AddFakeIndexedDB(kStorageKeyFirstPartyA, 1000);
std::vector<StorageKey> storage_keys = GetStorageKeysForType(kTemp);
std::vector<StorageKey> storage_keys = GetDefaultStorageKeys();
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyFirstPartyA));
@ -473,8 +467,7 @@ TEST_P(IndexedDBQuotaClientTest, IncognitoQuotaFirstParty) {
ASSERT_OK_AND_ASSIGN(auto bucket_a, bucket_future.Take());
// No FakeIndexDB is added.
EXPECT_TRUE(
GetStorageKeysForType(kTemp, incognito_idb_context.get()).empty());
EXPECT_TRUE(GetDefaultStorageKeys(incognito_idb_context.get()).empty());
EXPECT_EQ(0, GetBucketUsage(bucket_a.ToBucketLocator(),
incognito_idb_context.get()));
}
@ -499,8 +492,7 @@ TEST_P(IndexedDBQuotaClientTest, IncognitoQuotaThirdParty) {
ASSERT_OK_AND_ASSIGN(auto bucket_a, bucket_future.Take());
// No FakeIndexDB is added.
EXPECT_TRUE(
GetStorageKeysForType(kTemp, incognito_idb_context.get()).empty());
EXPECT_TRUE(GetDefaultStorageKeys(incognito_idb_context.get()).empty());
EXPECT_EQ(0, GetBucketUsage(bucket_a.ToBucketLocator(),
incognito_idb_context.get()));
}

@ -49,7 +49,6 @@ void ServiceWorkerQuotaClient::GetBucketUsage(
const storage::BucketLocator& bucket,
GetBucketUsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(bucket.type, StorageType::kTemporary);
// Skip non-default buckets until Storage Buckets are supported for
// ServiceWorkers.
@ -63,11 +62,9 @@ void ServiceWorkerQuotaClient::GetBucketUsage(
base::BindOnce(&FindUsageForStorageKey, std::move(callback)));
}
void ServiceWorkerQuotaClient::GetStorageKeysForType(
StorageType type,
GetStorageKeysForTypeCallback callback) {
void ServiceWorkerQuotaClient::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->registry()->GetRegisteredStorageKeys(std::move(callback));
}
@ -75,7 +72,6 @@ void ServiceWorkerQuotaClient::DeleteBucketData(
const storage::BucketLocator& bucket,
DeleteBucketDataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(bucket.type, StorageType::kTemporary);
// Skip non-default buckets until Storage Buckets are supported for
// ServiceWorkers.
@ -90,10 +86,8 @@ void ServiceWorkerQuotaClient::DeleteBucketData(
}
void ServiceWorkerQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(type, StorageType::kTemporary);
context_->registry()->PerformStorageCleanup(std::move(callback));
}

@ -11,7 +11,6 @@
#include "base/thread_annotations.h"
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
struct BucketLocator;
@ -40,12 +39,10 @@ class ServiceWorkerQuotaClient : public storage::mojom::QuotaClient {
// storage::mojom::QuotaClient override methods.
void GetBucketUsage(const storage::BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const storage::BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
private:
friend class ServiceWorkerContextWrapper;

@ -24,7 +24,6 @@
#include "storage/browser/quota/quota_client_type.h"
#include "storage/common/database/database_identifier.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "url/origin.h"
using ::blink::StorageKey;
@ -45,7 +44,6 @@ void DatabaseQuotaClient::GetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
DCHECK_EQ(bucket.type, StorageType::kTemporary);
// Skip non-default buckets because Storage Buckets are not planned to be
// supported by WebSQL.
@ -63,12 +61,10 @@ void DatabaseQuotaClient::GetBucketUsage(const BucketLocator& bucket,
}
}
void DatabaseQuotaClient::GetStorageKeysForType(
StorageType type,
GetStorageKeysForTypeCallback callback) {
void DatabaseQuotaClient::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
DCHECK_EQ(type, StorageType::kTemporary);
std::vector<StorageKey> all_storage_keys;
std::vector<std::string> origin_identifiers;
@ -85,7 +81,6 @@ void DatabaseQuotaClient::DeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
DCHECK_EQ(bucket.type, StorageType::kTemporary);
// Skip non-default buckets because Storage Buckets are not planned to be
// supported by WebSQL.
@ -106,11 +101,9 @@ void DatabaseQuotaClient::DeleteBucketData(const BucketLocator& bucket,
}
void DatabaseQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
DCHECK_EQ(type, StorageType::kTemporary);
std::move(callback).Run();
}

@ -12,7 +12,6 @@
#include "base/thread_annotations.h"
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
@ -35,12 +34,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabaseQuotaClient
// mojom::QuotaClient method overrides.
void GetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
private:
SEQUENCE_CHECKER(sequence_checker_);

@ -41,16 +41,11 @@
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace storage {
// Declared to shorten the line lengths.
static const blink::mojom::StorageType kTemp =
blink::mojom::StorageType::kTemporary;
// Mocks DatabaseTracker methods used by DatabaseQuotaClient.
class MockDatabaseTracker : public DatabaseTracker {
public:
@ -195,17 +190,15 @@ class DatabaseQuotaClientTest : public testing::TestWithParam<bool> {
return usage_future.Get();
}
static std::vector<blink::StorageKey> GetStorageKeysForType(
mojom::QuotaClient& client,
blink::mojom::StorageType type) {
static std::vector<blink::StorageKey> GetDefaultStorageKeys(
mojom::QuotaClient& client) {
std::vector<blink::StorageKey> result;
base::RunLoop loop;
client.GetStorageKeysForType(
type, base::BindLambdaForTesting(
[&](const std::vector<blink::StorageKey>& storage_keys) {
result = storage_keys;
loop.Quit();
}));
client.GetDefaultStorageKeys(base::BindLambdaForTesting(
[&](const std::vector<blink::StorageKey>& storage_keys) {
result = storage_keys;
loop.Quit();
}));
loop.Run();
return result;
}
@ -242,14 +235,13 @@ TEST_P(DatabaseQuotaClientTest, GetBucketUsage) {
EXPECT_EQ(0, GetBucketUsage(client, bucket_b));
}
TEST_P(DatabaseQuotaClientTest, GetStorageKeysForType) {
TEST_P(DatabaseQuotaClientTest, GetDefaultStorageKeys) {
DatabaseQuotaClient client(*mock_tracker_);
EXPECT_TRUE(GetStorageKeysForType(client, kTemp).empty());
EXPECT_TRUE(GetDefaultStorageKeys(client).empty());
mock_tracker_->AddMockDatabase(kStorageKeyA.origin(), "fooDB", 1000);
std::vector<blink::StorageKey> storage_keys =
GetStorageKeysForType(client, kTemp);
std::vector<blink::StorageKey> storage_keys = GetDefaultStorageKeys(client);
EXPECT_EQ(storage_keys.size(), 1ul);
EXPECT_THAT(storage_keys, testing::Contains(kStorageKeyA));
}

@ -58,31 +58,13 @@ std::vector<T> MergeWithoutDuplicates(const std::vector<std::vector<T>>& tss) {
return merged;
}
// Converts StorageType to the FileSystemTypes that are used for that quota
// type.
base::span<const FileSystemType> QuotaStorageTypeToFileSystemTypes(
blink::mojom::StorageType storage_type) {
using StorageType = blink::mojom::StorageType;
switch (storage_type) {
case StorageType::kTemporary:
return kTemporaryAndPersistentAndSyncable;
case StorageType::kDeprecatedQuotaNotManaged:
case StorageType::kDeprecatedPersistent:
case StorageType::kSyncable:
case StorageType::kUnknown:
NOTREACHED();
}
return {};
}
std::vector<blink::StorageKey> GetStorageKeysForTypeOnFileTaskRunner(
std::vector<blink::StorageKey> GetDefaultStorageKeysOnFileTaskRunner(
FileSystemContext* context,
FileSystemType type) {
FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type);
if (!quota_util)
return {};
return quota_util->GetStorageKeysForTypeOnFileTaskRunner(type);
return quota_util->GetDefaultStorageKeysOnFileTaskRunner(type);
}
blink::mojom::QuotaStatusCode DeleteBucketOnFileTaskRunner(
@ -138,7 +120,7 @@ void FileSystemQuotaClient::GetBucketUsage(const BucketLocator& bucket,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
auto types = GetFileSystemTypes(bucket.type);
auto types = GetFileSystemTypes();
base::RepeatingCallback<void(int64_t)> barrier =
base::BarrierCallback<int64_t>(
types.size(), base::BindOnce([](std::vector<int64_t> usages) {
@ -163,13 +145,12 @@ void FileSystemQuotaClient::GetBucketUsage(const BucketLocator& bucket,
}
}
void FileSystemQuotaClient::GetStorageKeysForType(
blink::mojom::StorageType storage_type,
GetStorageKeysForTypeCallback callback) {
void FileSystemQuotaClient::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
auto types = GetFileSystemTypes(storage_type);
auto types = GetFileSystemTypes();
base::RepeatingCallback<void(std::vector<blink::StorageKey>)> barrier =
base::BarrierCallback<std::vector<blink::StorageKey>>(
types.size(),
@ -179,7 +160,7 @@ void FileSystemQuotaClient::GetStorageKeysForType(
for (auto type : types) {
file_task_runner()->PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&GetStorageKeysForTypeOnFileTaskRunner,
base::BindOnce(&GetDefaultStorageKeysOnFileTaskRunner,
base::RetainedRef(file_system_context_.get()), type),
barrier);
}
@ -191,7 +172,7 @@ void FileSystemQuotaClient::DeleteBucketData(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
auto fs_types = GetFileSystemTypes(bucket.type);
auto fs_types = GetFileSystemTypes();
auto wrapped_callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), blink::mojom::QuotaStatusCode::kUnknown);
base::RepeatingCallback<void(blink::mojom::QuotaStatusCode)> barrier =
@ -218,12 +199,11 @@ void FileSystemQuotaClient::DeleteBucketData(
}
void FileSystemQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!callback.is_null());
auto fs_types = GetFileSystemTypes(type);
auto fs_types = GetFileSystemTypes();
base::RepeatingClosure barrier =
base::BarrierClosure(fs_types.size(), std::move(callback));
@ -241,14 +221,13 @@ base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const {
return file_system_context_->default_file_task_runner();
}
std::vector<FileSystemType> FileSystemQuotaClient::GetFileSystemTypes(
blink::mojom::StorageType type) const {
std::vector<FileSystemType> FileSystemQuotaClient::GetFileSystemTypes() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::vector<FileSystemType> backend_types =
file_system_context_->GetFileSystemTypes();
std::vector<FileSystemType> fs_types;
for (auto fs_type : QuotaStorageTypeToFileSystemTypes(type)) {
for (auto fs_type : kTemporaryAndPersistentAndSyncable) {
if (base::Contains(backend_types, fs_type)) {
fs_types.push_back(fs_type);
}

@ -14,7 +14,6 @@
#include "storage/browser/file_system/file_system_quota_util.h"
#include "storage/browser/quota/quota_client_type.h"
#include "storage/common/file_system/file_system_types.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace base {
class SequencedTaskRunner;
@ -39,19 +38,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemQuotaClient
// mojom::QuotaClient methods.
void GetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
private:
base::SequencedTaskRunner* file_task_runner() const;
// Gets available FileSystemTypes for a FileSystemContext given a StorageType.
std::vector<FileSystemType> GetFileSystemTypes(
blink::mojom::StorageType) const;
// Gets available FileSystemTypes for a FileSystemContext.
std::vector<FileSystemType> GetFileSystemTypes() const;
SEQUENCE_CHECKER(sequence_checker_);

@ -42,7 +42,6 @@
#include "url/origin.h"
using ::blink::StorageKey;
using ::blink::mojom::StorageType;
namespace storage {
namespace {
@ -51,9 +50,6 @@ const char kDummyURL1[] = "http://www.dummy.org";
const char kDummyURL2[] = "http://www.example.com";
const char kDummyURL3[] = "http://www.bleh";
// Declared to shorten the variable names.
const StorageType kTemporary = StorageType::kTemporary;
} // namespace
class FileSystemQuotaClientTest : public testing::Test {
@ -105,13 +101,12 @@ class FileSystemQuotaClientTest : public testing::Test {
return usage_;
}
const std::vector<StorageKey>& GetStorageKeysForType(
storage::mojom::QuotaClient& quota_client,
StorageType type) {
const std::vector<StorageKey>& GetDefaultStorageKeys(
storage::mojom::QuotaClient& quota_client) {
storage_keys_.clear();
quota_client.GetStorageKeysForType(
type, base::BindOnce(&FileSystemQuotaClientTest::OnGetStorageKeys,
weak_factory_.GetWeakPtr()));
quota_client.GetDefaultStorageKeys(
base::BindOnce(&FileSystemQuotaClientTest::OnGetStorageKeys,
weak_factory_.GetWeakPtr()));
base::RunLoop().RunUntilIdle();
return storage_keys_;
}
@ -473,7 +468,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
EXPECT_EQ(2, additional_callback_count());
}
TEST_F(FileSystemQuotaClientTest, GetStorageKeysForType) {
TEST_F(FileSystemQuotaClientTest, GetDefaultStorageKeys) {
FileSystemQuotaClient quota_client(GetFileSystemContext());
InitializeOriginFiles(
quota_client, {
@ -482,7 +477,7 @@ TEST_F(FileSystemQuotaClientTest, GetStorageKeysForType) {
{true, "", 0, kDummyURL3, kFileSystemTypePersistent},
});
EXPECT_THAT(GetStorageKeysForType(quota_client, kTemporary),
EXPECT_THAT(GetDefaultStorageKeys(quota_client),
testing::UnorderedElementsAre(
StorageKey::CreateFromStringForTesting(kDummyURL1),
StorageKey::CreateFromStringForTesting(kDummyURL2),

@ -33,9 +33,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemQuotaUtil {
public:
virtual ~FileSystemQuotaUtil() = default;
// Deletes the cached default bucket for `storage_key` of type
// StorageType::kTemporary. Called when the default bucket is deleted from
// Quota service.
// Deletes the cached default bucket for `storage_key`. Called when the
// default bucket is deleted from Quota service.
virtual void DeleteCachedDefaultBucket(
const blink::StorageKey& storage_key) = 0;
@ -51,7 +50,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemQuotaUtil {
QuotaManagerProxy* proxy,
FileSystemType type) = 0;
virtual std::vector<blink::StorageKey> GetStorageKeysForTypeOnFileTaskRunner(
virtual std::vector<blink::StorageKey> GetDefaultStorageKeysOnFileTaskRunner(
FileSystemType type) = 0;
// Returns the amount of data used for the `bucket_locator` for usage

@ -348,7 +348,7 @@ void SandboxFileSystemBackendDelegate::PerformStorageCleanupOnFileTaskRunner(
}
std::vector<blink::StorageKey>
SandboxFileSystemBackendDelegate::GetStorageKeysForTypeOnFileTaskRunner(
SandboxFileSystemBackendDelegate::GetDefaultStorageKeysOnFileTaskRunner(
FileSystemType type) {
DCHECK(file_task_runner_->RunsTasksInCurrentSequence());
std::unique_ptr<StorageKeyEnumerator> enumerator(

@ -163,7 +163,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileSystemBackendDelegate
void PerformStorageCleanupOnFileTaskRunner(FileSystemContext* context,
QuotaManagerProxy* proxy,
FileSystemType type) override;
std::vector<blink::StorageKey> GetStorageKeysForTypeOnFileTaskRunner(
std::vector<blink::StorageKey> GetDefaultStorageKeysOnFileTaskRunner(
FileSystemType type) override;
int64_t GetBucketUsageOnFileTaskRunner(FileSystemContext* context,
const BucketLocator& bucket_locator,

@ -525,11 +525,9 @@ class QuotaManagerImpl::StorageKeyGathererTask {
base::ConcurrentClosures concurrent;
for (const auto& client_and_type : manager_->client_types_) {
client_and_type.first->GetStorageKeysForType(
StorageType::kTemporary,
base::BindOnce(&StorageKeyGathererTask::DidGetStorageKeys,
weak_factory_.GetWeakPtr(),
concurrent.CreateClosure()));
client_and_type.first->GetDefaultStorageKeys(base::BindOnce(
&StorageKeyGathererTask::DidGetStorageKeys,
weak_factory_.GetWeakPtr(), concurrent.CreateClosure()));
}
std::move(concurrent)
.Done(
@ -872,8 +870,7 @@ class QuotaManagerImpl::StorageCleanupHelper : public QuotaTask {
mojom::QuotaClient* client = client_and_type.first;
QuotaClientType client_type = client_and_type.second;
if (quota_client_types_.contains(client_type)) {
client->PerformStorageCleanup(StorageType::kTemporary,
concurrent.CreateClosure());
client->PerformStorageCleanup(concurrent.CreateClosure());
}
}
std::move(concurrent)

@ -53,8 +53,7 @@ class UsageTrackerTestQuotaClient : public mojom::QuotaClient {
FROM_HERE, base::BindOnce(std::move(callback), usage));
}
void GetStorageKeysForType(StorageType type,
GetStorageKeysForTypeCallback callback) override {
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override {
std::set<StorageKey> storage_keys;
for (const auto& bucket_usage_pair : bucket_usage_map_) {
storage_keys.emplace(bucket_usage_pair.first.storage_key);
@ -72,8 +71,7 @@ class UsageTrackerTestQuotaClient : public mojom::QuotaClient {
FROM_HERE, base::BindOnce(std::move(callback), QuotaStatusCode::kOk));
}
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override {
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override {
std::move(callback).Run();
}

@ -72,13 +72,12 @@ void MockQuotaClient::GetBucketUsage(const BucketLocator& bucket,
weak_factory_.GetWeakPtr(), bucket, std::move(callback)));
}
void MockQuotaClient::GetStorageKeysForType(
blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) {
void MockQuotaClient::GetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&MockQuotaClient::RunGetStorageKeysForType,
weak_factory_.GetWeakPtr(), type, std::move(callback)));
base::BindOnce(&MockQuotaClient::RunGetDefaultStorageKeys,
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void MockQuotaClient::DeleteBucketData(const BucketLocator& bucket,
@ -90,7 +89,6 @@ void MockQuotaClient::DeleteBucketData(const BucketLocator& bucket,
}
void MockQuotaClient::PerformStorageCleanup(
blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) {
std::move(callback).Run();
}
@ -105,9 +103,8 @@ void MockQuotaClient::RunGetBucketUsage(const BucketLocator& bucket,
}
}
void MockQuotaClient::RunGetStorageKeysForType(
blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) {
void MockQuotaClient::RunGetDefaultStorageKeys(
GetDefaultStorageKeysCallback callback) {
std::vector<blink::StorageKey> storage_keys;
for (const auto& storage_key_usage : unmigrated_storage_key_data_) {
storage_keys.push_back(storage_key_usage.first);

@ -23,7 +23,6 @@
#include "components/services/storage/public/mojom/quota_client.mojom.h"
#include "storage/browser/quota/quota_client_type.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
@ -31,7 +30,7 @@ class QuotaManagerProxy;
// Default StorageKey data that the QuotaDatabase does not know about yet,
// and is to be fetched during QuotaDatabase bootstrapping via
// QuotaClient::GetStorageKeysForType.
// QuotaClient::GetDefaultStorageKeys.
struct UnmigratedStorageKeyData {
const char* origin;
int64_t usage;
@ -66,18 +65,15 @@ class MockQuotaClient : public mojom::QuotaClient {
// QuotaClient.
void GetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback) override;
void GetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback) override;
void GetDefaultStorageKeys(GetDefaultStorageKeysCallback callback) override;
void DeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback) override;
void PerformStorageCleanup(blink::mojom::StorageType type,
PerformStorageCleanupCallback callback) override;
void PerformStorageCleanup(PerformStorageCleanupCallback callback) override;
private:
void RunGetBucketUsage(const BucketLocator& bucket,
GetBucketUsageCallback callback);
void RunGetStorageKeysForType(blink::mojom::StorageType type,
GetStorageKeysForTypeCallback callback);
void RunGetDefaultStorageKeys(GetDefaultStorageKeysCallback callback);
void RunDeleteBucketData(const BucketLocator& bucket,
DeleteBucketDataCallback callback);

@ -91,7 +91,7 @@ class TestFileSystemBackend::QuotaUtil : public FileSystemQuotaUtil,
NOTREACHED();
}
std::vector<blink::StorageKey> GetStorageKeysForTypeOnFileTaskRunner(
std::vector<blink::StorageKey> GetDefaultStorageKeysOnFileTaskRunner(
FileSystemType type) override {
NOTREACHED();
}