| 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" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/threading/sequenced_task_runner_handle.h" | 13 #include "base/threading/sequenced_task_runner_handle.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "blimp/client/app/blimp_client_switches.h" | 15 #include "blimp/client/app/blimp_client_switches.h" |
| 16 #include "blimp/client/feature/ime_feature.h" | 16 #include "blimp/client/feature/ime_feature.h" |
| 17 #include "blimp/client/feature/navigation_feature.h" | 17 #include "blimp/client/feature/navigation_feature.h" |
| 18 #include "blimp/client/feature/render_widget_feature.h" | 18 #include "blimp/client/feature/render_widget_feature.h" |
| 19 #include "blimp/client/feature/settings_feature.h" | 19 #include "blimp/client/feature/settings_feature.h" |
| 20 #include "blimp/client/feature/tab_control_feature.h" | 20 #include "blimp/client/feature/tab_control_feature.h" |
| 21 #include "blimp/common/blob_cache/in_memory_blob_cache.h" |
| 21 #include "blimp/net/blimp_connection.h" | 22 #include "blimp/net/blimp_connection.h" |
| 22 #include "blimp/net/blimp_message_processor.h" | 23 #include "blimp/net/blimp_message_processor.h" |
| 23 #include "blimp/net/blimp_message_thread_pipe.h" | 24 #include "blimp/net/blimp_message_thread_pipe.h" |
| 25 #include "blimp/net/blob_channel/blob_channel_receiver.h" |
| 26 #include "blimp/net/blob_channel/helium_blob_receiver_delegate.h" |
| 24 #include "blimp/net/browser_connection_handler.h" | 27 #include "blimp/net/browser_connection_handler.h" |
| 25 #include "blimp/net/client_connection_manager.h" | 28 #include "blimp/net/client_connection_manager.h" |
| 26 #include "blimp/net/common.h" | 29 #include "blimp/net/common.h" |
| 27 #include "blimp/net/connection_handler.h" | 30 #include "blimp/net/connection_handler.h" |
| 28 #include "blimp/net/null_blimp_message_processor.h" | 31 #include "blimp/net/null_blimp_message_processor.h" |
| 29 #include "blimp/net/ssl_client_transport.h" | 32 #include "blimp/net/ssl_client_transport.h" |
| 30 #include "blimp/net/tcp_client_transport.h" | 33 #include "blimp/net/tcp_client_transport.h" |
| 31 #include "blimp/net/thread_pipe_manager.h" | 34 #include "blimp/net/thread_pipe_manager.h" |
| 32 #include "net/base/address_list.h" | 35 #include "net/base/address_list.h" |
| 33 #include "net/base/ip_address.h" | 36 #include "net/base/ip_address.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 82 |
| 80 // Sets up network components. | 83 // Sets up network components. |
| 81 void Initialize(); | 84 void Initialize(); |
| 82 | 85 |
| 83 // Starts the connection to the engine using the given |assignment|. | 86 // Starts the connection to the engine using the given |assignment|. |
| 84 // It is required to first call Initialize. | 87 // It is required to first call Initialize. |
| 85 void ConnectWithAssignment(const Assignment& assignment); | 88 void ConnectWithAssignment(const Assignment& assignment); |
| 86 | 89 |
| 87 BrowserConnectionHandler* GetBrowserConnectionHandler(); | 90 BrowserConnectionHandler* GetBrowserConnectionHandler(); |
| 88 | 91 |
| 92 void DropCurrentConnection(); |
| 93 |
| 89 private: | 94 private: |
| 90 // ConnectionHandler implementation. | 95 // ConnectionHandler implementation. |
| 91 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; | 96 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; |
| 92 | 97 |
| 93 // ConnectionErrorObserver implementation. | 98 // ConnectionErrorObserver implementation. |
| 94 void OnConnectionError(int error) override; | 99 void OnConnectionError(int error) override; |
| 95 | 100 |
| 96 std::unique_ptr<BrowserConnectionHandler> connection_handler_; | 101 std::unique_ptr<BrowserConnectionHandler> connection_handler_; |
| 97 std::unique_ptr<ClientConnectionManager> connection_manager_; | 102 std::unique_ptr<ClientConnectionManager> connection_manager_; |
| 98 std::unique_ptr<NetworkEventObserver> network_observer_; | 103 std::unique_ptr<NetworkEventObserver> network_observer_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 << transport_type << ")"; | 150 << transport_type << ")"; |
| 146 | 151 |
| 147 connection_manager_->Connect(); | 152 connection_manager_->Connect(); |
| 148 } | 153 } |
| 149 | 154 |
| 150 BrowserConnectionHandler* | 155 BrowserConnectionHandler* |
| 151 ClientNetworkComponents::GetBrowserConnectionHandler() { | 156 ClientNetworkComponents::GetBrowserConnectionHandler() { |
| 152 return connection_handler_.get(); | 157 return connection_handler_.get(); |
| 153 } | 158 } |
| 154 | 159 |
| 160 void ClientNetworkComponents::DropCurrentConnection() { |
| 161 connection_handler_->DropCurrentConnection(); |
| 162 } |
| 163 |
| 155 void ClientNetworkComponents::HandleConnection( | 164 void ClientNetworkComponents::HandleConnection( |
| 156 std::unique_ptr<BlimpConnection> connection) { | 165 std::unique_ptr<BlimpConnection> connection) { |
| 157 VLOG(1) << "Connection established."; | 166 VLOG(1) << "Connection established."; |
| 158 connection->AddConnectionErrorObserver(this); | 167 connection->AddConnectionErrorObserver(this); |
| 159 network_observer_->OnConnected(); | 168 network_observer_->OnConnected(); |
| 160 connection_handler_->HandleConnection(std::move(connection)); | 169 connection_handler_->HandleConnection(std::move(connection)); |
| 161 } | 170 } |
| 162 | 171 |
| 163 void ClientNetworkComponents::OnConnectionError(int result) { | 172 void ClientNetworkComponents::OnConnectionError(int result) { |
| 164 if (result >= 0) { | 173 if (result >= 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 182 io_thread_.StartWithOptions(options); | 191 io_thread_.StartWithOptions(options); |
| 183 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | 192 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 184 net_components_.reset(new ClientNetworkComponents( | 193 net_components_.reset(new ClientNetworkComponents( |
| 185 base::WrapUnique(new CrossThreadNetworkEventObserver( | 194 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 186 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | 195 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), |
| 187 base::WrapUnique(blimp_connection_statistics_))); | 196 base::WrapUnique(blimp_connection_statistics_))); |
| 188 | 197 |
| 189 assignment_source_.reset(new AssignmentSource( | 198 assignment_source_.reset(new AssignmentSource( |
| 190 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 199 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
| 191 | 200 |
| 201 std::unique_ptr<HeliumBlobReceiverDelegate> blob_delegate( |
| 202 new HeliumBlobReceiverDelegate); |
| 203 blob_delegate_ = blob_delegate.get(); |
| 204 blob_receiver_ = BlobChannelReceiver::Create( |
| 205 base::WrapUnique(new InMemoryBlobCache), std::move(blob_delegate)); |
| 206 |
| 192 RegisterFeatures(); | 207 RegisterFeatures(); |
| 193 | 208 |
| 209 blob_image_processor_.set_blob_receiver(blob_receiver_.get()); |
| 210 blob_image_processor_.set_error_delegate(this); |
| 211 |
| 194 // Initialize must only be posted after the RegisterFeature calls have | 212 // Initialize must only be posted after the RegisterFeature calls have |
| 195 // completed. | 213 // completed. |
| 196 io_thread_.task_runner()->PostTask( | 214 io_thread_.task_runner()->PostTask( |
| 197 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 215 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 198 base::Unretained(net_components_.get()))); | 216 base::Unretained(net_components_.get()))); |
| 199 } | 217 } |
| 200 | 218 |
| 201 BlimpClientSession::~BlimpClientSession() { | 219 BlimpClientSession::~BlimpClientSession() { |
| 202 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); | 220 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
| 203 } | 221 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 navigation_feature_.get())); | 262 navigation_feature_.get())); |
| 245 render_widget_feature_->set_outgoing_input_message_processor( | 263 render_widget_feature_->set_outgoing_input_message_processor( |
| 246 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, | 264 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, |
| 247 render_widget_feature_.get())); | 265 render_widget_feature_.get())); |
| 248 render_widget_feature_->set_outgoing_compositor_message_processor( | 266 render_widget_feature_->set_outgoing_compositor_message_processor( |
| 249 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, | 267 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, |
| 250 render_widget_feature_.get())); | 268 render_widget_feature_.get())); |
| 251 settings_feature_->set_outgoing_message_processor( | 269 settings_feature_->set_outgoing_message_processor( |
| 252 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 270 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 253 settings_feature_.get())); | 271 settings_feature_.get())); |
| 272 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, |
| 273 blob_delegate_); |
| 254 | 274 |
| 255 // Client will not send send any RenderWidget messages, so don't save the | 275 // Client will not send send any RenderWidget messages, so don't save the |
| 256 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 276 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
| 257 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 277 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 258 render_widget_feature_.get()); | 278 render_widget_feature_.get()); |
| 259 | 279 |
| 260 ime_feature_->set_outgoing_message_processor( | 280 ime_feature_->set_outgoing_message_processor( |
| 261 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 281 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
| 262 ime_feature_.get())); | 282 ime_feature_.get())); |
| 263 | 283 |
| 264 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 284 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 265 switches::kDownloadWholeDocument)) | 285 switches::kDownloadWholeDocument)) |
| 266 settings_feature_->SetRecordWholeDocument(true); | 286 settings_feature_->SetRecordWholeDocument(true); |
| 267 } | 287 } |
| 268 | 288 |
| 269 void BlimpClientSession::OnConnected() {} | 289 void BlimpClientSession::OnConnected() {} |
| 270 | 290 |
| 271 void BlimpClientSession::OnDisconnected(int result) {} | 291 void BlimpClientSession::OnDisconnected(int result) {} |
| 272 | 292 |
| 293 void BlimpClientSession::OnImageDecodeError() { |
| 294 io_thread_.task_runner()->PostTask( |
| 295 FROM_HERE, base::Bind(&ClientNetworkComponents::DropCurrentConnection, |
| 296 base::Unretained(net_components_.get()))); |
| 297 } |
| 298 |
| 273 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 299 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
| 274 return tab_control_feature_.get(); | 300 return tab_control_feature_.get(); |
| 275 } | 301 } |
| 276 | 302 |
| 277 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 303 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
| 278 return navigation_feature_.get(); | 304 return navigation_feature_.get(); |
| 279 } | 305 } |
| 280 | 306 |
| 281 ImeFeature* BlimpClientSession::GetImeFeature() const { | 307 ImeFeature* BlimpClientSession::GetImeFeature() const { |
| 282 return ime_feature_.get(); | 308 return ime_feature_.get(); |
| 283 } | 309 } |
| 284 | 310 |
| 285 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 311 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
| 286 return render_widget_feature_.get(); | 312 return render_widget_feature_.get(); |
| 287 } | 313 } |
| 288 | 314 |
| 289 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 315 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
| 290 return settings_feature_.get(); | 316 return settings_feature_.get(); |
| 291 } | 317 } |
| 292 | 318 |
| 293 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | 319 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() |
| 294 const { | 320 const { |
| 295 return blimp_connection_statistics_; | 321 return blimp_connection_statistics_; |
| 296 } | 322 } |
| 297 | 323 |
| 298 } // namespace client | 324 } // namespace client |
| 299 } // namespace blimp | 325 } // namespace blimp |
| OLD | NEW |