Chromium Code Reviews| Index: content/browser/service_worker/embedded_worker_registry.cc |
| diff --git a/content/browser/service_worker/embedded_worker_registry.cc b/content/browser/service_worker/embedded_worker_registry.cc |
| index cf9dbe791121cd02b02f4e5bdf1d044dc55dbfb8..fec0cad1ddd81c766d240759856bb809ee974672 100644 |
| --- a/content/browser/service_worker/embedded_worker_registry.cc |
| +++ b/content/browser/service_worker/embedded_worker_registry.cc |
| @@ -11,6 +11,7 @@ |
| #include "content/browser/service_worker/embedded_worker_instance.h" |
| #include "content/browser/service_worker/service_worker_context_core.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| +#include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| #include "content/common/service_worker/embedded_worker_messages.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "ipc/ipc_message.h" |
| @@ -32,7 +33,6 @@ scoped_refptr<EmbeddedWorkerRegistry> EmbeddedWorkerRegistry::Create( |
| new EmbeddedWorkerRegistry( |
| context, |
| old_registry->next_embedded_worker_id_); |
| - registry->process_sender_map_.swap(old_registry->process_sender_map_); |
| return registry; |
| } |
| @@ -179,19 +179,7 @@ void EmbeddedWorkerRegistry::OnReportConsoleMessage( |
| line_number, source_url); |
| } |
| -void EmbeddedWorkerRegistry::AddChildProcessSender( |
| - int process_id, |
| - IPC::Sender* sender, |
| - MessagePortMessageFilter* message_port_message_filter) { |
| - process_sender_map_[process_id] = sender; |
| - process_message_port_message_filter_map_[process_id] = |
| - message_port_message_filter; |
| - DCHECK(!base::ContainsKey(worker_process_map_, process_id)); |
| -} |
| - |
| -void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { |
| - process_sender_map_.erase(process_id); |
| - process_message_port_message_filter_map_.erase(process_id); |
| +void EmbeddedWorkerRegistry::RemoveProcess(int process_id) { |
| std::map<int, std::set<int> >::iterator found = |
| worker_process_map_.find(process_id); |
| if (found != worker_process_map_.end()) { |
| @@ -201,10 +189,9 @@ void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { |
| ++it) { |
| int embedded_worker_id = *it; |
| DCHECK(base::ContainsKey(worker_map_, embedded_worker_id)); |
| - // Somehow the worker thread has lost contact with the browser process. |
| - // The renderer may have been killed. Set the worker's status to STOPPED |
| - // so a new thread can be created for this version. Use OnDetached rather |
| - // than OnStopped so UMA doesn't record it as a normal stoppage. |
| + // |worker_map_| doesn't have workers when it's stopped normally, and |
| + // this is for resetting the workers which has lost contact with the |
| + // browser process somehow. |
|
falken
2017/02/13 05:59:24
I like how the existing comment explains why OnDet
shimazu
2017/02/13 08:20:19
Done.
|
| worker_map_[embedded_worker_id]->OnDetached(); |
| } |
| worker_process_map_.erase(found); |
| @@ -229,7 +216,10 @@ bool EmbeddedWorkerRegistry::CanHandle(int embedded_worker_id) const { |
| MessagePortMessageFilter* |
| EmbeddedWorkerRegistry::MessagePortMessageFilterForProcess(int process_id) { |
| - return process_message_port_message_filter_map_[process_id]; |
| + ServiceWorkerDispatcherHost* dispatcher_host = |
| + context_->GetDispatcherHost(process_id); |
| + DCHECK(dispatcher_host); |
| + return dispatcher_host->message_port_message_filter(); |
| } |
| EmbeddedWorkerRegistry::EmbeddedWorkerRegistry( |
| @@ -246,10 +236,6 @@ EmbeddedWorkerRegistry::~EmbeddedWorkerRegistry() { |
| void EmbeddedWorkerRegistry::BindWorkerToProcess(int process_id, |
| int embedded_worker_id) { |
| - // The ServiceWorkerDispatcherHost is supposed to be created when the process |
| - // is created, and keep an entry in process_sender_map_ for its whole |
| - // lifetime. |
| - DCHECK(base::ContainsKey(process_sender_map_, process_id)); |
| DCHECK(GetWorker(embedded_worker_id)); |
| DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); |
| DCHECK( |
| @@ -264,10 +250,10 @@ ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( |
| std::unique_ptr<IPC::Message> message(message_ptr); |
| if (!context_) |
| return SERVICE_WORKER_ERROR_ABORT; |
| - ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); |
| - if (found == process_sender_map_.end()) |
| + IPC::Sender* sender = context_->GetDispatcherHost(process_id); |
| + if (!sender) |
| return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; |
| - if (!found->second->Send(message.release())) |
| + if (!sender->Send(message.release())) |
| return SERVICE_WORKER_ERROR_IPC_FAILED; |
| return SERVICE_WORKER_OK; |
| } |