OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 private: | 56 private: |
57 ThenFunction(ScriptState* script_state, | 57 ThenFunction(ScriptState* script_state, |
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 DCHECK(observer_); | 65 DCHECK(observer_); |
66 ASSERT(resolve_type_ == kFulfilled || resolve_type_ == kRejected); | 66 DCHECK(resolve_type_ == kFulfilled || resolve_type_ == kRejected); |
67 if (resolve_type_ == kRejected) { | 67 if (resolve_type_ == kRejected) { |
68 observer_->OnPromiseRejected(); | 68 observer_->OnPromiseRejected(); |
69 value = | 69 value = |
70 ScriptPromise::Reject(value.GetScriptState(), value).GetScriptValue(); | 70 ScriptPromise::Reject(value.GetScriptState(), value).GetScriptValue(); |
71 } else { | 71 } else { |
72 observer_->OnPromiseFulfilled(); | 72 observer_->OnPromiseFulfilled(); |
73 } | 73 } |
74 observer_ = nullptr; | 74 observer_ = nullptr; |
75 return value; | 75 return value; |
76 } | 76 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void WaitUntilObserver::OnPromiseRejected() { | 151 void WaitUntilObserver::OnPromiseRejected() { |
152 has_rejected_promise_ = true; | 152 has_rejected_promise_ = true; |
153 DecrementPendingActivity(); | 153 DecrementPendingActivity(); |
154 } | 154 } |
155 | 155 |
156 void WaitUntilObserver::IncrementPendingActivity() { | 156 void WaitUntilObserver::IncrementPendingActivity() { |
157 ++pending_activity_; | 157 ++pending_activity_; |
158 } | 158 } |
159 | 159 |
160 void WaitUntilObserver::DecrementPendingActivity() { | 160 void WaitUntilObserver::DecrementPendingActivity() { |
161 ASSERT(pending_activity_ > 0); | 161 DCHECK_GT(pending_activity_, 0); |
162 if (!execution_context_ || | 162 if (!execution_context_ || |
163 (event_dispatch_state_ != EventDispatchState::kFailed && | 163 (event_dispatch_state_ != EventDispatchState::kFailed && |
164 --pending_activity_)) | 164 --pending_activity_)) |
165 return; | 165 return; |
166 | 166 |
167 ServiceWorkerGlobalScopeClient* client = | 167 ServiceWorkerGlobalScopeClient* client = |
168 ServiceWorkerGlobalScopeClient::From(execution_context_); | 168 ServiceWorkerGlobalScopeClient::From(execution_context_); |
169 WebServiceWorkerEventResult result = | 169 WebServiceWorkerEventResult result = |
170 (event_dispatch_state_ == EventDispatchState::kFailed || | 170 (event_dispatch_state_ == EventDispatchState::kFailed || |
171 has_rejected_promise_) | 171 has_rejected_promise_) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (!execution_context_) | 229 if (!execution_context_) |
230 return; | 230 return; |
231 execution_context_->ConsumeWindowInteraction(); | 231 execution_context_->ConsumeWindowInteraction(); |
232 } | 232 } |
233 | 233 |
234 DEFINE_TRACE(WaitUntilObserver) { | 234 DEFINE_TRACE(WaitUntilObserver) { |
235 visitor->Trace(execution_context_); | 235 visitor->Trace(execution_context_); |
236 } | 236 } |
237 | 237 |
238 } // namespace blink | 238 } // namespace blink |
OLD | NEW |