OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/navigator_connect/navigator_connect_dispatcher_host.h" | |
6 | |
7 #include "content/browser/message_port_service.h" | |
8 #include "content/browser/navigator_connect/navigator_connect_context_impl.h" | |
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" | |
10 #include "content/common/navigator_connect_messages.h" | |
11 #include "content/public/common/navigator_connect_client.h" | |
12 | |
13 namespace content { | |
14 | |
15 NavigatorConnectDispatcherHost::NavigatorConnectDispatcherHost( | |
16 const scoped_refptr<NavigatorConnectContextImpl>& navigator_connect_context, | |
17 MessagePortMessageFilter* message_port_message_filter) | |
18 : BrowserMessageFilter(NavigatorConnectMsgStart), | |
19 navigator_connect_context_(navigator_connect_context), | |
20 message_port_message_filter_(message_port_message_filter) { | |
21 } | |
22 | |
23 NavigatorConnectDispatcherHost::~NavigatorConnectDispatcherHost() { | |
24 } | |
25 | |
26 bool NavigatorConnectDispatcherHost::OnMessageReceived( | |
27 const IPC::Message& message) { | |
28 bool handled = true; | |
29 IPC_BEGIN_MESSAGE_MAP(NavigatorConnectDispatcherHost, message) | |
30 IPC_MESSAGE_HANDLER(NavigatorConnectHostMsg_Connect, OnConnect) | |
31 IPC_MESSAGE_UNHANDLED(handled = false) | |
32 IPC_END_MESSAGE_MAP() | |
33 return handled; | |
34 } | |
35 | |
36 void NavigatorConnectDispatcherHost::OnConnect( | |
37 int thread_id, | |
38 int request_id, | |
39 const NavigatorConnectClient& client) { | |
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
41 | |
42 DCHECK(client.message_port_id == MSG_ROUTING_NONE) | |
43 << "Connect request should not include a message port"; | |
44 | |
45 navigator_connect_context_->Connect( | |
46 client, message_port_message_filter_, | |
47 base::Bind(&NavigatorConnectDispatcherHost::OnConnectResult, this, | |
48 thread_id, request_id)); | |
49 } | |
50 | |
51 void NavigatorConnectDispatcherHost::OnConnectResult( | |
52 int thread_id, | |
53 int request_id, | |
54 const TransferredMessagePort& message_port, | |
55 int message_port_route_id, | |
56 bool accept_connection) { | |
57 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
58 Send(new NavigatorConnectMsg_ConnectResult( | |
59 thread_id, request_id, message_port, message_port_route_id, | |
60 accept_connection)); | |
61 } | |
62 | |
63 } // namespace content | |
OLD | NEW |