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

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp

Issue 2177243002: Use per-frame TaskRunner instead of thread's default in DataConsumerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data_consumer_handle_unique_ptr
Patch Set: update Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/serviceworkers/RespondWithObserver.h" 5 #include "modules/serviceworkers/RespondWithObserver.h"
6 6
7 #include "bindings/core/v8/ScriptFunction.h" 7 #include "bindings/core/v8/ScriptFunction.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/modules/v8/V8Response.h" 11 #include "bindings/modules/v8/V8Response.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/dom/ExecutionContext.h" 13 #include "core/dom/ExecutionContext.h"
14 #include "core/inspector/ConsoleMessage.h" 14 #include "core/inspector/ConsoleMessage.h"
15 #include "core/streams/Stream.h" 15 #include "core/streams/Stream.h"
16 #include "modules/fetch/BodyStreamBuffer.h" 16 #include "modules/fetch/BodyStreamBuffer.h"
17 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 17 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
18 #include "platform/RuntimeEnabledFeatures.h" 18 #include "platform/RuntimeEnabledFeatures.h"
19 #include "public/platform/Platform.h"
19 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" 20 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
20 #include "wtf/Assertions.h" 21 #include "wtf/Assertions.h"
21 #include "wtf/RefPtr.h" 22 #include "wtf/RefPtr.h"
22 #include <v8.h> 23 #include <v8.h>
23 24
24 namespace blink { 25 namespace blink {
25 namespace { 26 namespace {
26 27
27 // Returns the error message to let the developer know about the reason of the u nusual failures. 28 // Returns the error message to let the developer know about the reason of the u nusual failures.
28 const String getMessageForResponseError(WebServiceWorkerResponseError error, con st KURL& requestURL) 29 const String getMessageForResponseError(WebServiceWorkerResponseError error, con st KURL& requestURL)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool isNavigationRequest(WebURLRequest::FrameType frameType) 80 bool isNavigationRequest(WebURLRequest::FrameType frameType)
80 { 81 {
81 return frameType != WebURLRequest::FrameTypeNone; 82 return frameType != WebURLRequest::FrameTypeNone;
82 } 83 }
83 84
84 bool isClientRequest(WebURLRequest::FrameType frameType, WebURLRequest::RequestC ontext requestContext) 85 bool isClientRequest(WebURLRequest::FrameType frameType, WebURLRequest::RequestC ontext requestContext)
85 { 86 {
86 return isNavigationRequest(frameType) || requestContext == WebURLRequest::Re questContextSharedWorker || requestContext == WebURLRequest::RequestContextWorke r; 87 return isNavigationRequest(frameType) || requestContext == WebURLRequest::Re questContextSharedWorker || requestContext == WebURLRequest::RequestContextWorke r;
87 } 88 }
88 89
89 class NoopLoaderClient final : public GarbageCollectedFinalized<NoopLoaderClient >, public FetchDataLoader::Client {
90 WTF_MAKE_NONCOPYABLE(NoopLoaderClient);
91 USING_GARBAGE_COLLECTED_MIXIN(NoopLoaderClient);
92 public:
93 NoopLoaderClient() = default;
94 void didFetchDataLoadedStream() override {}
95 void didFetchDataLoadFailed() override {}
96 DEFINE_INLINE_TRACE() { FetchDataLoader::Client::trace(visitor); }
97 };
98
99 } // namespace 90 } // namespace
100 91
101 class RespondWithObserver::ThenFunction final : public ScriptFunction { 92 class RespondWithObserver::ThenFunction final : public ScriptFunction {
102 public: 93 public:
103 enum ResolveType { 94 enum ResolveType {
104 Fulfilled, 95 Fulfilled,
105 Rejected, 96 Rejected,
106 }; 97 };
107 98
108 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Resp ondWithObserver* observer, ResolveType type) 99 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Resp ondWithObserver* observer, ResolveType type)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 WebServiceWorkerResponse webResponse; 248 WebServiceWorkerResponse webResponse;
258 response->populateWebServiceWorkerResponse(webResponse); 249 response->populateWebServiceWorkerResponse(webResponse);
259 BodyStreamBuffer* buffer = response->internalBodyBuffer(); 250 BodyStreamBuffer* buffer = response->internalBodyBuffer();
260 if (buffer) { 251 if (buffer) {
261 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle(Fe tchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); 252 RefPtr<BlobDataHandle> blobDataHandle = buffer->drainAsBlobDataHandle(Fe tchDataConsumerHandle::Reader::AllowBlobWithInvalidSize);
262 if (blobDataHandle) { 253 if (blobDataHandle) {
263 webResponse.setBlobDataHandle(blobDataHandle); 254 webResponse.setBlobDataHandle(blobDataHandle);
264 } else { 255 } else {
265 Stream* outStream = Stream::create(getExecutionContext(), ""); 256 Stream* outStream = Stream::create(getExecutionContext(), "");
266 webResponse.setStreamURL(outStream->url()); 257 webResponse.setStreamURL(outStream->url());
267 buffer->startLoading(FetchDataLoader::createLoaderAsStream(outStream ), new NoopLoaderClient); 258 buffer->startLoading(FetchDataLoader::createLoaderAsStream(outStream ), nullptr);
268 } 259 }
269 } 260 }
270 ServiceWorkerGlobalScopeClient::from(getExecutionContext())->respondToFetchE vent(m_eventID, webResponse); 261 ServiceWorkerGlobalScopeClient::from(getExecutionContext())->respondToFetchE vent(m_eventID, webResponse);
271 m_state = Done; 262 m_state = Done;
272 m_observer->decrementPendingActivity(); 263 m_observer->decrementPendingActivity();
273 m_observer.clear(); 264 m_observer.clear();
274 } 265 }
275 266
276 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequ est::FrameType frameType, WebURLRequest::RequestContext requestContext, WaitUnti lObserver* observer) 267 RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequ est::FrameType frameType, WebURLRequest::RequestContext requestContext, WaitUnti lObserver* observer)
277 : ContextLifecycleObserver(context) 268 : ContextLifecycleObserver(context)
278 , m_eventID(eventID) 269 , m_eventID(eventID)
279 , m_requestURL(requestURL) 270 , m_requestURL(requestURL)
280 , m_requestMode(requestMode) 271 , m_requestMode(requestMode)
281 , m_frameType(frameType) 272 , m_frameType(frameType)
282 , m_requestContext(requestContext) 273 , m_requestContext(requestContext)
283 , m_state(Initial) 274 , m_state(Initial)
284 , m_observer(observer) 275 , m_observer(observer)
285 { 276 {
286 } 277 }
287 278
288 DEFINE_TRACE(RespondWithObserver) 279 DEFINE_TRACE(RespondWithObserver)
289 { 280 {
290 visitor->trace(m_observer); 281 visitor->trace(m_observer);
291 ContextLifecycleObserver::trace(visitor); 282 ContextLifecycleObserver::trace(visitor);
292 } 283 }
293 284
294 } // namespace blink 285 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698