Chromium Code Reviews| 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/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
| 13 #include "remoting/base/encoder.h" | 13 #include "remoting/base/encoder.h" |
| 14 #include "remoting/base/encoder_row_based.h" | 14 #include "remoting/base/encoder_row_based.h" |
| 15 #include "remoting/base/encoder_vp8.h" | 15 #include "remoting/base/encoder_vp8.h" |
| 16 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 17 #include "remoting/host/curtain.h" | 17 #include "remoting/host/curtain.h" |
| 18 #include "remoting/host/desktop_environment.h" | 18 #include "remoting/host/desktop_environment.h" |
| 19 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
| 20 #include "remoting/host/host_config.h" | 20 #include "remoting/host/host_config.h" |
| 21 #include "remoting/host/host_key_pair.h" | 21 #include "remoting/host/host_key_pair.h" |
| 22 #include "remoting/host/screen_recorder.h" | 22 #include "remoting/host/screen_recorder.h" |
| 23 #include "remoting/host/user_authenticator.h" | 23 #include "remoting/host/user_authenticator.h" |
| 24 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 24 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 25 #include "remoting/proto/auth.pb.h" | |
| 26 #include "remoting/protocol/connection_to_client.h" | 25 #include "remoting/protocol/connection_to_client.h" |
| 27 #include "remoting/protocol/client_stub.h" | 26 #include "remoting/protocol/client_stub.h" |
| 28 #include "remoting/protocol/host_stub.h" | 27 #include "remoting/protocol/host_stub.h" |
| 29 #include "remoting/protocol/input_stub.h" | 28 #include "remoting/protocol/input_stub.h" |
| 30 #include "remoting/protocol/jingle_session_manager.h" | 29 #include "remoting/protocol/jingle_session_manager.h" |
| 31 #include "remoting/protocol/session_config.h" | 30 #include "remoting/protocol/session_config.h" |
| 32 | 31 |
| 33 using remoting::protocol::ConnectionToClient; | 32 using remoting::protocol::ConnectionToClient; |
| 34 using remoting::protocol::InputStub; | 33 using remoting::protocol::InputStub; |
| 35 | 34 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 139 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 141 DCHECK_EQ(state_, kInitial); | 140 DCHECK_EQ(state_, kInitial); |
| 142 status_observers_.push_back(observer); | 141 status_observers_.push_back(observer); |
| 143 } | 142 } |
| 144 | 143 |
| 145 //////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////// |
| 146 // protocol::ConnectionToClient::EventHandler implementations | 145 // protocol::ConnectionToClient::EventHandler implementations |
| 147 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { | 146 void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { |
| 148 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 147 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 149 VLOG(1) << "Connection to client established."; | 148 VLOG(1) << "Connection to client established."; |
| 150 // TODO(wez): ChromotingHost shouldn't need to know about Me2Mom. | 149 context_->main_message_loop()->PostTask( |
|
Wez
2011/11/03 18:14:37
In future will we put the EKE exchange before OnCo
Sergey Ulanov
2011/11/03 19:11:55
We will have OnSessionAuthenticated() in ClientSes
| |
| 151 if (is_it2me_) { | 150 FROM_HERE, base::Bind(&ChromotingHost::ProcessPreAuthentication, this, |
|
Wez
2011/11/03 18:14:37
ProcessPreAuthentication really needs a better nam
Sergey Ulanov
2011/11/03 19:11:55
I'm going to remove it in the next CL.
| |
| 152 context_->main_message_loop()->PostTask( | |
| 153 FROM_HERE, base::Bind(&ChromotingHost::ProcessPreAuthentication, this, | |
| 154 make_scoped_refptr(connection))); | 151 make_scoped_refptr(connection))); |
| 155 } | |
| 156 } | 152 } |
| 157 | 153 |
| 158 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { | 154 void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { |
| 159 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 155 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 160 | 156 |
| 161 VLOG(1) << "Connection to client closed."; | 157 VLOG(1) << "Connection to client closed."; |
| 162 context_->main_message_loop()->PostTask( | 158 context_->main_message_loop()->PostTask( |
| 163 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, | 159 FROM_HERE, base::Bind(&ChromotingHost::OnClientDisconnected, this, |
| 164 make_scoped_refptr(connection))); | 160 make_scoped_refptr(connection))); |
| 165 } | 161 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 LOG(INFO) << "Client connected: " << session->jid(); | 293 LOG(INFO) << "Client connected: " << session->jid(); |
| 298 | 294 |
| 299 // We accept the connection, so create a connection object. | 295 // We accept the connection, so create a connection object. |
| 300 ConnectionToClient* connection = new ConnectionToClient( | 296 ConnectionToClient* connection = new ConnectionToClient( |
| 301 context_->network_message_loop(), this); | 297 context_->network_message_loop(), this); |
| 302 connection->Init(session); | 298 connection->Init(session); |
| 303 | 299 |
| 304 // Create a client object. | 300 // Create a client object. |
| 305 ClientSession* client = new ClientSession( | 301 ClientSession* client = new ClientSession( |
| 306 this, | 302 this, |
| 307 UserAuthenticator::Create(), | |
| 308 connection, | 303 connection, |
| 309 desktop_environment_->event_executor(), | 304 desktop_environment_->event_executor(), |
| 310 desktop_environment_->capturer()); | 305 desktop_environment_->capturer()); |
| 311 connection->set_host_stub(client); | 306 connection->set_host_stub(client); |
| 312 connection->set_input_stub(client); | 307 connection->set_input_stub(client); |
| 313 | 308 |
| 314 clients_.push_back(client); | 309 clients_.push_back(client); |
| 315 } | 310 } |
| 316 | 311 |
| 317 void ChromotingHost::set_protocol_config( | 312 void ChromotingHost::set_protocol_config( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 if (recorder_.get()) { | 370 if (recorder_.get()) { |
| 376 recorder_->RemoveConnection(connection); | 371 recorder_->RemoveConnection(connection); |
| 377 } | 372 } |
| 378 | 373 |
| 379 // Close the connection to client just to be safe. | 374 // Close the connection to client just to be safe. |
| 380 // TODO(garykac): This should be removed when we revisit our shutdown and | 375 // TODO(garykac): This should be removed when we revisit our shutdown and |
| 381 // disconnect code. This should only need to be done in | 376 // disconnect code. This should only need to be done in |
| 382 // ClientSession::Disconnect(). | 377 // ClientSession::Disconnect(). |
| 383 connection->Disconnect(); | 378 connection->Disconnect(); |
| 384 | 379 |
| 385 if (client->authenticated()) { | 380 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 386 for (StatusObserverList::iterator it = status_observers_.begin(); | 381 it != status_observers_.end(); ++it) { |
| 387 it != status_observers_.end(); ++it) { | 382 (*it)->OnClientDisconnected(client->client_jid()); |
| 388 (*it)->OnClientDisconnected(client->client_jid()); | |
| 389 } | |
| 390 } | 383 } |
| 391 | 384 |
| 392 if (AuthenticatedClientsCount() == 0) { | 385 if (AuthenticatedClientsCount() == 0) { |
| 393 if (recorder_.get()) { | 386 if (recorder_.get()) { |
| 394 // Stop the recorder if there are no more clients. | 387 // Stop the recorder if there are no more clients. |
| 395 StopScreenRecorder(); | 388 StopScreenRecorder(); |
| 396 } | 389 } |
| 397 | 390 |
| 398 // Disable the "curtain" if there are no more active clients. | 391 // Disable the "curtain" if there are no more active clients. |
| 399 EnableCurtainMode(false); | 392 EnableCurtainMode(false); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 void ChromotingHost::EnableCurtainMode(bool enable) { | 432 void ChromotingHost::EnableCurtainMode(bool enable) { |
| 440 // TODO(jamiewalch): This will need to be more sophisticated when we think | 433 // TODO(jamiewalch): This will need to be more sophisticated when we think |
| 441 // about proper crash recovery and daemon mode. | 434 // about proper crash recovery and daemon mode. |
| 442 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. | 435 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. |
| 443 if (is_it2me_ || enable == is_curtained_) | 436 if (is_it2me_ || enable == is_curtained_) |
| 444 return; | 437 return; |
| 445 desktop_environment_->curtain()->EnableCurtainMode(enable); | 438 desktop_environment_->curtain()->EnableCurtainMode(enable); |
| 446 is_curtained_ = enable; | 439 is_curtained_ = enable; |
| 447 } | 440 } |
| 448 | 441 |
| 449 void ChromotingHost::LocalLoginSucceeded( | 442 void ChromotingHost::OnAuthenticationComplete( |
| 450 scoped_refptr<ConnectionToClient> connection) { | 443 scoped_refptr<ConnectionToClient> connection) { |
| 451 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 444 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); |
| 452 | 445 |
| 453 context_->main_message_loop()->PostTask( | 446 context_->main_message_loop()->PostTask( |
| 454 FROM_HERE, base::Bind(&ChromotingHost::AddAuthenticatedClient, | 447 FROM_HERE, base::Bind(&ChromotingHost::AddAuthenticatedClient, |
| 455 this, connection, connection->session()->config(), | 448 this, connection, connection->session()->config(), |
| 456 connection->session()->jid())); | 449 connection->session()->jid())); |
| 457 } | 450 } |
| 458 | 451 |
| 459 void ChromotingHost::AddAuthenticatedClient( | 452 void ChromotingHost::AddAuthenticatedClient( |
| 460 scoped_refptr<ConnectionToClient> connection, | 453 scoped_refptr<ConnectionToClient> connection, |
| 461 const protocol::SessionConfig& config, | 454 const protocol::SessionConfig& config, |
| 462 const std::string& jid) { | 455 const std::string& jid) { |
| 463 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 456 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 464 | 457 |
| 465 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); | |
| 466 status->set_success(true); | |
| 467 connection->client_stub()->BeginSessionResponse( | |
| 468 status, base::Bind(&DeletePointer<protocol::LocalLoginStatus>, status)); | |
| 469 | |
| 470 // Disconnect all other clients. | 458 // Disconnect all other clients. |
| 471 // Iterate over a copy of the list of clients, to avoid mutating the list | 459 // Iterate over a copy of the list of clients, to avoid mutating the list |
| 472 // while iterating over it. | 460 // while iterating over it. |
| 473 ClientList clients_copy(clients_); | 461 ClientList clients_copy(clients_); |
| 474 for (ClientList::const_iterator client = clients_copy.begin(); | 462 for (ClientList::const_iterator client = clients_copy.begin(); |
| 475 client != clients_copy.end(); client++) { | 463 client != clients_copy.end(); client++) { |
| 476 ConnectionToClient* connection_other = client->get()->connection(); | 464 ConnectionToClient* connection_other = client->get()->connection(); |
| 477 if (connection_other != connection) { | 465 if (connection_other != connection) { |
| 478 OnClientDisconnected(connection_other); | 466 OnClientDisconnected(connection_other); |
| 479 } | 467 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 507 EnableCurtainMode(true); | 495 EnableCurtainMode(true); |
| 508 if (is_it2me_) { | 496 if (is_it2me_) { |
| 509 std::string username = jid; | 497 std::string username = jid; |
| 510 size_t pos = username.find('/'); | 498 size_t pos = username.find('/'); |
| 511 if (pos != std::string::npos) | 499 if (pos != std::string::npos) |
| 512 username.replace(pos, std::string::npos, ""); | 500 username.replace(pos, std::string::npos, ""); |
| 513 desktop_environment_->OnConnect(username); | 501 desktop_environment_->OnConnect(username); |
| 514 } | 502 } |
| 515 } | 503 } |
| 516 | 504 |
| 517 void ChromotingHost::LocalLoginFailed( | |
| 518 scoped_refptr<ConnectionToClient> connection) { | |
| 519 if (MessageLoop::current() != context_->main_message_loop()) { | |
| 520 context_->main_message_loop()->PostTask( | |
| 521 FROM_HERE, base::Bind(&ChromotingHost::LocalLoginFailed, this, | |
| 522 connection)); | |
| 523 return; | |
| 524 } | |
| 525 | |
| 526 protocol::LocalLoginStatus* status = new protocol::LocalLoginStatus(); | |
| 527 status->set_success(false); | |
| 528 connection->client_stub()->BeginSessionResponse( | |
| 529 status, base::Bind(&DeletePointer<protocol::LocalLoginStatus>, status)); | |
| 530 } | |
| 531 | |
| 532 void ChromotingHost::ProcessPreAuthentication( | 505 void ChromotingHost::ProcessPreAuthentication( |
| 533 const scoped_refptr<ConnectionToClient>& connection) { | 506 const scoped_refptr<ConnectionToClient>& connection) { |
| 534 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 507 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
| 535 // Find the client session corresponding to the given connection. | 508 // Find the client session corresponding to the given connection. |
| 536 ClientList::iterator client; | 509 ClientList::iterator client; |
| 537 for (client = clients_.begin(); client != clients_.end(); ++client) { | 510 for (client = clients_.begin(); client != clients_.end(); ++client) { |
| 538 if (client->get()->connection() == connection) | 511 if (client->get()->connection() == connection) |
| 539 break; | 512 break; |
| 540 } | 513 } |
| 541 CHECK(client != clients_.end()); | 514 CHECK(client != clients_.end()); |
| 542 | 515 |
| 543 context_->network_message_loop()->PostTask( | 516 context_->network_message_loop()->PostTask( |
| 544 FROM_HERE, base::Bind(&ClientSession::OnAuthorizationComplete, | 517 FROM_HERE, base::Bind(&ClientSession::OnAuthenticationComplete, |
| 545 client->get(), true)); | 518 client->get())); |
| 546 } | 519 } |
| 547 | 520 |
| 548 void ChromotingHost::StopScreenRecorder() { | 521 void ChromotingHost::StopScreenRecorder() { |
| 549 DCHECK(MessageLoop::current() == context_->main_message_loop()); | 522 DCHECK(MessageLoop::current() == context_->main_message_loop()); |
| 550 DCHECK(recorder_.get()); | 523 DCHECK(recorder_.get()); |
| 551 | 524 |
| 552 ++stopping_recorders_; | 525 ++stopping_recorders_; |
| 553 recorder_->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); | 526 recorder_->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); |
| 554 recorder_ = NULL; | 527 recorder_ = NULL; |
| 555 } | 528 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 | 612 |
| 640 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); | 613 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); |
| 641 it != shutdown_tasks_.end(); ++it) { | 614 it != shutdown_tasks_.end(); ++it) { |
| 642 (*it)->Run(); | 615 (*it)->Run(); |
| 643 delete *it; | 616 delete *it; |
| 644 } | 617 } |
| 645 shutdown_tasks_.clear(); | 618 shutdown_tasks_.clear(); |
| 646 } | 619 } |
| 647 | 620 |
| 648 } // namespace remoting | 621 } // namespace remoting |
| OLD | NEW |