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

Side by Side Diff: content/renderer/service_worker/service_worker_script_context.cc

Issue 717353004: ServiceWorker: Add support for .skipWaiting and controllerchange event(2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review update Created 6 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 "content/renderer/service_worker/service_worker_script_context.h" 5 #include "content/renderer/service_worker/service_worker_script_context.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "content/child/thread_safe_sender.h" 10 #include "content/child/thread_safe_sender.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) 74 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message)
75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) 75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) 76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent) 78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent)
79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) 80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) 81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage)
82 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, 82 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments,
83 OnDidGetClientDocuments) 83 OnDidGetClientDocuments)
84 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting)
84 IPC_MESSAGE_UNHANDLED(handled = false) 85 IPC_MESSAGE_UNHANDLED(handled = false)
85 IPC_END_MESSAGE_MAP() 86 IPC_END_MESSAGE_MAP()
86 87
87 // TODO(gavinp): Would it be preferable to put an AddListener() method to 88 // TODO(gavinp): Would it be preferable to put an AddListener() method to
88 // EmbeddedWorkerContextClient? 89 // EmbeddedWorkerContextClient?
89 if (!handled) 90 if (!handled)
90 handled = cache_storage_dispatcher_->OnMessageReceived(message); 91 handled = cache_storage_dispatcher_->OnMessageReceived(message);
91 92
92 DCHECK(handled); 93 DCHECK(handled);
93 } 94 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 165 // messages for MessagePort (e.g. QueueMessages) are sent from main thread
165 // (with thread hopping), so we need to do the same thread hopping here not 166 // (with thread hopping), so we need to do the same thread hopping here not
166 // to overtake those messages. 167 // to overtake those messages.
167 embedded_context_->main_thread_proxy()->PostTask( 168 embedded_context_->main_thread_proxy()->PostTask(
168 FROM_HERE, 169 FROM_HERE,
169 base::Bind(&SendPostMessageToDocumentOnMainThread, 170 base::Bind(&SendPostMessageToDocumentOnMainThread,
170 make_scoped_refptr(embedded_context_->thread_safe_sender()), 171 make_scoped_refptr(embedded_context_->thread_safe_sender()),
171 GetRoutingID(), client_id, message, base::Passed(&channels))); 172 GetRoutingID(), client_id, message, base::Passed(&channels)));
172 } 173 }
173 174
175 void ServiceWorkerScriptContext::SkipWaiting(
176 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) {
177 DCHECK(callbacks);
178 int request_id = pending_skip_waiting_callbacks_.Add(callbacks);
179 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id));
180 }
181
174 void ServiceWorkerScriptContext::Send(IPC::Message* message) { 182 void ServiceWorkerScriptContext::Send(IPC::Message* message) {
175 embedded_context_->Send(message); 183 embedded_context_->Send(message);
176 } 184 }
177 185
178 int ServiceWorkerScriptContext::GetRoutingID() const { 186 int ServiceWorkerScriptContext::GetRoutingID() const {
179 return embedded_context_->embedded_worker_id(); 187 return embedded_context_->embedded_worker_id();
180 } 188 }
181 189
182 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { 190 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) {
183 TRACE_EVENT0("ServiceWorker", 191 TRACE_EVENT0("ServiceWorker",
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 NOTREACHED() << "Got stray response: " << request_id; 295 NOTREACHED() << "Got stray response: " << request_id;
288 return; 296 return;
289 } 297 }
290 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( 298 scoped_ptr<blink::WebServiceWorkerClientsInfo> info(
291 new blink::WebServiceWorkerClientsInfo); 299 new blink::WebServiceWorkerClientsInfo);
292 info->clientIDs = client_ids; 300 info->clientIDs = client_ids;
293 callbacks->onSuccess(info.release()); 301 callbacks->onSuccess(info.release());
294 pending_clients_callbacks_.Remove(request_id); 302 pending_clients_callbacks_.Remove(request_id);
295 } 303 }
296 304
305 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) {
306 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks =
307 pending_skip_waiting_callbacks_.Lookup(request_id);
308 if (!callbacks) {
309 NOTREACHED() << "Got stray response: " << request_id;
310 return;
311 }
312 callbacks->onSuccess();
313 pending_skip_waiting_callbacks_.Remove(request_id);
314 }
315
297 } // namespace content 316 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698