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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/child/notifications/notification_data_conversions.h" | 10 #include "content/child/notifications/notification_data_conversions.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 | 247 |
248 void ServiceWorkerScriptContext::PostMessageToDocument( | 248 void ServiceWorkerScriptContext::PostMessageToDocument( |
249 int client_id, | 249 int client_id, |
250 const base::string16& message, | 250 const base::string16& message, |
251 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 251 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
252 // This may send channels for MessagePorts, and all internal book-keeping | 252 // This may send channels for MessagePorts, and all internal book-keeping |
253 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 253 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
254 // (with thread hopping), so we need to do the same thread hopping here not | 254 // (with thread hopping), so we need to do the same thread hopping here not |
255 // to overtake those messages. | 255 // to overtake those messages. |
256 embedded_context_->main_thread_proxy()->PostTask( | 256 embedded_context_->main_thread_task_runner()->PostTask( |
257 FROM_HERE, | 257 FROM_HERE, |
258 base::Bind(&SendPostMessageToDocumentOnMainThread, | 258 base::Bind(&SendPostMessageToDocumentOnMainThread, |
259 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 259 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
260 GetRoutingID(), client_id, message, base::Passed(&channels))); | 260 GetRoutingID(), client_id, message, base::Passed(&channels))); |
261 } | 261 } |
262 | 262 |
263 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( | 263 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( |
264 const blink::WebCrossOriginServiceWorkerClient& client, | 264 const blink::WebCrossOriginServiceWorkerClient& client, |
265 const base::string16& message, | 265 const base::string16& message, |
266 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 266 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
267 // This may send channels for MessagePorts, and all internal book-keeping | 267 // This may send channels for MessagePorts, and all internal book-keeping |
268 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 268 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
269 // (with thread hopping), so we need to do the same thread hopping here not | 269 // (with thread hopping), so we need to do the same thread hopping here not |
270 // to overtake those messages. | 270 // to overtake those messages. |
271 embedded_context_->main_thread_proxy()->PostTask( | 271 embedded_context_->main_thread_task_runner()->PostTask( |
272 FROM_HERE, | 272 FROM_HERE, |
273 base::Bind(&SendCrossOriginMessageToClientOnMainThread, | 273 base::Bind(&SendCrossOriginMessageToClientOnMainThread, |
274 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 274 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
275 client.clientID, message, base::Passed(&channels))); | 275 client.clientID, message, base::Passed(&channels))); |
276 } | 276 } |
277 | 277 |
278 void ServiceWorkerScriptContext::FocusClient( | 278 void ServiceWorkerScriptContext::FocusClient( |
279 int client_id, blink::WebServiceWorkerClientCallbacks* callback) { | 279 int client_id, blink::WebServiceWorkerClientCallbacks* callback) { |
280 DCHECK(callback); | 280 DCHECK(callback); |
281 int request_id = pending_client_callbacks_.Add(callback); | 281 int request_id = pending_client_callbacks_.Add(callback); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 405 } |
406 | 406 |
407 void ServiceWorkerScriptContext::OnPostMessage( | 407 void ServiceWorkerScriptContext::OnPostMessage( |
408 const base::string16& message, | 408 const base::string16& message, |
409 const std::vector<int>& sent_message_port_ids, | 409 const std::vector<int>& sent_message_port_ids, |
410 const std::vector<int>& new_routing_ids) { | 410 const std::vector<int>& new_routing_ids) { |
411 TRACE_EVENT0("ServiceWorker", | 411 TRACE_EVENT0("ServiceWorker", |
412 "ServiceWorkerScriptContext::OnPostEvent"); | 412 "ServiceWorkerScriptContext::OnPostEvent"); |
413 std::vector<WebMessagePortChannelImpl*> ports; | 413 std::vector<WebMessagePortChannelImpl*> ports; |
414 if (!sent_message_port_ids.empty()) { | 414 if (!sent_message_port_ids.empty()) { |
415 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); | 415 base::SingleThreadTaskRunner* task_runner = |
| 416 embedded_context_->main_thread_task_runner(); |
416 ports.resize(sent_message_port_ids.size()); | 417 ports.resize(sent_message_port_ids.size()); |
417 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 418 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
418 ports[i] = new WebMessagePortChannelImpl( | 419 ports[i] = new WebMessagePortChannelImpl( |
419 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); | 420 new_routing_ids[i], sent_message_port_ids[i], task_runner); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 // dispatchMessageEvent is expected to execute onmessage function | 424 // dispatchMessageEvent is expected to execute onmessage function |
424 // synchronously. | 425 // synchronously. |
425 base::TimeTicks before = base::TimeTicks::Now(); | 426 base::TimeTicks before = base::TimeTicks::Now(); |
426 proxy_->dispatchMessageEvent(message, ports); | 427 proxy_->dispatchMessageEvent(message, ports); |
427 UMA_HISTOGRAM_TIMES( | 428 UMA_HISTOGRAM_TIMES( |
428 "ServiceWorker.MessageEventExecutionTime", | 429 "ServiceWorker.MessageEventExecutionTime", |
429 base::TimeTicks::Now() - before); | 430 base::TimeTicks::Now() - before); |
430 } | 431 } |
431 | 432 |
432 void ServiceWorkerScriptContext::OnCrossOriginMessageToWorker( | 433 void ServiceWorkerScriptContext::OnCrossOriginMessageToWorker( |
433 const NavigatorConnectClient& client, | 434 const NavigatorConnectClient& client, |
434 const base::string16& message, | 435 const base::string16& message, |
435 const std::vector<int>& sent_message_port_ids, | 436 const std::vector<int>& sent_message_port_ids, |
436 const std::vector<int>& new_routing_ids) { | 437 const std::vector<int>& new_routing_ids) { |
437 TRACE_EVENT0("ServiceWorker", | 438 TRACE_EVENT0("ServiceWorker", |
438 "ServiceWorkerScriptContext::OnCrossOriginMessageToWorker"); | 439 "ServiceWorkerScriptContext::OnCrossOriginMessageToWorker"); |
439 std::vector<WebMessagePortChannelImpl*> ports; | 440 std::vector<WebMessagePortChannelImpl*> ports; |
440 if (!sent_message_port_ids.empty()) { | 441 if (!sent_message_port_ids.empty()) { |
441 base::MessageLoopProxy* loop_proxy = embedded_context_->main_thread_proxy(); | 442 base::SingleThreadTaskRunner* task_runner = |
| 443 embedded_context_->main_thread_task_runner(); |
442 ports.resize(sent_message_port_ids.size()); | 444 ports.resize(sent_message_port_ids.size()); |
443 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 445 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
444 ports[i] = new WebMessagePortChannelImpl( | 446 ports[i] = new WebMessagePortChannelImpl( |
445 new_routing_ids[i], sent_message_port_ids[i], loop_proxy); | 447 new_routing_ids[i], sent_message_port_ids[i], task_runner); |
446 } | 448 } |
447 } | 449 } |
448 | 450 |
449 blink::WebCrossOriginServiceWorkerClient web_client; | 451 blink::WebCrossOriginServiceWorkerClient web_client; |
450 web_client.origin = client.origin; | 452 web_client.origin = client.origin; |
451 web_client.targetURL = client.target_url; | 453 web_client.targetURL = client.target_url; |
452 web_client.clientID = client.message_port_id; | 454 web_client.clientID = client.message_port_id; |
453 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); | 455 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); |
454 } | 456 } |
455 | 457 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 new blink::WebServiceWorkerError(error_type, message)); | 583 new blink::WebServiceWorkerError(error_type, message)); |
582 callbacks->onError(error.release()); | 584 callbacks->onError(error.release()); |
583 pending_claim_clients_callbacks_.Remove(request_id); | 585 pending_claim_clients_callbacks_.Remove(request_id); |
584 } | 586 } |
585 | 587 |
586 void ServiceWorkerScriptContext::OnPing() { | 588 void ServiceWorkerScriptContext::OnPing() { |
587 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 589 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
588 } | 590 } |
589 | 591 |
590 } // namespace content | 592 } // namespace content |
OLD | NEW |