| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "remoting/host/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 8 #include "base/task.h" | 9 #include "base/task.h" |
| 9 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 10 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
| 11 #include "remoting/base/encoder.h" | 12 #include "remoting/base/encoder.h" |
| 12 #include "remoting/base/encoder_row_based.h" | 13 #include "remoting/base/encoder_row_based.h" |
| 13 #include "remoting/base/encoder_vp8.h" | 14 #include "remoting/base/encoder_vp8.h" |
| 14 #include "remoting/host/capturer.h" | 15 #include "remoting/host/capturer.h" |
| 15 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 16 #include "remoting/host/curtain.h" | 17 #include "remoting/host/curtain.h" |
| 17 #include "remoting/host/desktop_environment.h" | 18 #include "remoting/host/desktop_environment.h" |
| 18 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
| 19 #include "remoting/host/host_config.h" | 20 #include "remoting/host/host_config.h" |
| 20 #include "remoting/host/host_key_pair.h" | 21 #include "remoting/host/host_key_pair.h" |
| 21 #include "remoting/host/screen_recorder.h" | 22 #include "remoting/host/screen_recorder.h" |
| 23 #include "remoting/host/user_authenticator.h" |
| 22 #include "remoting/proto/auth.pb.h" | 24 #include "remoting/proto/auth.pb.h" |
| 23 #include "remoting/protocol/connection_to_client.h" | 25 #include "remoting/protocol/connection_to_client.h" |
| 24 #include "remoting/protocol/client_stub.h" | 26 #include "remoting/protocol/client_stub.h" |
| 25 #include "remoting/protocol/host_stub.h" | 27 #include "remoting/protocol/host_stub.h" |
| 26 #include "remoting/protocol/input_stub.h" | 28 #include "remoting/protocol/input_stub.h" |
| 27 #include "remoting/protocol/jingle_session_manager.h" | 29 #include "remoting/protocol/jingle_session_manager.h" |
| 28 #include "remoting/protocol/session_config.h" | 30 #include "remoting/protocol/session_config.h" |
| 29 | 31 |
| 30 using remoting::protocol::ConnectionToClient; | 32 using remoting::protocol::ConnectionToClient; |
| 31 using remoting::protocol::InputStub; | 33 using remoting::protocol::InputStub; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 175 } |
| 174 | 176 |
| 175 // This method is called when a client connects. | 177 // This method is called when a client connects. |
| 176 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { | 178 void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { |
| 177 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 179 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 178 } | 180 } |
| 179 | 181 |
| 180 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { | 182 void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { |
| 181 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 183 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 182 | 184 |
| 185 // Find the client session corresponding to the given connection. |
| 186 std::vector<scoped_refptr<ClientSession> >::iterator client; |
| 187 for (client = clients_.begin(); client != clients_.end(); ++client) { |
| 188 if (client->get()->connection() == connection) |
| 189 break; |
| 190 } |
| 191 if (client == clients_.end()) |
| 192 return; |
| 193 |
| 183 // Remove the connection from the session manager and stop the session. | 194 // Remove the connection from the session manager and stop the session. |
| 184 // TODO(hclam): Stop only if the last connection disconnected. | 195 // TODO(hclam): Stop only if the last connection disconnected. |
| 185 if (recorder_.get()) { | 196 if (recorder_.get()) { |
| 186 recorder_->RemoveConnection(connection); | 197 recorder_->RemoveConnection(connection); |
| 187 // The recorder only exists to serve the unique authenticated client. | 198 // The recorder only exists to serve the unique authenticated client. |
| 188 // If that client has disconnected, then we can kill the recorder. | 199 // If that client has disconnected, then we can kill the recorder. |
| 189 if (connection->client_authenticated()) { | 200 if (client->get()->authenticated()) { |
| 190 recorder_->Stop(NULL); | 201 recorder_->Stop(NULL); |
| 191 recorder_ = NULL; | 202 recorder_ = NULL; |
| 192 } | 203 } |
| 193 } | 204 } |
| 194 | 205 |
| 195 // Close the connection to connection just to be safe. | 206 // Close the connection to connection just to be safe. |
| 196 connection->Disconnect(); | 207 connection->Disconnect(); |
| 197 | 208 |
| 198 // Also remove reference to ConnectionToClient from this object. | 209 // Also remove reference to ConnectionToClient from this object. |
| 199 std::vector<scoped_refptr<ClientSession> >::iterator it; | 210 clients_.erase(client); |
| 200 for (it = clients_.begin(); it != clients_.end(); ++it) { | 211 |
| 201 if (it->get()->connection() == connection) { | |
| 202 clients_.erase(it); | |
| 203 break; | |
| 204 } | |
| 205 } | |
| 206 if (!HasAuthenticatedClients()) | 212 if (!HasAuthenticatedClients()) |
| 207 EnableCurtainMode(false); | 213 EnableCurtainMode(false); |
| 208 } | 214 } |
| 209 | 215 |
| 210 //////////////////////////////////////////////////////////////////////////// | 216 //////////////////////////////////////////////////////////////////////////// |
| 211 // protocol::ConnectionToClient::EventHandler implementations | 217 // protocol::ConnectionToClient::EventHandler implementations |
| 212 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { | 218 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { |
| 213 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); | 219 DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); |
| 214 | 220 |
| 215 // Completes the connection to the client. | 221 // Completes the connection to the client. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 session->set_config(config); | 320 session->set_config(config); |
| 315 session->set_receiver_token( | 321 session->set_receiver_token( |
| 316 GenerateHostAuthToken(session->initiator_token())); | 322 GenerateHostAuthToken(session->initiator_token())); |
| 317 | 323 |
| 318 *response = protocol::SessionManager::ACCEPT; | 324 *response = protocol::SessionManager::ACCEPT; |
| 319 | 325 |
| 320 VLOG(1) << "Client connected: " << session->jid(); | 326 VLOG(1) << "Client connected: " << session->jid(); |
| 321 | 327 |
| 322 // We accept the connection, so create a connection object. | 328 // We accept the connection, so create a connection object. |
| 323 ConnectionToClient* connection = new ConnectionToClient( | 329 ConnectionToClient* connection = new ConnectionToClient( |
| 324 context_->network_message_loop(), | 330 context_->network_message_loop(), this); |
| 325 this, | |
| 326 desktop_environment_->input_stub()); | |
| 327 | 331 |
| 328 // Create a client object. | 332 // Create a client object. |
| 329 ClientSession* client = new ClientSession(this, connection); | 333 ClientSession* client = new ClientSession( |
| 334 this, |
| 335 base::Bind(UserAuthenticator::Create), |
| 336 connection, |
| 337 desktop_environment_->input_stub()); |
| 330 connection->set_host_stub(client); | 338 connection->set_host_stub(client); |
| 339 connection->set_input_stub(client); |
| 331 | 340 |
| 332 connection->Init(session); | 341 connection->Init(session); |
| 333 | 342 |
| 334 clients_.push_back(client); | 343 clients_.push_back(client); |
| 335 } | 344 } |
| 336 | 345 |
| 337 void ChromotingHost::set_protocol_config( | 346 void ChromotingHost::set_protocol_config( |
| 338 protocol::CandidateSessionConfig* config) { | 347 protocol::CandidateSessionConfig* config) { |
| 339 DCHECK(config_.get()); | 348 DCHECK(config_.get()); |
| 340 DCHECK_EQ(state_, kInitial); | 349 DCHECK_EQ(state_, kInitial); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 370 | 379 |
| 371 std::string ChromotingHost::GenerateHostAuthToken( | 380 std::string ChromotingHost::GenerateHostAuthToken( |
| 372 const std::string& encoded_client_token) { | 381 const std::string& encoded_client_token) { |
| 373 // TODO(ajwong): Return the signature of this instead. | 382 // TODO(ajwong): Return the signature of this instead. |
| 374 return encoded_client_token; | 383 return encoded_client_token; |
| 375 } | 384 } |
| 376 | 385 |
| 377 bool ChromotingHost::HasAuthenticatedClients() const { | 386 bool ChromotingHost::HasAuthenticatedClients() const { |
| 378 std::vector<scoped_refptr<ClientSession> >::const_iterator it; | 387 std::vector<scoped_refptr<ClientSession> >::const_iterator it; |
| 379 for (it = clients_.begin(); it != clients_.end(); ++it) { | 388 for (it = clients_.begin(); it != clients_.end(); ++it) { |
| 380 if (it->get()->connection()->client_authenticated()) | 389 if (it->get()->authenticated()) |
| 381 return true; | 390 return true; |
| 382 } | 391 } |
| 383 return false; | 392 return false; |
| 384 } | 393 } |
| 385 | 394 |
| 386 void ChromotingHost::EnableCurtainMode(bool enable) { | 395 void ChromotingHost::EnableCurtainMode(bool enable) { |
| 387 // TODO(jamiewalch): This will need to be more sophisticated when we think | 396 // TODO(jamiewalch): This will need to be more sophisticated when we think |
| 388 // about proper crash recovery and daemon mode. | 397 // about proper crash recovery and daemon mode. |
| 389 if (enable == is_curtained_) | 398 if (enable == is_curtained_) |
| 390 return; | 399 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 401 &ChromotingHost::LocalLoginSucceeded, | 410 &ChromotingHost::LocalLoginSucceeded, |
| 402 connection)); | 411 connection)); |
| 403 return; | 412 return; |
| 404 } | 413 } |
| 405 | 414 |
| 406 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); | 415 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); |
| 407 status->set_success(true); | 416 status->set_success(true); |
| 408 connection->client_stub()->BeginSessionResponse( | 417 connection->client_stub()->BeginSessionResponse( |
| 409 status, new DeleteTask<protocol::LocalLoginStatus>(status)); | 418 status, new DeleteTask<protocol::LocalLoginStatus>(status)); |
| 410 | 419 |
| 411 connection->OnClientAuthenticated(); | |
| 412 | |
| 413 // Disconnect all other clients. | 420 // Disconnect all other clients. |
| 414 // Iterate over a copy of the list of clients, to avoid mutating the list | 421 // Iterate over a copy of the list of clients, to avoid mutating the list |
| 415 // while iterating over it. | 422 // while iterating over it. |
| 416 std::vector<scoped_refptr<ClientSession> > clients_copy(clients_); | 423 std::vector<scoped_refptr<ClientSession> > clients_copy(clients_); |
| 417 std::vector<scoped_refptr<ClientSession> >::const_iterator client; | 424 std::vector<scoped_refptr<ClientSession> >::const_iterator client; |
| 418 for (client = clients_copy.begin(); client != clients_copy.end(); client++) { | 425 for (client = clients_copy.begin(); client != clients_copy.end(); client++) { |
| 419 ConnectionToClient* connection_other = client->get()->connection(); | 426 ConnectionToClient* connection_other = client->get()->connection(); |
| 420 if (connection_other != connection) { | 427 if (connection_other != connection) { |
| 421 OnClientDisconnected(connection_other); | 428 OnClientDisconnected(connection_other); |
| 422 } | 429 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 452 return; | 459 return; |
| 453 } | 460 } |
| 454 | 461 |
| 455 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); | 462 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); |
| 456 status->set_success(false); | 463 status->set_success(false); |
| 457 connection->client_stub()->BeginSessionResponse( | 464 connection->client_stub()->BeginSessionResponse( |
| 458 status, new DeleteTask<protocol::LocalLoginStatus>(status)); | 465 status, new DeleteTask<protocol::LocalLoginStatus>(status)); |
| 459 } | 466 } |
| 460 | 467 |
| 461 } // namespace remoting | 468 } // namespace remoting |
| OLD | NEW |