Chromium Code Reviews| 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 token from config. | |
| 19 const char kDummyClientToken[] = "MyVoiceIsMyPassport"; | |
|
haibinlu
2016/01/04 19:45:45
empty string for now since you have TODO here?
Kevin M
2016/01/04 20:42:12
It's important to have a nonempty value so I can d
| |
| 20 } // namespace | |
| 21 | |
| 22 class ClientNetworkComponents { | |
| 23 public: | |
| 24 // Can be created on any thread. | |
| 25 ClientNetworkComponents() {} | |
| 26 | |
| 27 // Must be destroyed on the IO thread. | |
| 28 ~ClientNetworkComponents() {} | |
| 29 | |
| 30 // Creates instances for |browser_connection_handler_| and | |
| 31 // |connection_manager_|. | |
| 32 // Must be called on the IO thread. | |
| 33 void Initialize(); | |
| 34 | |
| 35 private: | |
| 36 scoped_ptr<BrowserConnectionHandler> browser_connection_handler_; | |
| 37 scoped_ptr<ClientConnectionManager> connection_manager_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | |
| 40 }; | |
| 41 | |
| 42 void ClientNetworkComponents::Initialize() { | |
| 43 browser_connection_handler_ = make_scoped_ptr(new BrowserConnectionHandler); | |
| 44 connection_manager_ = make_scoped_ptr( | |
| 45 new ClientConnectionManager(browser_connection_handler_.get())); | |
| 46 connection_manager_->set_client_token(kDummyClientToken); | |
| 47 connection_manager_->AddTransport(make_scoped_ptr(new TCPClientTransport( | |
| 48 net::AddressList(net::IPEndPoint(GetIPv4AnyAddress(), kDefaultTcpPort)), | |
| 49 nullptr))); | |
| 50 connection_manager_->Connect(); | |
| 51 } | |
| 13 | 52 |
| 14 BlimpClientSession::BlimpClientSession() | 53 BlimpClientSession::BlimpClientSession() |
| 15 : connection_handler_(new BrowserConnectionHandler), | 54 : io_thread_("BlimpIOThread"), |
| 16 tab_control_feature_(new TabControlFeature), | 55 tab_control_feature_(new TabControlFeature), |
| 17 navigation_feature_(new NavigationFeature), | 56 navigation_feature_(new NavigationFeature), |
| 18 render_widget_feature_(new RenderWidgetFeature) { | 57 render_widget_feature_(new RenderWidgetFeature), |
| 19 // Connect the features with the network layer. | 58 network_components_(new ClientNetworkComponents) { |
| 59 base::Thread::Options options; | |
| 60 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
| 61 io_thread_.StartWithOptions(options); | |
| 62 io_thread_.task_runner()->PostTask( | |
| 63 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | |
| 64 base::Unretained(network_components_.get()))); | |
| 65 | |
| 66 // Register features. | |
| 67 // TODO(haibinlu): connect the features with the network layer, with support | |
| 68 // for thread hopping. | |
| 20 tab_control_feature_->set_outgoing_message_processor( | 69 tab_control_feature_->set_outgoing_message_processor( |
| 21 connection_handler_->RegisterFeature(BlimpMessage::TAB_CONTROL, | 70 make_scoped_ptr(new NullBlimpMessageProcessor)); |
| 22 tab_control_feature_.get())); | |
| 23 navigation_feature_->set_outgoing_message_processor( | 71 navigation_feature_->set_outgoing_message_processor( |
| 24 connection_handler_->RegisterFeature(BlimpMessage::NAVIGATION, | 72 make_scoped_ptr(new NullBlimpMessageProcessor)); |
| 25 navigation_feature_.get())); | |
| 26 render_widget_feature_->set_outgoing_input_message_processor( | 73 render_widget_feature_->set_outgoing_input_message_processor( |
| 27 connection_handler_->RegisterFeature(BlimpMessage::INPUT, | 74 make_scoped_ptr(new NullBlimpMessageProcessor)); |
| 28 render_widget_feature_.get())); | |
| 29 render_widget_feature_->set_outgoing_compositor_message_processor( | 75 render_widget_feature_->set_outgoing_compositor_message_processor( |
| 30 connection_handler_->RegisterFeature(BlimpMessage::COMPOSITOR, | 76 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 } | 77 } |
| 37 | 78 |
| 38 BlimpClientSession::~BlimpClientSession() {} | 79 BlimpClientSession::~BlimpClientSession() { |
| 80 io_thread_.task_runner()->DeleteSoon(FROM_HERE, | |
| 81 network_components_.release()); | |
| 82 } | |
| 39 | 83 |
| 40 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 84 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
| 41 return tab_control_feature_.get(); | 85 return tab_control_feature_.get(); |
| 42 } | 86 } |
| 43 | 87 |
| 44 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 88 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
| 45 return navigation_feature_.get(); | 89 return navigation_feature_.get(); |
| 46 } | 90 } |
| 47 | 91 |
| 48 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 92 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
| 49 return render_widget_feature_.get(); | 93 return render_widget_feature_.get(); |
| 50 } | 94 } |
| 51 | 95 |
| 52 } // namespace blimp | 96 } // namespace blimp |
| OLD | NEW |