CacheStorage: Make addAll() support throttled network requests.
Cache.addAll() must wait for the all requests to succeed before starting to store the results in CacheStorage. Previously this was done by waiting for all the Response objects to become available and only then would it begin loading the bodies into blobs. This does not work with throttling since throttling requires bodies to be loaded in order to make progress. The main change in this CL is to refactor things so we now immediately load the body to a blob when a Response becomes available. We then wait for all Responses and their bodies before proceeding to store the result. This should not use too much memory since loading a Response to a blob streams data to the BlobRegistry, which may then subsequently stream to disk if necessary. One notable change here is that code cache generation now requires loading the body into an ArrayBuffer from a blob. Previously we loaded the response to the ArrayBuffer and then converted that into a blob. This will be slightly slower for putting scripts in CacheStorage, but that should be fine since generally we do not optimize for write performance. Other changes in this CL: * Adds a cache.addAll() test for the throttled service worker case. * Adds `cache:no-store` to the existing throttled service worker test since that more easily triggers true throttling behavior. This in turn also required draining the response bodies in the test. * Refactored cache add(), addAll(), and put() to all go through the same set of objects where appropriate. * FetchHandler is used in add/addAll to wait for each individual fetch() to complete. * ResponseBodyLoader is used in add/addAll/put to take a Response and load its body as a blob. * BarrierCallbackForPutResponse waits for a list of Response and blob objects to become available before calling PutImpl(). * BarrierCallbackForPutComplete waits for any code cache generation and the final cache operation to complete. Bug: 1035448 Change-Id: I8c9b6b5831cfd21bd266e526a138de4cbf03171f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404267 Commit-Queue: Ben Kelly <wanderview@chromium.org> Reviewed-by:Marijn Kruisselbrink <mek@chromium.org> Cr-Commit-Position: refs/heads/master@{#811379}
Showing
This diff is collapsed.
Please register or sign in to comment