Chromium Code Reviews| Index: third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp |
| diff --git a/third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp b/third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp |
| index 5c0d70895f69dd01c532329342ff3e778281bed6..a482edc0ea5a53e9b02c62f391b6824b39b2e2a3 100644 |
| --- a/third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp |
| +++ b/third_party/WebKit/Source/modules/serviceworkers/RespondWithObserver.cpp |
| @@ -145,15 +145,19 @@ private: |
| RespondWithObserver::~RespondWithObserver() {} |
| -RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext) |
| +RespondWithObserver* RespondWithObserver::create(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext, WaitUntilObserver* observer) |
| { |
| - return new RespondWithObserver(context, eventID, requestURL, requestMode, frameType, requestContext); |
| + return new RespondWithObserver(context, eventID, requestURL, requestMode, frameType, requestContext, observer); |
| } |
| void RespondWithObserver::contextDestroyed() |
| { |
| ContextLifecycleObserver::contextDestroyed(); |
| m_state = Done; |
| + if (m_observer) { |
| + m_observer->decrementPendingActivity(); |
|
falken
2016/06/22 01:27:32
Where is the incrementPendingActivity this balance
shimazu
2016/06/22 05:41:27
m_observer is non-null only when respondWith is in
|
| + m_observer.clear(); |
| + } |
| } |
| void RespondWithObserver::didDispatchEvent(DispatchEventResult dispatchResult) |
| @@ -167,8 +171,10 @@ void RespondWithObserver::didDispatchEvent(DispatchEventResult dispatchResult) |
| return; |
| } |
| - ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchEvent(m_eventID); |
| + ServiceWorkerGlobalScopeClient::from(getExecutionContext())->respondToFetchEvent(m_eventID); |
| m_state = Done; |
| + m_observer->decrementPendingActivity(); |
| + m_observer.clear(); |
| } |
| void RespondWithObserver::respondWith(ScriptState* scriptState, ScriptPromise scriptPromise, ExceptionState& exceptionState) |
| @@ -179,6 +185,7 @@ void RespondWithObserver::respondWith(ScriptState* scriptState, ScriptPromise sc |
| } |
| m_state = Pending; |
| + m_observer->incrementPendingActivity(); |
| scriptPromise.then( |
| ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled), |
| ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)); |
| @@ -193,8 +200,10 @@ void RespondWithObserver::responseWasRejected(WebServiceWorkerResponseError erro |
| // to a network error. |
| WebServiceWorkerResponse webResponse; |
| webResponse.setError(error); |
| - ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + ServiceWorkerGlobalScopeClient::from(getExecutionContext())->respondToFetchEvent(m_eventID, webResponse); |
| m_state = Done; |
| + m_observer->decrementPendingActivity(); |
| + m_observer.clear(); |
| } |
| void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| @@ -257,11 +266,13 @@ void RespondWithObserver::responseWasFulfilled(const ScriptValue& value) |
| buffer->startLoading(FetchDataLoader::createLoaderAsStream(outStream), new NoopLoaderClient); |
| } |
| } |
| - ServiceWorkerGlobalScopeClient::from(getExecutionContext())->didHandleFetchEvent(m_eventID, webResponse); |
| + ServiceWorkerGlobalScopeClient::from(getExecutionContext())->respondToFetchEvent(m_eventID, webResponse); |
| m_state = Done; |
| + m_observer->decrementPendingActivity(); |
| + m_observer.clear(); |
| } |
| -RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext) |
| +RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, const KURL& requestURL, WebURLRequest::FetchRequestMode requestMode, WebURLRequest::FrameType frameType, WebURLRequest::RequestContext requestContext, WaitUntilObserver* observer) |
| : ContextLifecycleObserver(context) |
| , m_eventID(eventID) |
| , m_requestURL(requestURL) |
| @@ -269,11 +280,13 @@ RespondWithObserver::RespondWithObserver(ExecutionContext* context, int eventID, |
| , m_frameType(frameType) |
| , m_requestContext(requestContext) |
| , m_state(Initial) |
| + , m_observer(observer) |
| { |
| } |
| DEFINE_TRACE(RespondWithObserver) |
| { |
| + visitor->trace(m_observer); |
| ContextLifecycleObserver::trace(visitor); |
| } |