| 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 "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 protocol::Session* session, | 271 protocol::Session* session, |
| 272 protocol::SessionManager::IncomingSessionResponse* response) { | 272 protocol::SessionManager::IncomingSessionResponse* response) { |
| 273 base::AutoLock auto_lock(lock_); | 273 base::AutoLock auto_lock(lock_); |
| 274 if (state_ != kStarted) { | 274 if (state_ != kStarted) { |
| 275 *response = protocol::SessionManager::DECLINE; | 275 *response = protocol::SessionManager::DECLINE; |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 // If we are running Me2Mom and already have an authenticated client then | 279 // If we are running Me2Mom and already have an authenticated client then |
| 280 // reject the connection immediately. | 280 // reject the connection immediately. |
| 281 if (is_it2me_ && HasAuthenticatedClients()) { | 281 if (is_it2me_ && AuthenticatedClientsCount() > 0) { |
| 282 *response = protocol::SessionManager::DECLINE; | 282 *response = protocol::SessionManager::DECLINE; |
| 283 return; | 283 return; |
| 284 } | 284 } |
| 285 | 285 |
| 286 // Check that the client has access to the host. | 286 // Check that the client has access to the host. |
| 287 if (!access_verifier_->VerifyPermissions(session->jid(), | 287 if (!access_verifier_->VerifyPermissions(session->jid(), |
| 288 session->initiator_token())) { | 288 session->initiator_token())) { |
| 289 *response = protocol::SessionManager::DECLINE; | 289 *response = protocol::SessionManager::DECLINE; |
| 290 | 290 |
| 291 // Notify observers. | 291 // Notify observers. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 if (client->get()->authenticated()) { | 393 if (client->get()->authenticated()) { |
| 394 recorder_->Stop(NULL); | 394 recorder_->Stop(NULL); |
| 395 recorder_ = NULL; | 395 recorder_ = NULL; |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Close the connection to connection just to be safe. | 399 // Close the connection to connection just to be safe. |
| 400 connection->Disconnect(); | 400 connection->Disconnect(); |
| 401 | 401 |
| 402 // Also remove reference to ConnectionToClient from this object. | 402 // Also remove reference to ConnectionToClient from this object. |
| 403 int old_authenticated_clients = AuthenticatedClientsCount(); |
| 403 clients_.erase(client); | 404 clients_.erase(client); |
| 404 | 405 |
| 405 if (!HasAuthenticatedClients()) { | 406 // Notify the observers of the change, if any. |
| 407 int authenticated_clients = AuthenticatedClientsCount(); |
| 408 if (old_authenticated_clients != authenticated_clients) { |
| 409 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 410 it != status_observers_.end(); ++it) { |
| 411 (*it)->OnAuthenticatedClientsChanged(authenticated_clients); |
| 412 } |
| 413 } |
| 414 |
| 415 // Enable the "curtain", if at least one client is actually authenticated. |
| 416 if (AuthenticatedClientsCount() > 0) { |
| 406 EnableCurtainMode(false); | 417 EnableCurtainMode(false); |
| 407 if (is_it2me_) { | 418 if (is_it2me_) { |
| 408 MonitorLocalInputs(false); | 419 MonitorLocalInputs(false); |
| 409 ShowDisconnectWindow(false, std::string()); | 420 ShowDisconnectWindow(false, std::string()); |
| 410 ShowContinueWindow(false); | 421 ShowContinueWindow(false); |
| 411 StartContinueWindowTimer(false); | 422 StartContinueWindowTimer(false); |
| 412 } | 423 } |
| 413 } | 424 } |
| 414 } | 425 } |
| 415 | 426 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 431 | 442 |
| 432 return NULL; | 443 return NULL; |
| 433 } | 444 } |
| 434 | 445 |
| 435 std::string ChromotingHost::GenerateHostAuthToken( | 446 std::string ChromotingHost::GenerateHostAuthToken( |
| 436 const std::string& encoded_client_token) { | 447 const std::string& encoded_client_token) { |
| 437 // TODO(ajwong): Return the signature of this instead. | 448 // TODO(ajwong): Return the signature of this instead. |
| 438 return encoded_client_token; | 449 return encoded_client_token; |
| 439 } | 450 } |
| 440 | 451 |
| 441 bool ChromotingHost::HasAuthenticatedClients() const { | 452 int ChromotingHost::AuthenticatedClientsCount() const { |
| 453 int authenticated_clients = 0; |
| 442 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); | 454 for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); |
| 443 ++it) { | 455 ++it) { |
| 444 if (it->get()->authenticated()) | 456 if (it->get()->authenticated()) |
| 445 return true; | 457 ++authenticated_clients; |
| 446 } | 458 } |
| 447 return false; | 459 return authenticated_clients; |
| 448 } | 460 } |
| 449 | 461 |
| 450 void ChromotingHost::EnableCurtainMode(bool enable) { | 462 void ChromotingHost::EnableCurtainMode(bool enable) { |
| 451 // TODO(jamiewalch): This will need to be more sophisticated when we think | 463 // TODO(jamiewalch): This will need to be more sophisticated when we think |
| 452 // about proper crash recovery and daemon mode. | 464 // about proper crash recovery and daemon mode. |
| 453 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. | 465 // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. |
| 454 if (is_it2me_ || enable == is_curtained_) | 466 if (is_it2me_ || enable == is_curtained_) |
| 455 return; | 467 return; |
| 456 desktop_environment_->curtain()->EnableCurtainMode(enable); | 468 desktop_environment_->curtain()->EnableCurtainMode(enable); |
| 457 is_curtained_ = enable; | 469 is_curtained_ = enable; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 EnableCurtainMode(true); | 529 EnableCurtainMode(true); |
| 518 if (is_it2me_) { | 530 if (is_it2me_) { |
| 519 MonitorLocalInputs(true); | 531 MonitorLocalInputs(true); |
| 520 std::string username = connection->session()->jid(); | 532 std::string username = connection->session()->jid(); |
| 521 size_t pos = username.find('/'); | 533 size_t pos = username.find('/'); |
| 522 if (pos != std::string::npos) | 534 if (pos != std::string::npos) |
| 523 username.replace(pos, std::string::npos, ""); | 535 username.replace(pos, std::string::npos, ""); |
| 524 ShowDisconnectWindow(true, username); | 536 ShowDisconnectWindow(true, username); |
| 525 StartContinueWindowTimer(true); | 537 StartContinueWindowTimer(true); |
| 526 } | 538 } |
| 539 |
| 540 // Notify observers that there is at least one authenticated client. |
| 541 for (StatusObserverList::iterator it = status_observers_.begin(); |
| 542 it != status_observers_.end(); ++it) { |
| 543 (*it)->OnAuthenticatedClientsChanged(AuthenticatedClientsCount()); |
| 544 } |
| 527 } | 545 } |
| 528 | 546 |
| 529 void ChromotingHost::LocalLoginFailed( | 547 void ChromotingHost::LocalLoginFailed( |
| 530 scoped_refptr<ConnectionToClient> connection) { | 548 scoped_refptr<ConnectionToClient> connection) { |
| 531 if (MessageLoop::current() != context_->main_message_loop()) { | 549 if (MessageLoop::current() != context_->main_message_loop()) { |
| 532 context_->main_message_loop()->PostTask( | 550 context_->main_message_loop()->PostTask( |
| 533 FROM_HERE, base::Bind(&ChromotingHost::LocalLoginFailed, this, | 551 FROM_HERE, base::Bind(&ChromotingHost::LocalLoginFailed, this, |
| 534 connection)); | 552 connection)); |
| 535 return; | 553 return; |
| 536 } | 554 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 694 |
| 677 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); | 695 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); |
| 678 it != shutdown_tasks_.end(); ++it) { | 696 it != shutdown_tasks_.end(); ++it) { |
| 679 (*it)->Run(); | 697 (*it)->Run(); |
| 680 delete *it; | 698 delete *it; |
| 681 } | 699 } |
| 682 shutdown_tasks_.clear(); | 700 shutdown_tasks_.clear(); |
| 683 } | 701 } |
| 684 | 702 |
| 685 } // namespace remoting | 703 } // namespace remoting |
| OLD | NEW |