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 ClientImageSerializationProcessor::GetInstance()->set_blob_receiver( | |
210 blob_receiver_.get()); | |
211 ClientImageSerializationProcessor::GetInstance()->set_error_delegate(this); | |
212 | |
194 // Initialize must only be posted after the RegisterFeature calls have | 213 // Initialize must only be posted after the RegisterFeature calls have |
195 // completed. | 214 // completed. |
196 io_thread_.task_runner()->PostTask( | 215 io_thread_.task_runner()->PostTask( |
197 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 216 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
198 base::Unretained(net_components_.get()))); | 217 base::Unretained(net_components_.get()))); |
199 } | 218 } |
200 | 219 |
201 BlimpClientSession::~BlimpClientSession() { | 220 BlimpClientSession::~BlimpClientSession() { |
202 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); | 221 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
203 } | 222 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 navigation_feature_.get())); | 263 navigation_feature_.get())); |
245 render_widget_feature_->set_outgoing_input_message_processor( | 264 render_widget_feature_->set_outgoing_input_message_processor( |
246 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, | 265 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, |
247 render_widget_feature_.get())); | 266 render_widget_feature_.get())); |
248 render_widget_feature_->set_outgoing_compositor_message_processor( | 267 render_widget_feature_->set_outgoing_compositor_message_processor( |
249 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, | 268 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, |
250 render_widget_feature_.get())); | 269 render_widget_feature_.get())); |
251 settings_feature_->set_outgoing_message_processor( | 270 settings_feature_->set_outgoing_message_processor( |
252 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 271 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
253 settings_feature_.get())); | 272 settings_feature_.get())); |
273 thread_pipe_manager_->RegisterFeature(BlimpMessage::kBlobChannel, | |
274 blob_delegate_); | |
254 | 275 |
255 // 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 |
256 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 277 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
257 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 278 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
258 render_widget_feature_.get()); | 279 render_widget_feature_.get()); |
259 | 280 |
260 ime_feature_->set_outgoing_message_processor( | 281 ime_feature_->set_outgoing_message_processor( |
261 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 282 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
262 ime_feature_.get())); | 283 ime_feature_.get())); |
263 | 284 |
264 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 285 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
265 switches::kDownloadWholeDocument)) | 286 switches::kDownloadWholeDocument)) |
266 settings_feature_->SetRecordWholeDocument(true); | 287 settings_feature_->SetRecordWholeDocument(true); |
267 } | 288 } |
268 | 289 |
269 void BlimpClientSession::OnConnected() {} | 290 void BlimpClientSession::OnConnected() {} |
270 | 291 |
271 void BlimpClientSession::OnDisconnected(int result) {} | 292 void BlimpClientSession::OnDisconnected(int result) {} |
272 | 293 |
294 void BlimpClientSession::OnImageDecodeError() { | |
295 io_thread_.task_runner()->PostTask( | |
296 FROM_HERE, base::Bind(&ClientNetworkComponents::DropCurrentConnection, | |
297 base::Unretained(net_components_.get()))); | |
Wez
2016/06/07 01:18:31
DropCurrentConnection() is expected to be called a
Kevin M
2016/06/08 00:21:09
I made BrowserConnectionHandler::DropCurrentConnec
Wez
2016/06/10 22:29:54
Acknowledged.
| |
298 } | |
299 | |
273 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 300 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
274 return tab_control_feature_.get(); | 301 return tab_control_feature_.get(); |
275 } | 302 } |
276 | 303 |
277 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 304 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
278 return navigation_feature_.get(); | 305 return navigation_feature_.get(); |
279 } | 306 } |
280 | 307 |
281 ImeFeature* BlimpClientSession::GetImeFeature() const { | 308 ImeFeature* BlimpClientSession::GetImeFeature() const { |
282 return ime_feature_.get(); | 309 return ime_feature_.get(); |
283 } | 310 } |
284 | 311 |
285 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 312 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
286 return render_widget_feature_.get(); | 313 return render_widget_feature_.get(); |
287 } | 314 } |
288 | 315 |
289 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 316 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
290 return settings_feature_.get(); | 317 return settings_feature_.get(); |
291 } | 318 } |
292 | 319 |
293 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() | 320 BlimpConnectionStatistics* BlimpClientSession::GetBlimpConnectionStatistics() |
294 const { | 321 const { |
295 return blimp_connection_statistics_; | 322 return blimp_connection_statistics_; |
296 } | 323 } |
297 | 324 |
298 } // namespace client | 325 } // namespace client |
299 } // namespace blimp | 326 } // namespace blimp |
OLD | NEW |