W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2013

Updating Quota API: Promise, Events and some more

From: Kinuko Yasuda <kinuko@chromium.org>
Date: Wed, 14 Aug 2013 14:57:09 +0900
Message-ID: <CAMWgRNaNHXs50Oq2mYXsa2rV0VLk06kCUdKfzK8Lkp1ESkxCzg@mail.gmail.com>
To: Web Applications Working Group WG <public-webapps@w3.org>
Cc: Jonas Sicking <jonas@sicking.cc>, Joshua Bell <jsbell@chromium.org>
Hi all,

It's been a while since Quota API's FPWD (http://www.w3.org/TR/quota-api/)
was published and we've gotten several requests/feedbacks so far.
To address some of the requests and to gain more consensus, I'm thinking
about making following changes to the Quota API:

* Use Promises rather than callbacks
* Add Events to notify webapps of important changes in the local storage
* Establish a way to get and set the storage types (temporary or persistent)
  of each storage object

This breaks compatibility in the existing implementation, but currently
it's implemented only in Chrome behind the flag, so I hope/assume it'll be
to make incompatible changes. I'm also strongly hoping these changes
(and debate on them) help building more consensus.

There're also some requests those are not (yet) addressed in this new draft:

* More granularity in storage types or priorities, rather than sticking to
  rigid two types, so that webapps can indicate which data should be evicted
  first / when.
* Helper method to estimate 'actual' size of each storage object
* Helper method to trigger GC/compaction on the local storage

While they look nice-to-have in some situations but may also add more
complexity in implementation, so I tentatively concluded that they can
be put off until the next iteration.

New draft needs some more polish but I'd like to get early feedback
on the new draft.

Detailed draft:

  enum StorageType { "temporary", "persistent" };

  partial interface Navigator {
    readonly attribute StorageQuota storageQuota;

  [NoInterfaceObject] interface StorageInfo {
    unsigned long long usageInBytes;
    unsigned long long quotaInBytes;

  [NoInterfaceObject] interface StorageQuota {
    readonly attribute StorageType[] supportedTypes;

    Promise<StorageInfo> queryStorageInfo(StorageType type);
    Promise<StorageInfo> requestQuota(StorageType type, unsigned long long

    Promise<StorageType> getStorageType((IDBObjectStore or Database or
Entry) object);
    Promise<void> setStorageType((IDBObjectStore or Database or Entry)
object, StorageType type);

    StorageWatcher createStorageWatcher(StorageType type)

This new draft uses string enums to specify storage types rather than
separate attributes on navigator (e.g. navigator.temporaryStorage),
mainly because some methods (like {get,set}StorageType do not fit well
in split interface) and to preserve greater flexibility to add more storage
types in a future. I'm open to discussions though.

 supportedTypes are list of all StorageType's supported by the UA.

* queryStorageInfo and requestQuota are Promise version of
  queryUsageAndQuota and requestQuota, which is for querying the current
  storage info (usage and quota) and requesting a new quota, respectively.
  Both return the current (or updated) StorageInfo.

* getStorageType and setStorageType are new methods which are intended to
  work horizontally across multiple storage APIs. getStorageType(object)
  returns the current storage type for the given storage object, and
  setStorageType(object, type) changes the object's storage type.
  They may fail if the storage backend of the object does not support
  Quota API or does not support getting or setting (changing) storage types.

  We're aware that this API may not work very well with FileSystem API(s),
  also will need coordination with IndexedDB. Feedback is strongly

* createStorageWatcher returns a new StorageWatcher object for the given
  storage type, with which webapps can listen to important changes in the
  local storage and can react appropriately (i.e. discard their
  cache data before UA-initiated merciless eviction happens).

[NoInterfaceObject] interface createStorageWatcher {
  attribute EventHandler onstoragelow;
  attribute EventHandler onstorageok;
  attribute EventHandler onstoragechange;

storagelow and storageok events are modeled after DEVICE_STORAGE_LOW
and DEVICE_STORAGE_OK intents on android, to give more chances to
webapps to adjust their local data quickly.

* storagelow event is fired when the remaining storage space becomes lower
  than 10% of all available space for the type, or before the quota backend
  triggers eviction (for temporary case), whichever happens first.
  This event must be also fired once when either one of these conditions has
  been already met when a StorageWatcher is created.

* storageok event is fired when the remaining available storage goes out of
  'storagelow' state.

* storagechange event is fired about every 1 second (TBD) or every time
  the quota backend detects the amount of remaining storage is changed,
  whichever is least frequent. This event must be fired before storagelow
  or storageok when the remaining space crosses the threshold.

Again, your review/feedback is really encouraged.  Thanks!

Received on Wednesday, 14 August 2013 05:57:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:12 UTC