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

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

Issue 2877543003: [ServiceWorker] Allow waitUntil to be called multiple times asynchronously (Closed)
Patch Set: Address comments from shimazu@ Created 3 years, 7 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 <v8.h> 7 #include <v8.h>
8 8
9 #include "bindings/core/v8/ScriptFunction.h" 9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 event_dispatch_time_ = WTF::CurrentTime(); 74 event_dispatch_time_ = WTF::CurrentTime();
75 } 75 }
76 76
77 void RespondWithObserver::DidDispatchEvent( 77 void RespondWithObserver::DidDispatchEvent(
78 DispatchEventResult dispatch_result) { 78 DispatchEventResult dispatch_result) {
79 DCHECK(GetExecutionContext()); 79 DCHECK(GetExecutionContext());
80 if (state_ != kInitial) 80 if (state_ != kInitial)
81 return; 81 return;
82 82
83 if (dispatch_result != DispatchEventResult::kNotCanceled) { 83 if (dispatch_result != DispatchEventResult::kNotCanceled) {
84 observer_->IncrementPendingActivity(); 84 observer_->IncrementPendingPromise();
85 ResponseWasRejected(kWebServiceWorkerResponseErrorDefaultPrevented); 85 ResponseWasRejected(kWebServiceWorkerResponseErrorDefaultPrevented);
86 return; 86 return;
87 } 87 }
88 88
89 OnNoResponse(); 89 OnNoResponse();
90 state_ = kDone; 90 state_ = kDone;
91 observer_.Clear(); 91 observer_.Clear();
92 } 92 }
93 93
94 void RespondWithObserver::RespondWith(ScriptState* script_state, 94 void RespondWithObserver::RespondWith(ScriptState* script_state,
95 ScriptPromise script_promise, 95 ScriptPromise script_promise,
96 ExceptionState& exception_state) { 96 ExceptionState& exception_state) {
97 if (state_ != kInitial) { 97 if (state_ != kInitial) {
98 exception_state.ThrowDOMException( 98 exception_state.ThrowDOMException(
99 kInvalidStateError, "The event has already been responded to."); 99 kInvalidStateError, "The event has already been responded to.");
100 return; 100 return;
101 } 101 }
102 102
103 state_ = kPending; 103 state_ = kPending;
104 observer_->IncrementPendingActivity(); 104 observer_->IncrementPendingPromise();
105 script_promise.Then(ThenFunction::CreateFunction(script_state, this, 105 script_promise.Then(ThenFunction::CreateFunction(script_state, this,
106 ThenFunction::kFulfilled), 106 ThenFunction::kFulfilled),
107 ThenFunction::CreateFunction(script_state, this, 107 ThenFunction::CreateFunction(script_state, this,
108 ThenFunction::kRejected)); 108 ThenFunction::kRejected));
109 } 109 }
110 110
111 void RespondWithObserver::ResponseWasRejected( 111 void RespondWithObserver::ResponseWasRejected(
112 WebServiceWorkerResponseError error) { 112 WebServiceWorkerResponseError error) {
113 OnResponseRejected(error); 113 OnResponseRejected(error);
114 state_ = kDone; 114 state_ = kDone;
115 observer_->DecrementPendingActivity(); 115 observer_->DecrementPendingPromise();
116 observer_.Clear(); 116 observer_.Clear();
117 } 117 }
118 118
119 void RespondWithObserver::ResponseWasFulfilled(const ScriptValue& value) { 119 void RespondWithObserver::ResponseWasFulfilled(const ScriptValue& value) {
120 OnResponseFulfilled(value); 120 OnResponseFulfilled(value);
121 state_ = kDone; 121 state_ = kDone;
122 observer_->DecrementPendingActivity(); 122 observer_->DecrementPendingPromise();
123 observer_.Clear(); 123 observer_.Clear();
124 } 124 }
125 125
126 RespondWithObserver::RespondWithObserver(ExecutionContext* context, 126 RespondWithObserver::RespondWithObserver(ExecutionContext* context,
127 int event_id, 127 int event_id,
128 WaitUntilObserver* observer) 128 WaitUntilObserver* observer)
129 : ContextLifecycleObserver(context), 129 : ContextLifecycleObserver(context),
130 event_id_(event_id), 130 event_id_(event_id),
131 state_(kInitial), 131 state_(kInitial),
132 observer_(observer) {} 132 observer_(observer) {}
133 133
134 DEFINE_TRACE(RespondWithObserver) { 134 DEFINE_TRACE(RespondWithObserver) {
135 visitor->Trace(observer_); 135 visitor->Trace(observer_);
136 ContextLifecycleObserver::Trace(visitor); 136 ContextLifecycleObserver::Trace(visitor);
137 } 137 }
138 138
139 } // namespace blink 139 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698