Implement StorageManager API#43976
Conversation
|
🔨 Triggering try run (#24036383072) for Linux (WPT) |
|
Test results for linux-wpt from try job (#24036383072): Flaky unexpected result (41)
Stable unexpected results that are known to be intermittent (19)
Stable unexpected results (1)
|
|
|
|
🔨 Triggering try run (#24042883821) for Linux (WPT) |
|
Test results for linux-wpt from try job (#24042883821): Flaky unexpected result (33)
Stable unexpected results that are known to be intermittent (21)
Stable unexpected results (1)
|
|
|
a1b345a to
e0be9da
Compare
|
🔨 Triggering try run (#24066694895) for Linux (WPT) |
|
Test results for linux-wpt from try job (#24066694895): Flaky unexpected result (33)
Stable unexpected results that are known to be intermittent (18)
|
|
✨ Try run (#24066694895) succeeded. |
|
I did a quick pass and it looks reasonable, I'll take a closer look soon. |
| let trusted_manager = Trusted::new(self); | ||
| let trusted_promise = TrustedPromise::new(promise.clone()); | ||
|
|
||
| request_task_source.queue(task!(storage_manager_persist_request: move || { |
There was a problem hiding this comment.
Looks like here you want to send a message first ,and then queue the task from the response handler.
| impl FromStr for Mode { | ||
| type Err = (); | ||
|
|
||
| /// <https://storage.spec.whatwg.org/#bucket> |
There was a problem hiding this comment.
| /// | ||
| /// Set shelf’s bucket map["default"] to the result of running create a storage bucket with type. | ||
| /// | ||
| /// Return shelf. |
There was a problem hiding this comment.
here also docs should be inside body, link on top of method.
| use crate::dom::navigator::hardware_concurrency; | ||
| use crate::dom::navigatorinfo; | ||
| use crate::dom::permissions::Permissions; | ||
| use crate::dom::storagemanager::StorageManager; |
There was a problem hiding this comment.
Just in case you were wondering why we have client_storage and eventually ClientStorageManager, it’s to avoid confusion or ambiguity, since StorageManager is already used by the Storage spec.
|
|
||
| [SecureContext, Exposed=(Window,Worker)] | ||
| interface StorageManager { | ||
| Promise<boolean> persisted(); |
There was a problem hiding this comment.
Not sure if it matters much in Servo, but for example Firefox annotates this with [NewObject]:
https://searchfox.org/firefox-main/rev/8332a06d47ce7d66623d807068b3410061cd29d3/dom/webidl/StorageManager.webidl#12
There was a problem hiding this comment.
No, it does not matter for the Servo implementation, at least the codegen is the same but I will add it anyywas.
| receiver | ||
| } | ||
|
|
||
| pub fn persisted(&self, origin: ImmutableOrigin) -> GenericReceiver<Result<bool, String>> { |
There was a problem hiding this comment.
Hm, these three functions are only used by unit tests? I guess it's not easy to use them from StorageManagerMethods as well.
| "StaticRange", | ||
| "StereoPannerNode", | ||
| "Storage", | ||
| "StorageManager", |
There was a problem hiding this comment.
The implementation looks complete, but maybe it should be gated by a pref and added to experimental features?
(so if there's a problem, only the pref could be flipped avoiding a backout)
| TrustedPromise::new(promise.clone()), | ||
| global | ||
| .task_manager() | ||
| .database_access_task_source() |
There was a problem hiding this comment.
It seems StorageManager uses "storage task source".
There was a problem hiding this comment.
we don't have storage_task_source do we?
There was a problem hiding this comment.
Maybe not, but it should be easy to add it?
There was a problem hiding this comment.
There was a problem hiding this comment.
Ah, sorry, I meant to add it to Servo
| impl StorageManagerMethods<crate::DomTypeHolder> for StorageManager { | ||
| /// <https://storage.spec.whatwg.org/#dom-storagemanager-persisted> | ||
| fn Persisted(&self, comp: InRealm, can_gc: CanGc) -> Rc<Promise> { | ||
| // Step 1. Let promise be a new promise. |
There was a problem hiding this comment.
Nice alignment with the spec, here and elsewhere!
(modulo the comment below)
| if global | ||
| .storage_threads() | ||
| .send(ClientStorageThreadMessage::Persisted { | ||
| origin: global.origin().immutable().clone(), |
There was a problem hiding this comment.
Hm, shouldn't we have a message like ObtainShelf and then pass the returned id here?
| // Let usage be storage usage for shelf. | ||
| let usage = storage_usage_for_bucket(shelf.default_bucket_id, &tx)?; | ||
| // Let quota be storage quota for shelf. | ||
| let quota = storage_quota_for_bucket(shelf.default_bucket_id, &tx)?; |
There was a problem hiding this comment.
Can we end up returning usage greater than quota?
(given quota checks at client storage level are not yet implemented, and the constant STORAGE_ENDPOINT_QUOTA_BYTES is rather small 5MB)
I guess, for now, we should follow Firefox or Chrome:
https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria
"Or 10 GiB, which is the group limit that Firefox applies to all origins that are part of the same site"
"In browsers based on the Chromium open-source project, including Chrome and Edge, an origin can store up to 60% of the total disk size in both persistent and best-effort modes."
|
🔨 Triggering try run (#24669584187) for Linux (WPT) |
|
Test results for linux-wpt from try job (#24669584187): Flaky unexpected result (35)
Stable unexpected results that are known to be intermittent (18)
|
|
Looking... |
|
✨ Try run (#24669584187) succeeded. |
janvarga
left a comment
There was a problem hiding this comment.
Looks good, but please consider adding the storage task source.
Signed-off-by: Taym Haddadi <[email protected]>
…task source Signed-off-by: Taym Haddadi <[email protected]>
|
🔨 Triggering try run (#24724235626) for Linux (WPT) |
|
Test results for linux-wpt from try job (#24724235626): Flaky unexpected result (39)
Stable unexpected results that are known to be intermittent (12)
|
|
✨ Try run (#24724235626) succeeded. |
Add the Storage Standard WebIDL for NavigatorStorage and StorageManager, wire navigator.storage on Window and Worker, and implement persisted(), persist(), and estimate().
Testing: covered by WP test.
part of #39100
fixes #39101