| 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/browser/navigator_connect/navigator_connect_dispatcher_host.h" | 5 #include "content/browser/navigator_connect/navigator_connect_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "content/browser/message_port_service.h" | 7 #include "content/browser/message_port_service.h" |
| 8 #include "content/browser/navigator_connect/navigator_connect_context.h" |
| 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 9 #include "content/common/navigator_connect_messages.h" | 10 #include "content/common/navigator_connect_messages.h" |
| 10 #include "content/common/navigator_connect_types.h" | 11 #include "content/common/navigator_connect_types.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 NavigatorConnectDispatcherHost::NavigatorConnectDispatcherHost( | 15 NavigatorConnectDispatcherHost::NavigatorConnectDispatcherHost( |
| 15 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) | 16 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, |
| 17 const scoped_refptr<NavigatorConnectContext>& navigator_connect_context) |
| 16 : BrowserMessageFilter(NavigatorConnectMsgStart), | 18 : BrowserMessageFilter(NavigatorConnectMsgStart), |
| 17 service_worker_context_(service_worker_context) { | 19 service_worker_context_(service_worker_context), |
| 20 navigator_connect_context_(navigator_connect_context) { |
| 18 } | 21 } |
| 19 | 22 |
| 20 NavigatorConnectDispatcherHost::~NavigatorConnectDispatcherHost() { | 23 NavigatorConnectDispatcherHost::~NavigatorConnectDispatcherHost() { |
| 21 } | 24 } |
| 22 | 25 |
| 23 bool NavigatorConnectDispatcherHost::OnMessageReceived( | 26 bool NavigatorConnectDispatcherHost::OnMessageReceived( |
| 24 const IPC::Message& message) { | 27 const IPC::Message& message) { |
| 25 bool handled = true; | 28 bool handled = true; |
| 26 IPC_BEGIN_MESSAGE_MAP(NavigatorConnectDispatcherHost, message) | 29 IPC_BEGIN_MESSAGE_MAP(NavigatorConnectDispatcherHost, message) |
| 27 IPC_MESSAGE_HANDLER(NavigatorConnectHostMsg_Connect, OnConnect) | 30 IPC_MESSAGE_HANDLER(NavigatorConnectHostMsg_Connect, OnConnect) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const CrossOriginServiceWorkerClient& client, | 82 const CrossOriginServiceWorkerClient& client, |
| 80 const scoped_refptr<ServiceWorkerRegistration>& registration, | 83 const scoped_refptr<ServiceWorkerRegistration>& registration, |
| 81 ServiceWorkerStatusCode status, | 84 ServiceWorkerStatusCode status, |
| 82 bool accept_connection) { | 85 bool accept_connection) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 84 | 87 |
| 85 if (status != SERVICE_WORKER_OK || !accept_connection) { | 88 if (status != SERVICE_WORKER_OK || !accept_connection) { |
| 86 // Close port since connection failed. | 89 // Close port since connection failed. |
| 87 MessagePortService::GetInstance()->ClosePort(client.message_port_id); | 90 MessagePortService::GetInstance()->ClosePort(client.message_port_id); |
| 88 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, false)); | 91 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, false)); |
| 89 } else { | 92 return; |
| 90 // TODO(mek): Update MessagePortService to make communication between client | |
| 91 // and service possible. | |
| 92 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, true)); | |
| 93 } | 93 } |
| 94 |
| 95 // Register connection and post back result. |
| 96 navigator_connect_context_->RegisterConnection(client, registration); |
| 97 Send(new NavigatorConnectMsg_ConnectResult(thread_id, request_id, true)); |
| 94 } | 98 } |
| 95 | 99 |
| 96 } // namespace content | 100 } // namespace content |
| OLD | NEW |