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

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

Issue 2218943002: Introduce ServiceWorker.EventDispatchingDelay UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated mpearson@'s comment Created 4 years, 3 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/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ResolveType m_resolveType; 77 ResolveType m_resolveType;
78 }; 78 };
79 79
80 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp e type, int eventID) 80 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp e type, int eventID)
81 { 81 {
82 return new WaitUntilObserver(context, type, eventID); 82 return new WaitUntilObserver(context, type, eventID);
83 } 83 }
84 84
85 void WaitUntilObserver::willDispatchEvent() 85 void WaitUntilObserver::willDispatchEvent()
86 { 86 {
87 m_eventDispatchTime = WTF::currentTime();
87 // 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
88 // 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
89 // willDispatchEvent() and the last call to decrementPendingActivity(). If 90 // willDispatchEvent() and the last call to decrementPendingActivity(). If
90 // waitUntil() isn't called, that means between willDispatchEvent() and 91 // waitUntil() isn't called, that means between willDispatchEvent() and
91 // didDispatchEvent(). 92 // didDispatchEvent().
92 if (m_type == NotificationClick) 93 if (m_type == NotificationClick)
93 getExecutionContext()->allowWindowInteraction(); 94 getExecutionContext()->allowWindowInteraction();
94 95
95 incrementPendingActivity(); 96 incrementPendingActivity();
96 } 97 }
(...skipping 27 matching lines...) Expand all
124 incrementPendingActivity(); 125 incrementPendingActivity();
125 scriptPromise.then( 126 scriptPromise.then(
126 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) , 127 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) ,
127 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ; 128 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ;
128 } 129 }
129 130
130 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID) 131 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID)
131 : ContextLifecycleObserver(context) 132 : ContextLifecycleObserver(context)
132 , m_type(type) 133 , m_type(type)
133 , m_eventID(eventID) 134 , m_eventID(eventID)
134 , m_pendingActivity(0)
135 , m_hasError(false)
136 , m_eventDispatched(false)
137 , m_consumeWindowInteractionTimer(this, &WaitUntilObserver::consumeWindowInt eraction) 135 , m_consumeWindowInteractionTimer(this, &WaitUntilObserver::consumeWindowInt eraction)
138 { 136 {
139 } 137 }
140 138
141 void WaitUntilObserver::reportError(const ScriptValue& value) 139 void WaitUntilObserver::reportError(const ScriptValue& value)
142 { 140 {
143 // FIXME: Propagate error message to the client for onerror handling. 141 // FIXME: Propagate error message to the client for onerror handling.
144 NOTIMPLEMENTED(); 142 NOTIMPLEMENTED();
145 143
146 m_hasError = true; 144 m_hasError = true;
147 } 145 }
148 146
149 void WaitUntilObserver::incrementPendingActivity() 147 void WaitUntilObserver::incrementPendingActivity()
150 { 148 {
151 ++m_pendingActivity; 149 ++m_pendingActivity;
152 } 150 }
153 151
154 void WaitUntilObserver::decrementPendingActivity() 152 void WaitUntilObserver::decrementPendingActivity()
155 { 153 {
156 ASSERT(m_pendingActivity > 0); 154 ASSERT(m_pendingActivity > 0);
157 if (!getExecutionContext() || (!m_hasError && --m_pendingActivity)) 155 if (!getExecutionContext() || (!m_hasError && --m_pendingActivity))
158 return; 156 return;
159 157
160 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(getExecutionContext()); 158 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro m(getExecutionContext());
161 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul tRejected : WebServiceWorkerEventResultCompleted; 159 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul tRejected : WebServiceWorkerEventResultCompleted;
162 switch (m_type) { 160 switch (m_type) {
163 case Activate: 161 case Activate:
164 client->didHandleActivateEvent(m_eventID, result); 162 client->didHandleActivateEvent(m_eventID, result, m_eventDispatchTime);
165 break; 163 break;
166 case Fetch: 164 case Fetch:
167 client->didHandleFetchEvent(m_eventID, result); 165 client->didHandleFetchEvent(m_eventID, result, m_eventDispatchTime);
168 break; 166 break;
169 case Install: 167 case Install:
170 client->didHandleInstallEvent(m_eventID, result); 168 client->didHandleInstallEvent(m_eventID, result, m_eventDispatchTime);
171 break; 169 break;
172 case Message: 170 case Message:
173 client->didHandleExtendableMessageEvent(m_eventID, result); 171 client->didHandleExtendableMessageEvent(m_eventID, result, m_eventDispat chTime);
174 break; 172 break;
175 case NotificationClick: 173 case NotificationClick:
176 client->didHandleNotificationClickEvent(m_eventID, result); 174 client->didHandleNotificationClickEvent(m_eventID, result, m_eventDispat chTime);
177 m_consumeWindowInteractionTimer.stop(); 175 m_consumeWindowInteractionTimer.stop();
178 consumeWindowInteraction(nullptr); 176 consumeWindowInteraction(nullptr);
179 break; 177 break;
180 case NotificationClose: 178 case NotificationClose:
181 client->didHandleNotificationCloseEvent(m_eventID, result); 179 client->didHandleNotificationCloseEvent(m_eventID, result, m_eventDispat chTime);
182 break; 180 break;
183 case Push: 181 case Push:
184 client->didHandlePushEvent(m_eventID, result); 182 client->didHandlePushEvent(m_eventID, result, m_eventDispatchTime);
185 break; 183 break;
186 case Sync: 184 case Sync:
187 client->didHandleSyncEvent(m_eventID, result); 185 client->didHandleSyncEvent(m_eventID, result, m_eventDispatchTime);
188 break; 186 break;
189 } 187 }
190 setContext(nullptr); 188 setContext(nullptr);
191 } 189 }
192 190
193 void WaitUntilObserver::consumeWindowInteraction(TimerBase*) 191 void WaitUntilObserver::consumeWindowInteraction(TimerBase*)
194 { 192 {
195 if (!getExecutionContext()) 193 if (!getExecutionContext())
196 return; 194 return;
197 getExecutionContext()->consumeWindowInteraction(); 195 getExecutionContext()->consumeWindowInteraction();
198 } 196 }
199 197
200 DEFINE_TRACE(WaitUntilObserver) 198 DEFINE_TRACE(WaitUntilObserver)
201 { 199 {
202 ContextLifecycleObserver::trace(visitor); 200 ContextLifecycleObserver::trace(visitor);
203 } 201 }
204 202
205 } // namespace blink 203 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698