Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1327)

Unified Diff: Source/modules/cachestorage/Cache.cpp

Issue 1192913007: Change BodyStreamBuffer to be FetchDataConsumerHandle-based and enable backpressure in Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/cachestorage/script-tests/cache-put.js ('k') | Source/modules/fetch/Body.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/cachestorage/Cache.cpp
diff --git a/Source/modules/cachestorage/Cache.cpp b/Source/modules/cachestorage/Cache.cpp
index e711b2a5177ba22e4e5dfc20616d3071eb980c38..f5abc013831d6633d0e0ba6bd6ac0a48789742ae 100644
--- a/Source/modules/cachestorage/Cache.cpp
+++ b/Source/modules/cachestorage/Cache.cpp
@@ -16,6 +16,7 @@
#include "core/dom/ExceptionCode.h"
#include "modules/cachestorage/CacheStorageError.h"
#include "modules/fetch/BodyStreamBuffer.h"
+#include "modules/fetch/FetchDataLoader.h"
#include "modules/fetch/GlobalFetch.h"
#include "modules/fetch/Request.h"
#include "modules/fetch/Response.h"
@@ -295,20 +296,14 @@ public:
m_cache->webCache()->dispatchBatch(new CallbackPromiseAdapter<void, CacheStorageError>(m_resolver), m_batchOperations);
}
- void onError(DOMException* exception)
+ void onError(const String& errorMessage)
{
if (m_completed)
return;
m_completed = true;
- m_resolver->reject(exception);
- }
-
- void onError(v8::Local<v8::Value> exception)
- {
- if (m_completed)
- return;
- m_completed = true;
- m_resolver->reject(exception);
+ ScriptState* state = m_resolver->scriptState();
+ ScriptState::Scope scope(state);
+ m_resolver->reject(V8ThrowException::createTypeError(state->isolate(), errorMessage));
}
DEFINE_INLINE_VIRTUAL_TRACE()
@@ -325,7 +320,8 @@ private:
Vector<WebServiceWorkerCache::BatchOperation> m_batchOperations;
};
-class Cache::BlobHandleCallbackForPut final : public BodyStreamBuffer::BlobHandleCreatorClient {
+class Cache::BlobHandleCallbackForPut final : public GarbageCollectedFinalized<BlobHandleCallbackForPut>, public FetchDataLoader::Client {
+ USING_GARBAGE_COLLECTED_MIXIN(BlobHandleCallbackForPut);
public:
BlobHandleCallbackForPut(size_t index, BarrierCallbackForPut* barrierCallback, Request* request, Response* response)
: m_index(index)
@@ -336,7 +332,7 @@ public:
}
~BlobHandleCallbackForPut() override { }
- void didCreateBlobHandle(PassRefPtr<BlobDataHandle> handle) override
+ void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle> handle) override
{
WebServiceWorkerCache::BatchOperation batchOperation;
batchOperation.operationType = WebServiceWorkerCache::OperationTypePut;
@@ -346,15 +342,15 @@ public:
m_barrierCallback->onSuccess(m_index, batchOperation);
}
- void didFail(DOMException* exception) override
+ void didFetchDataLoadFailed() override
{
- m_barrierCallback->onError(exception);
+ m_barrierCallback->onError("network error");
}
DEFINE_INLINE_VIRTUAL_TRACE()
{
visitor->trace(m_barrierCallback);
- BlobHandleCreatorClient::trace(visitor);
+ FetchDataLoader::Client::trace(visitor);
}
private:
@@ -541,19 +537,19 @@ ScriptPromise Cache::putImpl(ScriptState* scriptState, const HeapVector<Member<R
for (size_t i = 0; i < requests.size(); ++i) {
KURL url(KURL(), requests[i]->url());
if (!url.protocolIsInHTTPFamily()) {
- barrierCallback->onError(V8ThrowException::createTypeError(scriptState->isolate(), "Request scheme '" + url.protocol() + "' is unsupported"));
+ barrierCallback->onError("Request scheme '" + url.protocol() + "' is unsupported");
return promise;
}
if (requests[i]->method() != "GET") {
- barrierCallback->onError(V8ThrowException::createTypeError(scriptState->isolate(), "Request method '" + requests[i]->method() + "' is unsupported"));
+ barrierCallback->onError("Request method '" + requests[i]->method() + "' is unsupported");
return promise;
}
if (requests[i]->hasBody() && requests[i]->bodyUsed()) {
- barrierCallback->onError(V8ThrowException::createTypeError(scriptState->isolate(), "Request body is already used"));
+ barrierCallback->onError("Request body is already used");
return promise;
}
if (responses[i]->hasBody() && responses[i]->bodyUsed()) {
- barrierCallback->onError(V8ThrowException::createTypeError(scriptState->isolate(), "Response body is already used"));
+ barrierCallback->onError("Response body is already used");
return promise;
}
@@ -562,12 +558,11 @@ ScriptPromise Cache::putImpl(ScriptState* scriptState, const HeapVector<Member<R
if (responses[i]->hasBody())
responses[i]->lockBody(Body::PassBody);
- if (BodyStreamBuffer* buffer = responses[i]->internalBuffer()) {
- if (buffer == responses[i]->buffer() && responses[i]->isBodyConsumed())
- buffer = responses[i]->createDrainingStream();
- // If the response body type is stream, read the all data and create
+ if (OwnPtr<DrainingBodyStreamBuffer> buffer = responses[i]->createInternalDrainingStream()) {
+ // If the response has body, read the all data and create
// the blob handle and dispatch the put batch asynchronously.
- buffer->readAllAndCreateBlobHandle(responses[i]->internalMIMEType(), new BlobHandleCallbackForPut(i, barrierCallback, requests[i], responses[i]));
+ FetchDataLoader* loader = FetchDataLoader::createLoaderAsBlobHandle(responses[i]->internalMIMEType());
+ buffer->startLoading(loader, new BlobHandleCallbackForPut(i, barrierCallback, requests[i], responses[i]));
continue;
}
« no previous file with comments | « LayoutTests/http/tests/cachestorage/script-tests/cache-put.js ('k') | Source/modules/fetch/Body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698