Chromium Code Reviews| Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| index a02c5690faf9bd6d5de743a6c257decf1dd056b5..389ed4e8796f821255aab311e772b0b6088cf742 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -5,10 +5,12 @@ |
| #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "content/browser/message_port_message_filter.h" |
| +#include "content/browser/message_port_service.h" |
| #include "content/browser/service_worker/embedded_worker_registry.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_provider_host.h" |
| +#include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/common/service_worker/embedded_worker_messages.h" |
| #include "content/common/service_worker/service_worker_messages.h" |
| #include "ipc/ipc_message_macros.h" |
| @@ -34,10 +36,12 @@ const uint32 kFilteredMessageClasses[] = { |
| namespace content { |
| ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| - int render_process_id) |
| - : BrowserMessageFilter( |
| - kFilteredMessageClasses, arraysize(kFilteredMessageClasses)), |
| - render_process_id_(render_process_id) { |
| + int render_process_id, |
| + MessagePortMessageFilter* message_port_message_filter) |
| + : BrowserMessageFilter(kFilteredMessageClasses, |
| + arraysize(kFilteredMessageClasses)), |
| + render_process_id_(render_process_id), |
| + message_port_message_filter_(message_port_message_filter) { |
| } |
| ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { |
| @@ -84,6 +88,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| OnAddScriptClient) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RemoveScriptClient, |
| OnRemoveScriptClient) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, |
| + OnPostMessage) |
| IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, |
| OnWorkerStarted) |
| IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, |
| @@ -157,6 +163,47 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| request_id)); |
| } |
| +void ServiceWorkerDispatcherHost::OnPostMessage( |
| + int64 registration_id, |
| + const base::string16& message, |
| + const std::vector<int>& sent_message_port_ids) { |
| + if (!context_ || !context_->IsEnabled()) |
| + return; |
| + |
| + context_->storage()->FindRegistrationForId( |
| + registration_id, |
| + base::Bind(&ServiceWorkerDispatcherHost::PostMessageFoundRegistration, |
| + this, |
| + message, |
| + sent_message_port_ids)); |
| +} |
| + |
| +static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} |
|
jsbell
2014/03/13 17:53:27
BTW, this is necessary since ServiceWorkerVersion:
michaeln
2014/03/13 21:16:42
No strong opionion. Putting it in the _utils.h fil
|
| + |
| +void ServiceWorkerDispatcherHost::PostMessageFoundRegistration( |
| + const base::string16& message, |
| + const std::vector<int>& sent_message_port_ids, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& result) { |
| + // TODO(jsbell): Can we assert anything here? |
| + if (status == SERVICE_WORKER_ERROR_NOT_FOUND) |
|
michaeln
2014/03/12 23:38:47
Maybe test for SUCCESS instead, there could be mor
jsbell
2014/03/13 17:53:27
Done.
|
| + return; |
| + |
| + std::vector<int> new_routing_ids(sent_message_port_ids.size()); |
| + for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| + new_routing_ids[i] = message_port_message_filter_->GetNextRoutingID(); |
|
michaeln
2014/03/12 23:38:47
I'm not so sure about the safety of this message_p
jsbell
2014/03/13 17:53:27
Very nice catch. This can be addressed by moving t
|
| + MessagePortService::GetInstance()->UpdateMessagePort( |
| + sent_message_port_ids[i], |
| + message_port_message_filter_, |
| + new_routing_ids[i]); |
| + } |
| + |
| + // TODO(jsbell): Route message to appropriate version. crbug.com/351797 |
| + result->active_version()->SendMessage( |
|
michaeln
2014/03/12 23:38:47
Any chance there may be no active version? If not
jsbell
2014/03/13 17:53:27
If window1 made a registration, window2 deletes th
michaeln
2014/03/13 21:16:42
Resilient sgtm if we're unsure but we need to nail
jsbell
2014/03/14 18:11:44
+N for large N.
|
| + ServiceWorkerMsg_Message(message, sent_message_port_ids, new_routing_ids), |
| + base::Bind(&NoOpStatusCallback)); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { |
| if (!context_) |
| return; |