OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/session/blimp_client_session.h" | 5 #include "blimp/client/session/blimp_client_session.h" |
6 | 6 |
7 #include "blimp/client/session/navigation_feature.h" | 7 #include "blimp/client/session/navigation_feature.h" |
8 #include "blimp/client/session/render_widget_feature.h" | 8 #include "blimp/client/session/render_widget_feature.h" |
9 #include "blimp/client/session/tab_control_feature.h" | 9 #include "blimp/client/session/tab_control_feature.h" |
10 #include "blimp/net/browser_connection_handler.h" | 10 #include "blimp/net/browser_connection_handler.h" |
11 #include "blimp/net/client_connection_manager.h" | |
12 #include "blimp/net/common.h" | |
13 #include "blimp/net/null_blimp_message_processor.h" | |
14 #include "blimp/net/tcp_client_transport.h" | |
11 | 15 |
12 namespace blimp { | 16 namespace blimp { |
17 namespace { | |
18 // TODO(kmarshall): Read auth token, port, IP address from configuration. | |
19 const char kDummyClientToken[] = "MyVoiceIsMyPassport"; | |
20 const uint16_t kDefaultTcpPort = 25467; | |
21 | |
22 net::IPAddressNumber GetEndpointIPAddress() { | |
23 // Just connect to localhost for now. | |
haibinlu
2016/01/04 21:17:12
add a TODO here.
| |
24 net::IPAddressNumber output; | |
25 output.push_back(0); | |
26 output.push_back(0); | |
27 output.push_back(0); | |
28 output.push_back(0); | |
29 return output; | |
30 } | |
31 | |
32 } // namespace | |
33 | |
34 class ClientNetworkComponents { | |
35 public: | |
36 // Can be created on any thread. | |
37 ClientNetworkComponents() {} | |
38 | |
39 // Must be destroyed on the IO thread. | |
40 ~ClientNetworkComponents() {} | |
41 | |
42 // Creates instances for |browser_connection_handler_| and | |
43 // |connection_manager_|. | |
44 // Must be called on the IO thread. | |
45 void Initialize(); | |
46 | |
47 private: | |
48 scoped_ptr<BrowserConnectionHandler> browser_connection_handler_; | |
49 scoped_ptr<ClientConnectionManager> connection_manager_; | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | |
52 }; | |
53 | |
54 void ClientNetworkComponents::Initialize() { | |
55 browser_connection_handler_ = make_scoped_ptr(new BrowserConnectionHandler); | |
56 connection_manager_ = make_scoped_ptr( | |
57 new ClientConnectionManager(browser_connection_handler_.get())); | |
58 connection_manager_->set_client_token(kDummyClientToken); | |
59 | |
60 connection_manager_->AddTransport(make_scoped_ptr( | |
61 new TCPClientTransport(net::AddressList(net::IPEndPoint( | |
62 GetEndpointIPAddress(), kDefaultTcpPort)), | |
63 nullptr))); | |
64 | |
65 connection_manager_->Connect(); | |
66 } | |
13 | 67 |
14 BlimpClientSession::BlimpClientSession() | 68 BlimpClientSession::BlimpClientSession() |
15 : connection_handler_(new BrowserConnectionHandler), | 69 : io_thread_("BlimpIOThread"), |
16 tab_control_feature_(new TabControlFeature), | 70 tab_control_feature_(new TabControlFeature), |
17 navigation_feature_(new NavigationFeature), | 71 navigation_feature_(new NavigationFeature), |
18 render_widget_feature_(new RenderWidgetFeature) { | 72 render_widget_feature_(new RenderWidgetFeature), |
19 // Connect the features with the network layer. | 73 network_components_(new ClientNetworkComponents) { |
74 base::Thread::Options options; | |
75 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
76 io_thread_.StartWithOptions(options); | |
77 io_thread_.task_runner()->PostTask( | |
78 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | |
79 base::Unretained(network_components_.get()))); | |
80 | |
81 // Register features. | |
82 // TODO(haibinlu): connect the features with the network layer, with support | |
83 // for thread hopping. | |
20 tab_control_feature_->set_outgoing_message_processor( | 84 tab_control_feature_->set_outgoing_message_processor( |
21 connection_handler_->RegisterFeature(BlimpMessage::TAB_CONTROL, | 85 make_scoped_ptr(new NullBlimpMessageProcessor)); |
22 tab_control_feature_.get())); | |
23 navigation_feature_->set_outgoing_message_processor( | 86 navigation_feature_->set_outgoing_message_processor( |
24 connection_handler_->RegisterFeature(BlimpMessage::NAVIGATION, | 87 make_scoped_ptr(new NullBlimpMessageProcessor)); |
25 navigation_feature_.get())); | |
26 render_widget_feature_->set_outgoing_input_message_processor( | 88 render_widget_feature_->set_outgoing_input_message_processor( |
27 connection_handler_->RegisterFeature(BlimpMessage::INPUT, | 89 make_scoped_ptr(new NullBlimpMessageProcessor)); |
28 render_widget_feature_.get())); | |
29 render_widget_feature_->set_outgoing_compositor_message_processor( | 90 render_widget_feature_->set_outgoing_compositor_message_processor( |
30 connection_handler_->RegisterFeature(BlimpMessage::COMPOSITOR, | 91 make_scoped_ptr(new NullBlimpMessageProcessor)); |
31 render_widget_feature_.get())); | |
32 // We don't expect to send any RenderWidget messages, so don't save the | |
33 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | |
34 connection_handler_->RegisterFeature(BlimpMessage::RENDER_WIDGET, | |
35 render_widget_feature_.get()); | |
36 } | 92 } |
37 | 93 |
38 BlimpClientSession::~BlimpClientSession() {} | 94 BlimpClientSession::~BlimpClientSession() { |
95 io_thread_.task_runner()->DeleteSoon(FROM_HERE, | |
96 network_components_.release()); | |
97 } | |
39 | 98 |
40 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 99 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
41 return tab_control_feature_.get(); | 100 return tab_control_feature_.get(); |
42 } | 101 } |
43 | 102 |
44 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 103 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
45 return navigation_feature_.get(); | 104 return navigation_feature_.get(); |
46 } | 105 } |
47 | 106 |
48 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 107 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
49 return render_widget_feature_.get(); | 108 return render_widget_feature_.get(); |
50 } | 109 } |
51 | 110 |
52 } // namespace blimp | 111 } // namespace blimp |
OLD | NEW |