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