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 <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 VLOG(1) << "Connection error: " << net::ErrorToString(result); | 173 VLOG(1) << "Connection error: " << net::ErrorToString(result); |
| 165 network_observer_->OnDisconnected(result); | 174 network_observer_->OnDisconnected(result); |
| 166 } | 175 } |
| 167 | 176 |
| 168 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 177 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
| 169 : io_thread_("BlimpIOThread"), | 178 : io_thread_("BlimpIOThread"), |
| 179 blob_delegate_(new HeliumBlobReceiverDelegate), | |
| 180 blob_receiver_( | |
| 181 BlobChannelReceiver::Create(base::WrapUnique(new InMemoryBlobCache), | |
| 182 base::WrapUnique(blob_delegate_))), | |
| 170 tab_control_feature_(new TabControlFeature), | 183 tab_control_feature_(new TabControlFeature), |
| 171 navigation_feature_(new NavigationFeature), | 184 navigation_feature_(new NavigationFeature), |
| 172 ime_feature_(new ImeFeature), | 185 ime_feature_(new ImeFeature), |
| 173 render_widget_feature_(new RenderWidgetFeature), | 186 render_widget_feature_(new RenderWidgetFeature), |
| 174 settings_feature_(new SettingsFeature), | 187 settings_feature_(new SettingsFeature), |
| 175 weak_factory_(this) { | 188 weak_factory_(this) { |
| 176 base::Thread::Options options; | 189 base::Thread::Options options; |
| 177 options.message_loop_type = base::MessageLoop::TYPE_IO; | 190 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 178 io_thread_.StartWithOptions(options); | 191 io_thread_.StartWithOptions(options); |
| 179 blimp_connection_statistics_ = new BlimpConnectionStatistics(); | 192 blimp_connection_statistics_ = new BlimpConnectionStatistics(); |
| 180 net_components_.reset(new ClientNetworkComponents( | 193 net_components_.reset(new ClientNetworkComponents( |
| 181 base::WrapUnique(new CrossThreadNetworkEventObserver( | 194 base::WrapUnique(new CrossThreadNetworkEventObserver( |
| 182 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | 195 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), |
| 183 base::WrapUnique(blimp_connection_statistics_))); | 196 base::WrapUnique(blimp_connection_statistics_))); |
| 184 | 197 |
| 185 assignment_source_.reset(new AssignmentSource( | 198 assignment_source_.reset(new AssignmentSource( |
| 186 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 199 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
| 187 | 200 |
| 201 std::unique_ptr<HeliumBlobReceiverDelegate> blob_delegate( | |
|
nyquist
2016/06/03 18:30:44
You seem to do these operations in the constructor
Kevin M
2016/06/06 17:43:38
Uh, whoops.
Done.
| |
| 202 new HeliumBlobReceiverDelegate); | |
| 203 blob_delegate_ = blob_delegate.get(); | |
| 204 blob_receiver_ = BlobChannelReceiver::Create( | |
| 205 base::WrapUnique(new InMemoryBlobCache), std::move(blob_delegate)); | |
| 206 | |
| 188 RegisterFeatures(); | 207 RegisterFeatures(); |
| 189 | 208 |
| 209 ClientImageSerializationProcessor::GetInstance()->set_blob_receiver( | |
| 210 blob_receiver_.get()); | |
| 211 ClientImageSerializationProcessor::GetInstance()->set_error_delegate(this); | |
| 212 | |
| 190 // Initialize must only be posted after the RegisterFeature calls have | 213 // Initialize must only be posted after the RegisterFeature calls have |
| 191 // completed. | 214 // completed. |
| 192 io_thread_.task_runner()->PostTask( | 215 io_thread_.task_runner()->PostTask( |
| 193 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 216 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 194 base::Unretained(net_components_.get()))); | 217 base::Unretained(net_components_.get()))); |
| 195 } | 218 } |
| 196 | 219 |
| 197 BlimpClientSession::~BlimpClientSession() { | 220 BlimpClientSession::~BlimpClientSession() { |
| 198 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); | 221 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
| 199 } | 222 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 navigation_feature_.get())); | 263 navigation_feature_.get())); |
| 241 render_widget_feature_->set_outgoing_input_message_processor( | 264 render_widget_feature_->set_outgoing_input_message_processor( |
| 242 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, | 265 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, |
| 243 render_widget_feature_.get())); | 266 render_widget_feature_.get())); |
| 244 render_widget_feature_->set_outgoing_compositor_message_processor( | 267 render_widget_feature_->set_outgoing_compositor_message_processor( |
| 245 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, | 268 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, |
| 246 render_widget_feature_.get())); | 269 render_widget_feature_.get())); |
| 247 settings_feature_->set_outgoing_message_processor( | 270 settings_feature_->set_outgoing_message_processor( |
| 248 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 271 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 249 settings_feature_.get())); | 272 settings_feature_.get())); |
| 273 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, | |
| 274 blob_delegate_); | |
| 250 | 275 |
| 251 // Client will not send send any RenderWidget messages, so don't save the | 276 // Client will not send send any RenderWidget messages, so don't save the |
| 252 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 277 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
| 253 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 278 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 254 render_widget_feature_.get()); | 279 render_widget_feature_.get()); |
| 255 | 280 |
| 256 ime_feature_->set_outgoing_message_processor( | 281 ime_feature_->set_outgoing_message_processor( |
| 257 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 282 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
| 258 ime_feature_.get())); | 283 ime_feature_.get())); |
| 259 | 284 |
| 260 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 285 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 261 switches::kDownloadWholeDocument)) | 286 switches::kDownloadWholeDocument)) |
| 262 settings_feature_->SetRecordWholeDocument(true); | 287 settings_feature_->SetRecordWholeDocument(true); |
| 263 } | 288 } |
| 264 | 289 |
| 265 void BlimpClientSession::OnConnected() {} | 290 void BlimpClientSession::OnConnected() {} |
| 266 | 291 |
| 267 void BlimpClientSession::OnDisconnected(int result) {} | 292 void BlimpClientSession::OnDisconnected(int result) {} |
| 268 | 293 |
| 294 void BlimpClientSession::OnImageDecodeError() { | |
| 295 io_thread_.task_runner()->PostTask( | |
| 296 FROM_HERE, base::Bind(&ClientNetworkComponents::DropCurrentConnection, | |
| 297 base::Unretained(net_components_.get()))); | |
| 298 } | |
| 299 | |
| 269 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 300 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
| 270 return tab_control_feature_.get(); | 301 return tab_control_feature_.get(); |
| 271 } | 302 } |
| 272 | 303 |
| 273 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 304 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
| 274 return navigation_feature_.get(); | 305 return navigation_feature_.get(); |
| 275 } | 306 } |
| 276 | 307 |
| 277 ImeFeature* BlimpClientSession::GetImeFeature() const { | 308 ImeFeature* BlimpClientSession::GetImeFeature() const { |
| 278 return ime_feature_.get(); | 309 return ime_feature_.get(); |
| 279 } | 310 } |
| 280 | 311 |
| 281 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 312 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
| 282 return render_widget_feature_.get(); | 313 return render_widget_feature_.get(); |
| 283 } | 314 } |
| 284 | 315 |
| 285 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 316 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
| 286 return settings_feature_.get(); | 317 return settings_feature_.get(); |
| 287 } | 318 } |
| 288 | 319 |
| 289 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | 320 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() |
| 290 const { | 321 const { |
| 291 return blimp_connection_statistics_; | 322 return blimp_connection_statistics_; |
| 292 } | 323 } |
| 293 | 324 |
| 294 } // namespace client | 325 } // namespace client |
| 295 } // namespace blimp | 326 } // namespace blimp |
| OLD | NEW |