| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 115 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 116 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
| 117 BrowserThread::IO, FROM_HERE, | 117 BrowserThread::IO, FROM_HERE, |
| 118 base::Bind(&ServiceWorkerDispatcherHost::Init, | 118 base::Bind(&ServiceWorkerDispatcherHost::Init, |
| 119 this, make_scoped_refptr(context_wrapper))); | 119 this, make_scoped_refptr(context_wrapper))); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 context_wrapper_ = context_wrapper; | 123 context_wrapper_ = context_wrapper; |
| 124 GetContext()->embedded_worker_registry()->AddChildProcessSender( | 124 GetContext()->embedded_worker_registry()->AddChildProcessSender( |
| 125 render_process_id_, this); | 125 render_process_id_, this, message_port_message_filter_); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Sender* sender) { | 128 void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Sender* sender) { |
| 129 TRACE_EVENT0("ServiceWorker", | 129 TRACE_EVENT0("ServiceWorker", |
| 130 "ServiceWorkerDispatcherHost::OnFilterAdded"); | 130 "ServiceWorkerDispatcherHost::OnFilterAdded"); |
| 131 channel_ready_ = true; | 131 channel_ready_ = true; |
| 132 std::vector<IPC::Message*> messages; | 132 std::vector<IPC::Message*> messages; |
| 133 pending_messages_.release(&messages); | 133 pending_messages_.release(&messages); |
| 134 for (size_t i = 0; i < messages.size(); ++i) { | 134 for (size_t i = 0; i < messages.size(); ++i) { |
| 135 BrowserMessageFilter::Send(messages[i]); | 135 BrowserMessageFilter::Send(messages[i]); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); | 463 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); |
| 464 if (!GetContext()) | 464 if (!GetContext()) |
| 465 return; | 465 return; |
| 466 | 466 |
| 467 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 467 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
| 468 if (!handle) { | 468 if (!handle) { |
| 469 BadMessageReceived(); | 469 BadMessageReceived(); |
| 470 return; | 470 return; |
| 471 } | 471 } |
| 472 | 472 |
| 473 std::vector<int> new_routing_ids; | 473 handle->version()->DispatchMessageEvent( |
| 474 message_port_message_filter_->UpdateMessagePortsWithNewRoutes( | 474 message, sent_message_port_ids, |
| 475 sent_message_port_ids, &new_routing_ids); | |
| 476 handle->version()->SendMessage( | |
| 477 ServiceWorkerMsg_MessageToWorker(message, | |
| 478 sent_message_port_ids, | |
| 479 new_routing_ids), | |
| 480 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 475 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 481 } | 476 } |
| 482 | 477 |
| 483 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { | 478 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { |
| 484 TRACE_EVENT0("ServiceWorker", | 479 TRACE_EVENT0("ServiceWorker", |
| 485 "ServiceWorkerDispatcherHost::OnProviderCreated"); | 480 "ServiceWorkerDispatcherHost::OnProviderCreated"); |
| 486 if (!GetContext()) | 481 if (!GetContext()) |
| 487 return; | 482 return; |
| 488 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 483 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
| 489 BadMessageReceived(); | 484 BadMessageReceived(); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 thread_id, request_id, error_type, error_message)); | 852 thread_id, request_id, error_type, error_message)); |
| 858 } | 853 } |
| 859 | 854 |
| 860 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 855 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
| 861 if (!context_wrapper_.get()) | 856 if (!context_wrapper_.get()) |
| 862 return nullptr; | 857 return nullptr; |
| 863 return context_wrapper_->context(); | 858 return context_wrapper_->context(); |
| 864 } | 859 } |
| 865 | 860 |
| 866 } // namespace content | 861 } // namespace content |
| OLD | NEW |