chromium/components/services/storage/public/mojom/cache_storage_control.mojom

// 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 "components/services/storage/public/mojom/buckets/bucket_locator.mojom";
import "components/services/storage/public/mojom/storage_policy_update.mojom";
import "components/services/storage/public/mojom/storage_usage_info.mojom";
import "services/network/public/mojom/cross_origin_embedder_policy.mojom";
import "services/network/public/mojom/document_isolation_policy.mojom";
import "third_party/blink/public/mojom/cache_storage/cache_storage.mojom";
import "third_party/blink/public/mojom/storage_key/storage_key.mojom";

enum CacheStorageOwner {
  // Caches that can be accessed by the JS CacheStorage API (developer facing).
  kCacheAPI,

  // Private cache to store background fetch downloads.
  kBackgroundFetch,
};

// Observer interface for receiving callbacks after cache storage changes. This
// is used by Devtools.
interface CacheStorageObserver {
  // Called when caches are created or deleted.
  OnCacheListChanged(BucketLocator bucket_locator);

  // Called when the content of a cache has been modified.
  OnCacheContentChanged(BucketLocator bucket_locator, string cache_name);
};

// Controls the state of CacheStorage within a partition. This is a privileged
// interface and must not be brokered to untrusted clients.
//
// Currently this is consumed and implemented in the browser process, but the
// implementation will eventually live in the storage service which may run
// out-of-process.
interface CacheStorageControl {
  // Binds a CacheStorage receiver to the CacheStorageControl to access
  // the cache storage for a particular storage key and owner. `bucket_locator`
  // may represent the default bucket (`is_default` will be true), in which case
  // its ID will not be valid.
  AddReceiver(
      network.mojom.CrossOriginEmbedderPolicy cross_origin_embedder_policy,
      pending_remote<network.mojom.CrossOriginEmbedderPolicyReporter>?
          coep_reporter,
      network.mojom.DocumentIsolationPolicy document_isolation_policy,
      BucketLocator bucket_locator,
      CacheStorageOwner owner,
      pending_receiver<blink.mojom.CacheStorage> receiver);

  // Adds an observer that will receive cache change callbacks.
  AddObserver(pending_remote<CacheStorageObserver> observer);

  // Applies changes to data retention policy which are relevant at shutdown.
  // See StoragePolicyUpdate.
  ApplyPolicyUpdates(array<StoragePolicyUpdate> policy_updates);
};