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

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

Issue 2558773002: Remove ContextLifecycleObserver from WaitUntilObserver (Closed)
Patch Set: Created 4 years 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/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 void WaitUntilObserver::willDispatchEvent() { 86 void WaitUntilObserver::willDispatchEvent() {
87 m_eventDispatchTime = WTF::currentTime(); 87 m_eventDispatchTime = WTF::currentTime();
88 // When handling a notificationclick event, we want to allow one window to 88 // When handling a notificationclick event, we want to allow one window to
89 // be focused or opened. These calls are allowed between the call to 89 // be focused or opened. These calls are allowed between the call to
90 // willDispatchEvent() and the last call to decrementPendingActivity(). If 90 // willDispatchEvent() and the last call to decrementPendingActivity(). If
91 // waitUntil() isn't called, that means between willDispatchEvent() and 91 // waitUntil() isn't called, that means between willDispatchEvent() and
92 // didDispatchEvent(). 92 // didDispatchEvent().
93 if (m_type == NotificationClick) 93 if (m_type == NotificationClick)
94 getExecutionContext()->allowWindowInteraction(); 94 m_executionContext->allowWindowInteraction();
95 95
96 incrementPendingActivity(); 96 incrementPendingActivity();
97 } 97 }
98 98
99 void WaitUntilObserver::didDispatchEvent(bool errorOccurred) { 99 void WaitUntilObserver::didDispatchEvent(bool errorOccurred) {
100 if (errorOccurred) 100 if (errorOccurred)
101 m_hasError = true; 101 m_hasError = true;
102 decrementPendingActivity(); 102 decrementPendingActivity();
103 m_eventDispatched = true; 103 m_eventDispatched = true;
104 } 104 }
105 105
106 void WaitUntilObserver::waitUntil(ScriptState* scriptState, 106 void WaitUntilObserver::waitUntil(ScriptState* scriptState,
107 ScriptPromise scriptPromise, 107 ScriptPromise scriptPromise,
108 ExceptionState& exceptionState) { 108 ExceptionState& exceptionState) {
109 if (m_eventDispatched) { 109 if (m_eventDispatched) {
110 exceptionState.throwDOMException(InvalidStateError, 110 exceptionState.throwDOMException(InvalidStateError,
111 "The event handler is already finished."); 111 "The event handler is already finished.");
112 return; 112 return;
113 } 113 }
114 114
115 if (!getExecutionContext()) 115 if (!m_executionContext)
116 return; 116 return;
117 117
118 // When handling a notificationclick event, we want to allow one window to 118 // When handling a notificationclick event, we want to allow one window to
119 // be focused or opened. See comments in ::willDispatchEvent(). When 119 // be focused or opened. See comments in ::willDispatchEvent(). When
120 // waitUntil() is being used, opening or closing a window must happen in a 120 // waitUntil() is being used, opening or closing a window must happen in a
121 // timeframe specified by windowInteractionTimeout(), otherwise the calls 121 // timeframe specified by windowInteractionTimeout(), otherwise the calls
122 // will fail. 122 // will fail.
123 if (m_type == NotificationClick) 123 if (m_type == NotificationClick)
124 m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(), 124 m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(),
125 BLINK_FROM_HERE); 125 BLINK_FROM_HERE);
126 126
127 incrementPendingActivity(); 127 incrementPendingActivity();
128 scriptPromise.then( 128 scriptPromise.then(
129 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled), 129 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled),
130 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)); 130 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected));
131 } 131 }
132 132
133 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, 133 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context,
134 EventType type, 134 EventType type,
135 int eventID) 135 int eventID)
136 : ContextLifecycleObserver(context), 136 : m_executionContext(context),
137 m_type(type), 137 m_type(type),
138 m_eventID(eventID), 138 m_eventID(eventID),
139 m_consumeWindowInteractionTimer( 139 m_consumeWindowInteractionTimer(
140 this, 140 this,
141 &WaitUntilObserver::consumeWindowInteraction) {} 141 &WaitUntilObserver::consumeWindowInteraction) {}
142 142
143 void WaitUntilObserver::reportError(const ScriptValue& value) { 143 void WaitUntilObserver::reportError(const ScriptValue& value) {
144 // FIXME: Propagate error message to the client for onerror handling. 144 // FIXME: Propagate error message to the client for onerror handling.
145 NOTIMPLEMENTED(); 145 NOTIMPLEMENTED();
146 146
147 m_hasError = true; 147 m_hasError = true;
148 } 148 }
149 149
150 void WaitUntilObserver::incrementPendingActivity() { 150 void WaitUntilObserver::incrementPendingActivity() {
151 ++m_pendingActivity; 151 ++m_pendingActivity;
152 } 152 }
153 153
154 void WaitUntilObserver::decrementPendingActivity() { 154 void WaitUntilObserver::decrementPendingActivity() {
155 ASSERT(m_pendingActivity > 0); 155 ASSERT(m_pendingActivity > 0);
156 if (!getExecutionContext() || (!m_hasError && --m_pendingActivity)) 156 if (!m_executionContext || (!m_hasError && --m_pendingActivity))
157 return; 157 return;
158 158
159 ServiceWorkerGlobalScopeClient* client = 159 ServiceWorkerGlobalScopeClient* client =
160 ServiceWorkerGlobalScopeClient::from(getExecutionContext()); 160 ServiceWorkerGlobalScopeClient::from(m_executionContext);
161 WebServiceWorkerEventResult result = 161 WebServiceWorkerEventResult result =
162 m_hasError ? WebServiceWorkerEventResultRejected 162 m_hasError ? WebServiceWorkerEventResultRejected
163 : WebServiceWorkerEventResultCompleted; 163 : WebServiceWorkerEventResultCompleted;
164 switch (m_type) { 164 switch (m_type) {
165 case Activate: 165 case Activate:
166 client->didHandleActivateEvent(m_eventID, result, m_eventDispatchTime); 166 client->didHandleActivateEvent(m_eventID, result, m_eventDispatchTime);
167 break; 167 break;
168 case Fetch: 168 case Fetch:
169 client->didHandleFetchEvent(m_eventID, result, m_eventDispatchTime); 169 client->didHandleFetchEvent(m_eventID, result, m_eventDispatchTime);
170 break; 170 break;
(...skipping 18 matching lines...) Expand all
189 client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime); 189 client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime);
190 break; 190 break;
191 case Sync: 191 case Sync:
192 client->didHandleSyncEvent(m_eventID, result, m_eventDispatchTime); 192 client->didHandleSyncEvent(m_eventID, result, m_eventDispatchTime);
193 break; 193 break;
194 case PaymentRequest: 194 case PaymentRequest:
195 client->didHandlePaymentRequestEvent(m_eventID, result, 195 client->didHandlePaymentRequestEvent(m_eventID, result,
196 m_eventDispatchTime); 196 m_eventDispatchTime);
197 break; 197 break;
198 } 198 }
199 setContext(nullptr); 199 m_executionContext = nullptr;
200 } 200 }
201 201
202 void WaitUntilObserver::consumeWindowInteraction(TimerBase*) { 202 void WaitUntilObserver::consumeWindowInteraction(TimerBase*) {
203 if (!getExecutionContext()) 203 if (!m_executionContext)
204 return; 204 return;
205 getExecutionContext()->consumeWindowInteraction(); 205 m_executionContext->consumeWindowInteraction();
206 } 206 }
207 207
208 DEFINE_TRACE(WaitUntilObserver) { 208 DEFINE_TRACE(WaitUntilObserver) {
209 ContextLifecycleObserver::trace(visitor); 209 visitor->trace(m_executionContext);
210 } 210 }
211 211
212 } // namespace blink 212 } // 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