// 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 blink.mojom; import "mojo/public/mojom/base/time.mojom"; import "third_party/blink/public/mojom/cache_storage/cache_storage.mojom"; import "third_party/blink/public/mojom/file_system_access/file_system_access_directory_handle.mojom"; import "third_party/blink/public/mojom/file_system_access/file_system_access_error.mojom"; import "third_party/blink/public/mojom/indexeddb/indexeddb.mojom"; import "third_party/blink/public/mojom/locks/lock_manager.mojom"; import "third_party/blink/public/mojom/quota/quota_types.mojom"; // Implementation of the proposed "Storage Buckets API". // // Proposal: https://github.com/WICG/storage-buckets enum BucketError { kUnknown = 0, kQuotaExceeded = 1, kInvalidExpiration = 2, }; // The policies applied to a StorageBucket upon its creation. struct BucketPolicies { bool persisted; bool has_persisted = false; BucketDurability durability; bool has_durability = false; // `quota` should always be positive, but this is not uint64_t because SQLite // only handles signed integers and some legacy code does arithmetic with // these values. int64 quota; bool has_quota = false; mojo_base.mojom.Time? expires; }; // The mojo interface representing a single StorageBucket object. // // The interface is scoped to a single bucket, which belongs to an origin, // and is consumed by Blink in the renderer process. The interface is // currently implemented in the browser process, and will eventually move // to the Storage Service. interface BucketHost { // Requests persisted storage for the StorageBucket. The implementation is // free to decline the request. The |persisted| value is only valid when // |success| is true. Persist() => (bool persisted, bool success); // Retrieves StorageBucket persistence policy. The |persisted| value is only // valid when |success| is true. Persisted() => (bool persisted, bool success); // Retrieves estimated quota usage data for the StorageBucket. The values for // |current_usage| and |current_quota| are only valid when |success| is true. // Ideally usage and quota should be an uint64s. See comment in BucketPolicies // for quota. // TODO(ayui): Return quota UsageBreakdown. Estimate() => (int64 current_usage, int64 current_quota, bool success); // Retrieves the durability policy for the StorageBucket. The |durability| // value is only valid when |success| is true. Durability() => (BucketDurability durability, bool success); // Sets expiry policy for the StorageBucket. The StorageBucket will be // inaccessible after |expires| date. SetExpires(mojo_base.mojom.Time expires) => (bool success); // Retrieves the expiry policy for the StorageBucket. |expires| will return // null when there is not expiry policy set for the Storage Bucket. The // |expires| value is only valid when |success| is true. Expires() => (mojo_base.mojom.Time? expires, bool success); // Connects to the IndexedDB factory implementation in the browser process. GetIdbFactory(pending_receiver idb_factory); // Connects a LockManager to this bucket. GetLockManager(pending_receiver lock_manager); // Connects a CacheStorage implementation in the browser process. GetCaches(pending_receiver cache_storage); // Opens the sandboxed filesystem for this bucket. GetDirectory() => (FileSystemAccessError result, pending_remote? directory); // Opens the sandboxed filesystem for this bucket. An empty // `directory_path_components` array will retrieve the root. // Note: This method is equivalent to the `GetDirectory` method but allows // DevTools to pass a path (avoiding multiple roundtrips). // The `GetDirectory` method requires starting at the root and iterating // through directories using additional calls. GetDirectoryForDevtools(array directory_path_components) => (FileSystemAccessError result, pending_remote? directory); }; // Origin-scoped entry point to the Storage Buckets API. // // The interface is origin-scoped, and is consumed by Blink in the renderer // process. The interface is currently implemented in the browser process, // and will eventually move to the Storage Service. interface BucketManagerHost { // Open or create or bucket with the specified name and policies. // On success, it will return a mojo data pipe to the BucketHost in the // browser process. Returns a null remote on error, e.g. if the storage bucket // failed to be created or retrieved due to a database error. `error` is only // meaningful if `remote` is null. OpenBucket(string name, BucketPolicies policy) => (pending_remote? remote, BucketError error); // Gets bucket without creating or updating it. GetBucketForDevtools(string name, pending_receiver receiver); // Returns a list of stored bucket names in alphabetical order. Keys() => (array buckets, bool success); // Deletes the bucket. DeleteBucket(string name) => (bool success); };