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

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

Issue 2867023002: [ServiceWorker] waitUntil() should wait until all promises got resolved/rejected. (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/WaitUntilObserver.h" 5 #include "modules/serviceworkers/WaitUntilObserver.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/V8BindingForCore.h" 10 #include "bindings/core/v8/V8BindingForCore.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 WaitUntilObserver* observer, 58 WaitUntilObserver* observer,
59 ResolveType type) 59 ResolveType type)
60 : ScriptFunction(script_state), 60 : ScriptFunction(script_state),
61 observer_(observer), 61 observer_(observer),
62 resolve_type_(type) {} 62 resolve_type_(type) {}
63 63
64 ScriptValue Call(ScriptValue value) override { 64 ScriptValue Call(ScriptValue value) override {
65 ASSERT(observer_); 65 ASSERT(observer_);
66 ASSERT(resolve_type_ == kFulfilled || resolve_type_ == kRejected); 66 ASSERT(resolve_type_ == kFulfilled || resolve_type_ == kRejected);
67 if (resolve_type_ == kRejected) { 67 if (resolve_type_ == kRejected) {
68 observer_->ReportError(value); 68 observer_->ReportPromiseRejected(value);
69 value = 69 value =
70 ScriptPromise::Reject(value.GetScriptState(), value).GetScriptValue(); 70 ScriptPromise::Reject(value.GetScriptState(), value).GetScriptValue();
71 } 71 }
72 observer_->DecrementPendingActivity(); 72 observer_->DecrementPendingActivity();
73 observer_ = nullptr; 73 observer_ = nullptr;
74 return value; 74 return value;
75 } 75 }
76 76
77 Member<WaitUntilObserver> observer_; 77 Member<WaitUntilObserver> observer_;
78 ResolveType resolve_type_; 78 ResolveType resolve_type_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 EventType type, 136 EventType type,
137 int event_id) 137 int event_id)
138 : execution_context_(context), 138 : execution_context_(context),
139 type_(type), 139 type_(type),
140 event_id_(event_id), 140 event_id_(event_id),
141 consume_window_interaction_timer_( 141 consume_window_interaction_timer_(
142 Platform::Current()->CurrentThread()->GetWebTaskRunner(), 142 Platform::Current()->CurrentThread()->GetWebTaskRunner(),
143 this, 143 this,
144 &WaitUntilObserver::ConsumeWindowInteraction) {} 144 &WaitUntilObserver::ConsumeWindowInteraction) {}
145 145
146 void WaitUntilObserver::ReportError(const ScriptValue& value) { 146 void WaitUntilObserver::ReportPromiseRejected(const ScriptValue& value) {
147 // FIXME: Propagate error message to the client for onerror handling. 147 // FIXME: Propagate error message to the client for onerror handling.
leonhsl(Using Gerrit) 2017/05/08 10:33:48 ServiceWorker spec does not have such requirement,
148 NOTIMPLEMENTED(); 148 NOTIMPLEMENTED();
leonhsl(Using Gerrit) 2017/05/08 10:33:48 I'm confused why NOTIMPLEMENTED() here does not cr
falken 2017/05/09 04:00:25 I think it's fine to delete the FIXME and the NOTI
leonhsl(Using Gerrit) 2017/05/09 07:26:52 Done.
149 149
150 has_error_ = true; 150 has_rejected_promise_ = true;
151 } 151 }
152 152
153 void WaitUntilObserver::IncrementPendingActivity() { 153 void WaitUntilObserver::IncrementPendingActivity() {
154 ++pending_activity_; 154 ++pending_activity_;
155 } 155 }
156 156
157 void WaitUntilObserver::DecrementPendingActivity() { 157 void WaitUntilObserver::DecrementPendingActivity() {
158 ASSERT(pending_activity_ > 0); 158 ASSERT(pending_activity_ > 0);
159 if (!execution_context_ || (!has_error_ && --pending_activity_)) 159 if (!execution_context_ || (!has_error_ && --pending_activity_))
160 return; 160 return;
161 161
162 ServiceWorkerGlobalScopeClient* client = 162 ServiceWorkerGlobalScopeClient* client =
163 ServiceWorkerGlobalScopeClient::From(execution_context_); 163 ServiceWorkerGlobalScopeClient::From(execution_context_);
164 WebServiceWorkerEventResult result = 164 WebServiceWorkerEventResult result =
165 has_error_ ? kWebServiceWorkerEventResultRejected 165 (has_error_ || has_rejected_promise_)
166 : kWebServiceWorkerEventResultCompleted; 166 ? kWebServiceWorkerEventResultRejected
167 : kWebServiceWorkerEventResultCompleted;
167 switch (type_) { 168 switch (type_) {
168 case kActivate: 169 case kActivate:
169 client->DidHandleActivateEvent(event_id_, result, event_dispatch_time_); 170 client->DidHandleActivateEvent(event_id_, result, event_dispatch_time_);
170 break; 171 break;
171 case kFetch: 172 case kFetch:
172 client->DidHandleFetchEvent(event_id_, result, event_dispatch_time_); 173 client->DidHandleFetchEvent(event_id_, result, event_dispatch_time_);
173 break; 174 break;
174 case kInstall: 175 case kInstall:
175 client->DidHandleInstallEvent(event_id_, result, event_dispatch_time_); 176 client->DidHandleInstallEvent(event_id_, result, event_dispatch_time_);
176 break; 177 break;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (!execution_context_) 223 if (!execution_context_)
223 return; 224 return;
224 execution_context_->ConsumeWindowInteraction(); 225 execution_context_->ConsumeWindowInteraction();
225 } 226 }
226 227
227 DEFINE_TRACE(WaitUntilObserver) { 228 DEFINE_TRACE(WaitUntilObserver) {
228 visitor->Trace(execution_context_); 229 visitor->Trace(execution_context_);
229 } 230 }
230 231
231 } // namespace blink 232 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698