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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 151 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
151 // (with thread hopping), so we need to do the same thread hopping here not | 152 // (with thread hopping), so we need to do the same thread hopping here not |
152 // to overtake those messages. | 153 // to overtake those messages. |
153 embedded_context_->main_thread_proxy()->PostTask( | 154 embedded_context_->main_thread_proxy()->PostTask( |
154 FROM_HERE, | 155 FROM_HERE, |
155 base::Bind(&SendPostMessageToDocumentOnMainThread, | 156 base::Bind(&SendPostMessageToDocumentOnMainThread, |
156 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 157 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
157 GetRoutingID(), client_id, message, base::Passed(&channels))); | 158 GetRoutingID(), client_id, message, base::Passed(&channels))); |
158 } | 159 } |
159 | 160 |
| 161 void ServiceWorkerScriptContext::SkipWaiting(blink::WebCallback* callback) { |
| 162 DCHECK(callback); |
| 163 int request_id = pending_skip_waiting_callbacks_.Add(callback); |
| 164 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 165 } |
| 166 |
160 void ServiceWorkerScriptContext::Send(IPC::Message* message) { | 167 void ServiceWorkerScriptContext::Send(IPC::Message* message) { |
161 embedded_context_->Send(message); | 168 embedded_context_->Send(message); |
162 } | 169 } |
163 | 170 |
164 int ServiceWorkerScriptContext::GetRoutingID() const { | 171 int ServiceWorkerScriptContext::GetRoutingID() const { |
165 return embedded_context_->embedded_worker_id(); | 172 return embedded_context_->embedded_worker_id(); |
166 } | 173 } |
167 | 174 |
168 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { | 175 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { |
169 TRACE_EVENT0("ServiceWorker", | 176 TRACE_EVENT0("ServiceWorker", |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 NOTREACHED() << "Got stray response: " << request_id; | 281 NOTREACHED() << "Got stray response: " << request_id; |
275 return; | 282 return; |
276 } | 283 } |
277 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( | 284 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( |
278 new blink::WebServiceWorkerClientsInfo); | 285 new blink::WebServiceWorkerClientsInfo); |
279 info->clientIDs = client_ids; | 286 info->clientIDs = client_ids; |
280 callbacks->onSuccess(info.release()); | 287 callbacks->onSuccess(info.release()); |
281 pending_clients_callbacks_.Remove(request_id); | 288 pending_clients_callbacks_.Remove(request_id); |
282 } | 289 } |
283 | 290 |
| 291 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { |
| 292 blink::WebCallback* callback = |
| 293 pending_skip_waiting_callbacks_.Lookup(request_id); |
| 294 if (!callback) { |
| 295 NOTREACHED() << "Got stray response: " << request_id; |
| 296 return; |
| 297 } |
| 298 callback->run(); |
| 299 pending_skip_waiting_callbacks_.Remove(request_id); |
| 300 } |
| 301 |
284 } // namespace content | 302 } // namespace content |
OLD | NEW |