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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 explicit ClientNetworkComponents( |
| 76 std::unique_ptr<NetworkEventObserver> observer); | 76 std::unique_ptr<NetworkEventObserver> observer, |
| 77 BlimpConnectionDetails* blimp_connection_details); | |
| 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 BlimpConnectionDetails* connection_details_; | |
| 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 BlimpConnectionDetails* details) | |
| 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_details_(details) {} | |
|
Khushal
2016/05/18 00:23:00
DCHECK |connection_details_| here.
shaktisahu
2016/05/19 21:39:18
Not sure if this saves much, since we invoke the c
| |
| 106 | 110 |
| 107 ClientNetworkComponents::~ClientNetworkComponents() {} | 111 ClientNetworkComponents::~ClientNetworkComponents() {} |
| 108 | 112 |
| 109 void ClientNetworkComponents::Initialize() { | 113 void ClientNetworkComponents::Initialize() { |
| 110 DCHECK(!connection_manager_); | 114 DCHECK(!connection_manager_); |
| 111 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); | 115 connection_manager_ = base::WrapUnique(new ClientConnectionManager(this)); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void ClientNetworkComponents::ConnectWithAssignment( | 118 void ClientNetworkComponents::ConnectWithAssignment( |
| 115 const Assignment& assignment) { | 119 const Assignment& assignment) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 143 BrowserConnectionHandler* | 147 BrowserConnectionHandler* |
| 144 ClientNetworkComponents::GetBrowserConnectionHandler() { | 148 ClientNetworkComponents::GetBrowserConnectionHandler() { |
| 145 return connection_handler_.get(); | 149 return connection_handler_.get(); |
| 146 } | 150 } |
| 147 | 151 |
| 148 void ClientNetworkComponents::HandleConnection( | 152 void ClientNetworkComponents::HandleConnection( |
| 149 std::unique_ptr<BlimpConnection> connection) { | 153 std::unique_ptr<BlimpConnection> connection) { |
| 150 VLOG(1) << "Connection established."; | 154 VLOG(1) << "Connection established."; |
| 151 connection->AddConnectionErrorObserver(this); | 155 connection->AddConnectionErrorObserver(this); |
| 152 network_observer_->OnConnected(); | 156 network_observer_->OnConnected(); |
| 157 connection->SetBlimpConnectionDetails(connection_details_); | |
| 153 connection_handler_->HandleConnection(std::move(connection)); | 158 connection_handler_->HandleConnection(std::move(connection)); |
| 154 } | 159 } |
| 155 | 160 |
| 156 void ClientNetworkComponents::OnConnectionError(int result) { | 161 void ClientNetworkComponents::OnConnectionError(int result) { |
| 157 VLOG(1) << "Connection error: " << net::ErrorToString(result); | 162 VLOG(1) << "Connection error: " << net::ErrorToString(result); |
| 158 network_observer_->OnDisconnected(result); | 163 network_observer_->OnDisconnected(result); |
| 159 } | 164 } |
| 160 | 165 |
| 161 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) | 166 BlimpClientSession::BlimpClientSession(const GURL& assigner_endpoint) |
| 162 : io_thread_("BlimpIOThread"), | 167 : io_thread_("BlimpIOThread"), |
| 163 tab_control_feature_(new TabControlFeature), | 168 tab_control_feature_(new TabControlFeature), |
| 164 navigation_feature_(new NavigationFeature), | |
| 165 ime_feature_(new ImeFeature), | 169 ime_feature_(new ImeFeature), |
| 166 render_widget_feature_(new RenderWidgetFeature), | 170 render_widget_feature_(new RenderWidgetFeature), |
| 167 settings_feature_(new SettingsFeature), | 171 settings_feature_(new SettingsFeature), |
| 168 weak_factory_(this) { | 172 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; | 173 base::Thread::Options options; |
| 174 options.message_loop_type = base::MessageLoop::TYPE_IO; | 174 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 175 io_thread_.StartWithOptions(options); | 175 io_thread_.StartWithOptions(options); |
| 176 blimp_connection_details_ = base::WrapUnique(new BlimpConnectionDetails( | |
|
Khushal
2016/05/18 00:23:00
nit: Use x_.reset(new ...) for member variables of
shaktisahu
2016/05/19 21:39:18
Done.
| |
| 177 base::SequencedTaskRunnerHandle::Get(), io_thread_.task_runner())); | |
| 178 blimp_connection_details_->SetObserver(weak_factory_.GetWeakPtr()); | |
| 179 navigation_feature_ = | |
| 180 base::WrapUnique(new NavigationFeature(blimp_connection_details_.get())); | |
| 181 net_components_.reset(new ClientNetworkComponents( | |
| 182 base::WrapUnique(new CrossThreadNetworkEventObserver( | |
| 183 weak_factory_.GetWeakPtr(), base::SequencedTaskRunnerHandle::Get())), | |
| 184 blimp_connection_details_.get())); | |
| 176 | 185 |
| 177 assignment_source_.reset(new AssignmentSource( | 186 assignment_source_.reset(new AssignmentSource( |
| 178 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); | 187 assigner_endpoint, io_thread_.task_runner(), io_thread_.task_runner())); |
| 179 | 188 |
| 180 RegisterFeatures(); | 189 RegisterFeatures(); |
| 181 | 190 |
| 182 // Initialize must only be posted after the RegisterFeature calls have | 191 // Initialize must only be posted after the RegisterFeature calls have |
| 183 // completed. | 192 // completed. |
| 184 io_thread_.task_runner()->PostTask( | 193 io_thread_.task_runner()->PostTask( |
| 185 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, | 194 FROM_HERE, base::Bind(&ClientNetworkComponents::Initialize, |
| 186 base::Unretained(net_components_.get()))); | 195 base::Unretained(net_components_.get()))); |
| 187 } | 196 } |
| 188 | 197 |
| 189 BlimpClientSession::~BlimpClientSession() { | 198 BlimpClientSession::~BlimpClientSession() { |
| 190 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); | 199 io_thread_.task_runner()->DeleteSoon(FROM_HERE, net_components_.release()); |
| 200 io_thread_.task_runner()->DeleteSoon(FROM_HERE, | |
| 201 blimp_connection_details_.release()); | |
| 191 } | 202 } |
| 192 | 203 |
| 193 void BlimpClientSession::Connect(const std::string& client_auth_token) { | 204 void BlimpClientSession::Connect(const std::string& client_auth_token) { |
| 194 assignment_source_->GetAssignment( | 205 assignment_source_->GetAssignment( |
| 195 client_auth_token, base::Bind(&BlimpClientSession::ConnectWithAssignment, | 206 client_auth_token, base::Bind(&BlimpClientSession::ConnectWithAssignment, |
| 196 weak_factory_.GetWeakPtr())); | 207 weak_factory_.GetWeakPtr())); |
| 197 } | 208 } |
| 198 | 209 |
| 199 void BlimpClientSession::ConnectWithAssignment(AssignmentSource::Result result, | 210 void BlimpClientSession::ConnectWithAssignment(AssignmentSource::Result result, |
| 200 const Assignment& assignment) { | 211 const Assignment& assignment) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 // Client will not send send any RenderWidget messages, so don't save the | 255 // Client will not send send any RenderWidget messages, so don't save the |
| 245 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. | 256 // outgoing BlimpMessageProcessor in the RenderWidgetFeature. |
| 246 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, | 257 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, |
| 247 render_widget_feature_.get()); | 258 render_widget_feature_.get()); |
| 248 | 259 |
| 249 ime_feature_->set_outgoing_message_processor( | 260 ime_feature_->set_outgoing_message_processor( |
| 250 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, | 261 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, |
| 251 ime_feature_.get())); | 262 ime_feature_.get())); |
| 252 } | 263 } |
| 253 | 264 |
| 265 void BlimpClientSession::EnableDebugInfo(bool enable) { | |
| 266 blimp_connection_details_->EnableDebugInfo(enable); | |
| 267 } | |
| 268 | |
| 269 void BlimpClientSession::UpdateDebugInfo(int received, int sent, int commits) {} | |
| 270 | |
| 254 void BlimpClientSession::OnConnected() {} | 271 void BlimpClientSession::OnConnected() {} |
| 255 | 272 |
| 256 void BlimpClientSession::OnDisconnected(int result) {} | 273 void BlimpClientSession::OnDisconnected(int result) {} |
| 257 | 274 |
| 258 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { | 275 TabControlFeature* BlimpClientSession::GetTabControlFeature() const { |
| 259 return tab_control_feature_.get(); | 276 return tab_control_feature_.get(); |
| 260 } | 277 } |
| 261 | 278 |
| 262 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { | 279 NavigationFeature* BlimpClientSession::GetNavigationFeature() const { |
| 263 return navigation_feature_.get(); | 280 return navigation_feature_.get(); |
| 264 } | 281 } |
| 265 | 282 |
| 266 ImeFeature* BlimpClientSession::GetImeFeature() const { | 283 ImeFeature* BlimpClientSession::GetImeFeature() const { |
| 267 return ime_feature_.get(); | 284 return ime_feature_.get(); |
| 268 } | 285 } |
| 269 | 286 |
| 270 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { | 287 RenderWidgetFeature* BlimpClientSession::GetRenderWidgetFeature() const { |
| 271 return render_widget_feature_.get(); | 288 return render_widget_feature_.get(); |
| 272 } | 289 } |
| 273 | 290 |
| 274 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { | 291 SettingsFeature* BlimpClientSession::GetSettingsFeature() const { |
| 275 return settings_feature_.get(); | 292 return settings_feature_.get(); |
| 276 } | 293 } |
| 277 | 294 |
| 295 BlimpConnectionDetails* BlimpClientSession::GetBlimpConnectionDetails() const { | |
| 296 return blimp_connection_details_.get(); | |
| 297 } | |
| 298 | |
| 278 } // namespace client | 299 } // namespace client |
| 279 } // namespace blimp | 300 } // namespace blimp |
| OLD | NEW |