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 "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 Loading... |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 166 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
166 // (with thread hopping), so we need to do the same thread hopping here not | 167 // (with thread hopping), so we need to do the same thread hopping here not |
167 // to overtake those messages. | 168 // to overtake those messages. |
168 embedded_context_->main_thread_proxy()->PostTask( | 169 embedded_context_->main_thread_proxy()->PostTask( |
169 FROM_HERE, | 170 FROM_HERE, |
170 base::Bind(&SendPostMessageToDocumentOnMainThread, | 171 base::Bind(&SendPostMessageToDocumentOnMainThread, |
171 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 172 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
172 GetRoutingID(), client_id, message, base::Passed(&channels))); | 173 GetRoutingID(), client_id, message, base::Passed(&channels))); |
173 } | 174 } |
174 | 175 |
| 176 void ServiceWorkerScriptContext::SkipWaiting( |
| 177 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
| 178 DCHECK(callbacks); |
| 179 int request_id = pending_skip_waiting_callbacks_.Add(callbacks); |
| 180 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 181 } |
| 182 |
175 void ServiceWorkerScriptContext::Send(IPC::Message* message) { | 183 void ServiceWorkerScriptContext::Send(IPC::Message* message) { |
176 embedded_context_->Send(message); | 184 embedded_context_->Send(message); |
177 } | 185 } |
178 | 186 |
179 int ServiceWorkerScriptContext::GetRoutingID() const { | 187 int ServiceWorkerScriptContext::GetRoutingID() const { |
180 return embedded_context_->embedded_worker_id(); | 188 return embedded_context_->embedded_worker_id(); |
181 } | 189 } |
182 | 190 |
183 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { | 191 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { |
184 TRACE_EVENT0("ServiceWorker", | 192 TRACE_EVENT0("ServiceWorker", |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 NOTREACHED() << "Got stray response: " << request_id; | 296 NOTREACHED() << "Got stray response: " << request_id; |
289 return; | 297 return; |
290 } | 298 } |
291 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( | 299 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( |
292 new blink::WebServiceWorkerClientsInfo); | 300 new blink::WebServiceWorkerClientsInfo); |
293 info->clientIDs = client_ids; | 301 info->clientIDs = client_ids; |
294 callbacks->onSuccess(info.release()); | 302 callbacks->onSuccess(info.release()); |
295 pending_clients_callbacks_.Remove(request_id); | 303 pending_clients_callbacks_.Remove(request_id); |
296 } | 304 } |
297 | 305 |
| 306 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { |
| 307 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
| 308 pending_skip_waiting_callbacks_.Lookup(request_id); |
| 309 if (!callbacks) { |
| 310 NOTREACHED() << "Got stray response: " << request_id; |
| 311 return; |
| 312 } |
| 313 callbacks->onSuccess(); |
| 314 pending_skip_waiting_callbacks_.Remove(request_id); |
| 315 } |
| 316 |
298 } // namespace content | 317 } // namespace content |
OLD | NEW |