// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module storage.mojom;
import "third_party/blink/public/mojom/quota/quota_types.mojom";
import "third_party/blink/public/mojom/storage_key/storage_key.mojom";
import "components/services/storage/public/mojom/buckets/bucket_locator.mojom";
// Interface between each storage API and the quota manager.
//
// Each storage API must register an implementation of this interface with
// the quota manager, by calling QuotaManager::RegisterClient().
//
// Storage APIs may implement this interface in the browser process or in the
// Storage Service process. The interface is consumed by QuotaManager, which
// currently lives in the browser process, and will eventually move to the
// Storage Service process.
interface QuotaClient {
// Returns the amount of data stored in the storage specified by `bucket`.
// The quota manager should not assume that 0 `usage` means the
// storage API has no record of the `bucket`'s existence.
// DeleteBucketData() is the only way to guarantee that storage APIs erase
// 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.
//
// 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.
// We're planning to remove this around 05/2024 (2 years after we've enforced
// bootstrapping in crbug.com/1317419), and data for the default bucket has
// been migrated to the new buckets path (crbug.com/1349156).
//
// 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
// processing other tasks, and a deadlock would occur if a
// QuotaClient::GetStorageKeysForType implementation waits for a QuotaManager
// task to finish.
GetStorageKeysForType(blink.mojom.StorageType type)
=> (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) => ();
};