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

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

Issue 2517223002: Move content/renderer/background_sync to Blink (Closed)
Patch Set: Fix broken WebEmbeddedWorker test 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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return value; 73 return value;
74 } 74 }
75 75
76 Member<WaitUntilObserver> m_observer; 76 Member<WaitUntilObserver> m_observer;
77 ResolveType m_resolveType; 77 ResolveType m_resolveType;
78 }; 78 };
79 79
80 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, 80 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context,
81 EventType type, 81 EventType type,
82 int eventID) { 82 int eventID) {
83 return new WaitUntilObserver(context, type, eventID); 83 return new WaitUntilObserver(context, type, eventID, nullptr);
84 }
85
86 WaitUntilObserver* WaitUntilObserver::create(
87 ExecutionContext* context,
88 EventType type,
89 std::unique_ptr<Callback> callback) {
90 return new WaitUntilObserver(context, type, -1, std::move(callback));
84 } 91 }
85 92
86 void WaitUntilObserver::willDispatchEvent() { 93 void WaitUntilObserver::willDispatchEvent() {
87 m_eventDispatchTime = WTF::currentTime(); 94 m_eventDispatchTime = WTF::currentTime();
88 // When handling a notificationclick event, we want to allow one window to 95 // 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 96 // be focused or opened. These calls are allowed between the call to
90 // willDispatchEvent() and the last call to decrementPendingActivity(). If 97 // willDispatchEvent() and the last call to decrementPendingActivity(). If
91 // waitUntil() isn't called, that means between willDispatchEvent() and 98 // waitUntil() isn't called, that means between willDispatchEvent() and
92 // didDispatchEvent(). 99 // didDispatchEvent().
93 if (m_type == NotificationClick) 100 if (m_type == NotificationClick)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 BLINK_FROM_HERE); 132 BLINK_FROM_HERE);
126 133
127 incrementPendingActivity(); 134 incrementPendingActivity();
128 scriptPromise.then( 135 scriptPromise.then(
129 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled), 136 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled),
130 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)); 137 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected));
131 } 138 }
132 139
133 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, 140 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context,
134 EventType type, 141 EventType type,
135 int eventID) 142 int eventID,
143 std::unique_ptr<Callback> callback)
136 : ContextLifecycleObserver(context), 144 : ContextLifecycleObserver(context),
137 m_type(type), 145 m_type(type),
138 m_eventID(eventID), 146 m_eventID(eventID),
139 m_consumeWindowInteractionTimer( 147 m_consumeWindowInteractionTimer(
140 this, 148 this,
141 &WaitUntilObserver::consumeWindowInteraction) {} 149 &WaitUntilObserver::consumeWindowInteraction),
150 m_callback(std::move(callback)) {}
142 151
143 void WaitUntilObserver::reportError(const ScriptValue& value) { 152 void WaitUntilObserver::reportError(const ScriptValue& value) {
144 // FIXME: Propagate error message to the client for onerror handling. 153 // FIXME: Propagate error message to the client for onerror handling.
145 NOTIMPLEMENTED(); 154 NOTIMPLEMENTED();
146 155
147 m_hasError = true; 156 m_hasError = true;
148 } 157 }
149 158
150 void WaitUntilObserver::incrementPendingActivity() { 159 void WaitUntilObserver::incrementPendingActivity() {
151 ++m_pendingActivity; 160 ++m_pendingActivity;
(...skipping 30 matching lines...) Expand all
182 consumeWindowInteraction(nullptr); 191 consumeWindowInteraction(nullptr);
183 break; 192 break;
184 case NotificationClose: 193 case NotificationClose:
185 client->didHandleNotificationCloseEvent(m_eventID, result, 194 client->didHandleNotificationCloseEvent(m_eventID, result,
186 m_eventDispatchTime); 195 m_eventDispatchTime);
187 break; 196 break;
188 case Push: 197 case Push:
189 client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime); 198 client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime);
190 break; 199 break;
191 case Sync: 200 case Sync:
192 client->didHandleSyncEvent(m_eventID, result, m_eventDispatchTime); 201 DCHECK(m_callback);
202 (*m_callback)(m_hasError
203 ? blink::mojom::ServiceWorkerEventStatus::REJECTED
204 : blink::mojom::ServiceWorkerEventStatus::COMPLETED,
205 m_eventDispatchTime);
193 break; 206 break;
194 } 207 }
195 setContext(nullptr); 208 setContext(nullptr);
196 } 209 }
197 210
198 void WaitUntilObserver::consumeWindowInteraction(TimerBase*) { 211 void WaitUntilObserver::consumeWindowInteraction(TimerBase*) {
199 if (!getExecutionContext()) 212 if (!getExecutionContext())
200 return; 213 return;
201 getExecutionContext()->consumeWindowInteraction(); 214 getExecutionContext()->consumeWindowInteraction();
202 } 215 }
203 216
217 void WaitUntilObserver::contextDestroyed() {
218 if (m_type == Sync && !m_eventDispatched) {
219 DCHECK(m_callback);
220 (*m_callback)(blink::mojom::ServiceWorkerEventStatus::ABORTED,
221 WTF::currentTime());
222 m_eventDispatched = true;
223 }
224 ContextLifecycleObserver::contextDestroyed();
225 }
226
204 DEFINE_TRACE(WaitUntilObserver) { 227 DEFINE_TRACE(WaitUntilObserver) {
205 ContextLifecycleObserver::trace(visitor); 228 ContextLifecycleObserver::trace(visitor);
206 } 229 }
207 230
208 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698