| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 // This class's functions and destruction are all invoked on the IO thread by | 69 // This class's functions and destruction are all invoked on the IO thread by |
| 70 // the BlimpClientSession. | 70 // the BlimpClientSession. |
| 71 class ClientNetworkComponents : public ConnectionHandler, | 71 class ClientNetworkComponents : public ConnectionHandler, |
| 72 public ConnectionErrorObserver { | 72 public ConnectionErrorObserver { |
| 73 public: | 73 public: |
| 74 // Can be created on any thread. | 74 // Can be created on any thread. |
| 75 explicit ClientNetworkComponents( | 75 ClientNetworkComponents( |
| 76 std::unique_ptr<NetworkEventObserver> observer); | 76 std::unique_ptr<NetworkEventObserver> observer, |
| 77 std::unique_ptr<BlimpConnectionStatistics> blimp_connection_statistics); |
| 77 ~ClientNetworkComponents() override; | 78 ~ClientNetworkComponents() override; |
| 78 | 79 |
| 79 // Sets up network components. | 80 // Sets up network components. |
| 80 void Initialize(); | 81 void Initialize(); |
| 81 | 82 |
| 82 // Starts the connection to the engine using the given |assignment|. | 83 // Starts the connection to the engine using the given |assignment|. |
| 83 // It is required to first call Initialize. | 84 // It is required to first call Initialize. |
| 84 void ConnectWithAssignment(const Assignment& assignment); | 85 void ConnectWithAssignment(const Assignment& assignment); |
| 85 | 86 |
| 86 BrowserConnectionHandler* GetBrowserConnectionHandler(); | 87 BrowserConnectionHandler* GetBrowserConnectionHandler(); |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 // ConnectionHandler implementation. | 90 // ConnectionHandler implementation. |
| 90 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; | 91 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; |
| 91 | 92 |
| 92 // ConnectionErrorObserver implementation. | 93 // ConnectionErrorObserver implementation. |
| 93 void OnConnectionError(int error) override; | 94 void OnConnectionError(int error) override; |
| 94 | 95 |
| 95 std::unique_ptr<BrowserConnectionHandler> connection_handler_; | 96 std::unique_ptr<BrowserConnectionHandler> connection_handler_; |
| 96 std::unique_ptr<ClientConnectionManager> connection_manager_; | 97 std::unique_ptr<ClientConnectionManager> connection_manager_; |
| 97 std::unique_ptr<NetworkEventObserver> network_observer_; | 98 std::unique_ptr<NetworkEventObserver> network_observer_; |
| 99 std::unique_ptr<BlimpConnectionStatistics> connection_statistics_; |
| 98 | 100 |
| 99 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); | 101 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 ClientNetworkComponents::ClientNetworkComponents( | 104 ClientNetworkComponents::ClientNetworkComponents( |
| 103 std::unique_ptr<NetworkEventObserver> network_observer) | 105 std::unique_ptr<NetworkEventObserver> network_observer, |
| 106 std::unique_ptr<BlimpConnectionStatistics> statistics) |
| 104 : connection_handler_(new BrowserConnectionHandler), | 107 : connection_handler_(new BrowserConnectionHandler), |
| 105 network_observer_(std::move(network_observer)) {} | 108 network_observer_(std::move(network_observer)), |
| 109 connection_statistics_(std::move(statistics)) { |
| 110 DCHECK(connection_statistics_); |
| 111 } |
| 106 | 112 |
| 107 ClientNetworkComponents::~ClientNetworkComponents() {} | 113 ClientNetworkComponents::~ClientNetworkComponents() {} |
| 108 | 114 |
| 109 void ClientNetworkComponents::Initialize() { | 115 void ClientNetworkComponents::Initialize() { |
| 110 DCHECK(!connection_manager_); | 116 DCHECK(!connection_manager_); |
| 111 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); | 117 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); |
| 112 } | 118 } |
| 113 | 119 |
| 114 void ClientNetworkComponents::ConnectWithAssignment( | 120 void ClientNetworkComponents::ConnectWithAssignment( |
| 115 const Assignment& assignment) { | 121 const Assignment& assignment) { |
| 116 DCHECK(connection_manager_); | 122 DCHECK(connection_manager_); |
| 117 | 123 |
| 118 connection_manager_->set_client_token(assignment.client_token); | 124 connection_manager_->set_client_token(assignment.client_token); |
| 119 const char* transport_type = "UNKNOWN"; | 125 const char* transport_type = "UNKNOWN"; |
| 120 switch (assignment.transport_protocol) { | 126 switch (assignment.transport_protocol) { |
| 121 case Assignment::SSL: | 127 case Assignment::SSL: |
| 122 DCHECK(assignment.cert); | 128 DCHECK(assignment.cert); |
| 123 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( | 129 connection_manager_->AddTransport(base::WrapUnique(new SSLClientTransport( |
| 124 assignment.engine_endpoint, std::move(assignment.cert), nullptr))); | 130 assignment.engine_endpoint, std::move(assignment.cert), |
| 131 connection_statistics_.get(), nullptr))); |
| 125 transport_type = "SSL"; | 132 transport_type = "SSL"; |
| 126 break; | 133 break; |
| 127 case Assignment::TCP: | 134 case Assignment::TCP: |
| 128 connection_manager_->AddTransport(base::WrapUnique( | 135 connection_manager_->AddTransport(base::WrapUnique(new TCPClientTransport( |
| 129 new TCPClientTransport(assignment.engine_endpoint, nullptr))); | 136 assignment.engine_endpoint, connection_statistics_.get(), nullptr))); |
| 130 transport_type = "TCP"; | 137 transport_type = "TCP"; |
| 131 break; | 138 break; |
| 132 case Assignment::UNKNOWN: | 139 case Assignment::UNKNOWN: |
| 133 LOG(FATAL) << "Unknown transport type."; | 140 LOG(FATAL) << "Unknown transport type."; |
| 134 break; | 141 break; |
| 135 } | 142 } |
| 136 | 143 |
| 137 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" | 144 VLOG(1) << "Connecting to " << assignment.engine_endpoint.ToString() << " (" |
| 138 << transport_type << ")"; | 145 << transport_type << ")"; |
| 139 | 146 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 159 } | 166 } |
| 160 | 167 |
| 161 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 168 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
| 162 : io_thread_("BlimpIOThread"), | 169 : io_thread_("BlimpIOThread"), |
| 163 tab_control_feature_(new TabControlFeature), | 170 tab_control_feature_(new TabControlFeature), |
| 164 navigation_feature_(new NavigationFeature), | 171 navigation_feature_(new NavigationFeature), |
| 165 ime_feature_(new ImeFeature), | 172 ime_feature_(new ImeFeature), |
| 166 render_widget_feature_(new RenderWidgetFeature), | 173 render_widget_feature_(new RenderWidgetFeature), |
| 167 settings_feature_(new SettingsFeature), | 174 settings_feature_(new SettingsFeature), |
| 168 weak_factory_(this) { | 175 weak_factory_(this) { |
| 169 net_components_.reset(new ClientNetworkComponents( | |
| 170 base::WrapUnique(new CrossThreadNetworkEventObserver( | |
| 171 weak_factory_.GetWeakPtr(), | |
| 172 base::SequencedTaskRunnerHandle::Get())))); | |
| 173 base::Thread::Options options; | 176 base::Thread::Options options; |
| 174 options.message_loop_type = base::MessageLoop::TYPE_IO; | 177 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 175 io_thread_.StartWithOptions(options); | 178 io_thread_.StartWithOptions(options); |
| 179 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 180 net_components_.reset(new ClientNetworkComponents( |
| 181 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 182 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), |
| 183 base::WrapUnique(blimp_connection_statistics_))); |
| 176 | 184 |
| 177 assignment_source_.reset(new AssignmentSource( | 185 assignment_source_.reset(new AssignmentSource( |
| 178 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 186 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
| 179 | 187 |
| 180 RegisterFeatures(); | 188 RegisterFeatures(); |
| 181 | 189 |
| 182 // Initialize must only be posted after the RegisterFeature calls have | 190 // Initialize must only be posted after the RegisterFeature calls have |
| 183 // completed. | 191 // completed. |
| 184 io_thread_.task_runner()->PostTask( | 192 io_thread_.task_runner()->PostTask( |
| 185 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 193 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 279 } |
| 272 | 280 |
| 273 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 281 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
| 274 return render_widget_feature_.get(); | 282 return render_widget_feature_.get(); |
| 275 } | 283 } |
| 276 | 284 |
| 277 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 285 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
| 278 return settings_feature_.get(); | 286 return settings_feature_.get(); |
| 279 } | 287 } |
| 280 | 288 |
| 289 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() |
| 290 const { |
| 291 return blimp_connection_statistics_; |
| 292 } |
| 293 |
| 281 } // namespace client | 294 } // namespace client |
| 282 } // namespace blimp | 295 } // namespace blimp |
| OLD | NEW |