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 "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 MutableHostConfig* config, | 48 MutableHostConfig* config, |
49 DesktopEnvironment* environment, | 49 DesktopEnvironment* environment, |
50 AccessVerifier* access_verifier, | 50 AccessVerifier* access_verifier, |
51 bool allow_nat_traversal) | 51 bool allow_nat_traversal) |
52 : context_(context), | 52 : context_(context), |
53 desktop_environment_(environment), | 53 desktop_environment_(environment), |
54 config_(config), | 54 config_(config), |
55 access_verifier_(access_verifier), | 55 access_verifier_(access_verifier), |
56 allow_nat_traversal_(allow_nat_traversal), | 56 allow_nat_traversal_(allow_nat_traversal), |
57 state_(kInitial), | 57 state_(kInitial), |
58 stopping_recorders_(0), | |
58 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), | 59 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
59 is_curtained_(false), | 60 is_curtained_(false), |
60 is_it2me_(false) { | 61 is_it2me_(false) { |
61 DCHECK(desktop_environment_); | 62 DCHECK(desktop_environment_); |
62 desktop_environment_->set_host(this); | 63 desktop_environment_->set_host(this); |
63 } | 64 } |
64 | 65 |
65 ChromotingHost::~ChromotingHost() { | 66 ChromotingHost::~ChromotingHost() { |
66 } | 67 } |
67 | 68 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 } | 370 } |
370 if (client == clients_.end()) | 371 if (client == clients_.end()) |
371 return; | 372 return; |
372 | 373 |
373 // Remove the connection from the session manager and stop the session. | 374 // Remove the connection from the session manager and stop the session. |
374 // TODO(hclam): Stop only if the last connection disconnected. | 375 // TODO(hclam): Stop only if the last connection disconnected. |
375 if (recorder_.get()) { | 376 if (recorder_.get()) { |
376 recorder_->RemoveConnection(connection); | 377 recorder_->RemoveConnection(connection); |
377 // The recorder only exists to serve the unique authenticated client. | 378 // The recorder only exists to serve the unique authenticated client. |
378 // If that client has disconnected, then we can kill the recorder. | 379 // If that client has disconnected, then we can kill the recorder. |
379 if (client->get()->authenticated()) { | 380 if (client->get()->authenticated()) |
380 recorder_->Stop(NULL); | 381 StopScreenRecorder(); |
381 recorder_ = NULL; | |
382 } | |
383 } | 382 } |
384 | 383 |
385 // Close the connection to connection just to be safe. | 384 // Close the connection to client just to be safe. |
386 connection->Disconnect(); | 385 connection->Disconnect(); |
387 | 386 |
388 // Also remove reference to ConnectionToClient from this object. | 387 // Also remove reference to ConnectionToClient from this object. |
389 int old_authenticated_clients = AuthenticatedClientsCount(); | 388 int old_authenticated_clients = AuthenticatedClientsCount(); |
390 clients_.erase(client); | 389 clients_.erase(client); |
391 | 390 |
392 // Notify the observers of the change, if any. | 391 // Notify the observers of the change, if any. |
393 int authenticated_clients = AuthenticatedClientsCount(); | 392 int authenticated_clients = AuthenticatedClientsCount(); |
394 if (old_authenticated_clients != authenticated_clients) { | 393 if (old_authenticated_clients != authenticated_clients) { |
395 for (StatusObserverList::iterator it = status_observers_.begin(); | 394 for (StatusObserverList::iterator it = status_observers_.begin(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 // Find the client session corresponding to the given connection. | 534 // Find the client session corresponding to the given connection. |
536 ClientList::iterator client; | 535 ClientList::iterator client; |
537 for (client = clients_.begin(); client != clients_.end(); ++client) { | 536 for (client = clients_.begin(); client != clients_.end(); ++client) { |
538 if (client->get()->connection() == connection) | 537 if (client->get()->connection() == connection) |
539 break; | 538 break; |
540 } | 539 } |
541 CHECK(client != clients_.end()); | 540 CHECK(client != clients_.end()); |
542 client->get()->OnAuthorizationComplete(true); | 541 client->get()->OnAuthorizationComplete(true); |
543 } | 542 } |
544 | 543 |
544 void ChromotingHost::StopScreenRecorder() { | |
545 DCHECK(MessageLoop::current() == context_->main_message_loop()); | |
546 | |
547 ++stopping_recorders_; | |
548 recorder_->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); | |
dmac
2011/08/11 23:56:34
should we check recorder_.get() != NULL? Could we
Sergey Ulanov
2011/08/12 00:29:48
Done.
| |
549 recorder_ = NULL; | |
550 } | |
551 | |
552 void ChromotingHost::OnScreenRecorderStopped() { | |
553 if (MessageLoop::current() != context_->main_message_loop()) { | |
554 context_->main_message_loop()->PostTask( | |
555 FROM_HERE, base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); | |
556 return; | |
557 } | |
558 | |
559 --stopping_recorders_; | |
560 DCHECK_GE(stopping_recorders_, 0); | |
561 | |
562 bool stopping; | |
563 { | |
564 base::AutoLock auto_lock(lock_); | |
565 stopping = state_ == kStopping; | |
566 } | |
567 | |
568 if (!stopping_recorders_ && stopping) | |
569 ShutdownFinish(); | |
570 } | |
571 | |
545 void ChromotingHost::ShutdownNetwork() { | 572 void ChromotingHost::ShutdownNetwork() { |
546 if (MessageLoop::current() != context_->network_message_loop()) { | 573 if (MessageLoop::current() != context_->network_message_loop()) { |
547 context_->network_message_loop()->PostTask( | 574 context_->network_message_loop()->PostTask( |
548 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this)); | 575 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this)); |
549 return; | 576 return; |
550 } | 577 } |
551 | 578 |
552 // Stop chromotocol session manager. | 579 // Stop chromotocol session manager. |
553 if (session_manager_.get()) { | 580 if (session_manager_.get()) { |
554 session_manager_->Close(); | 581 session_manager_->Close(); |
(...skipping 15 matching lines...) Expand all Loading... | |
570 } | 597 } |
571 | 598 |
572 void ChromotingHost::ShutdownRecorder() { | 599 void ChromotingHost::ShutdownRecorder() { |
573 if (MessageLoop::current() != context_->main_message_loop()) { | 600 if (MessageLoop::current() != context_->main_message_loop()) { |
574 context_->main_message_loop()->PostTask( | 601 context_->main_message_loop()->PostTask( |
575 FROM_HERE, base::Bind(&ChromotingHost::ShutdownRecorder, this)); | 602 FROM_HERE, base::Bind(&ChromotingHost::ShutdownRecorder, this)); |
576 return; | 603 return; |
577 } | 604 } |
578 | 605 |
579 if (recorder_.get()) { | 606 if (recorder_.get()) { |
580 recorder_->Stop(NewRunnableMethod(this, &ChromotingHost::ShutdownFinish)); | 607 StopScreenRecorder(); |
581 } else { | 608 } else if (!stopping_recorders_) { |
582 ShutdownFinish(); | 609 ShutdownFinish(); |
583 } | 610 } |
584 } | 611 } |
585 | 612 |
586 void ChromotingHost::ShutdownFinish() { | 613 void ChromotingHost::ShutdownFinish() { |
587 if (MessageLoop::current() != context_->main_message_loop()) { | 614 if (MessageLoop::current() != context_->main_message_loop()) { |
588 context_->main_message_loop()->PostTask( | 615 context_->main_message_loop()->PostTask( |
589 FROM_HERE, base::Bind(&ChromotingHost::ShutdownFinish, this)); | 616 FROM_HERE, base::Bind(&ChromotingHost::ShutdownFinish, this)); |
590 return; | 617 return; |
591 } | 618 } |
(...skipping 11 matching lines...) Expand all Loading... | |
603 | 630 |
604 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); | 631 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); |
605 it != shutdown_tasks_.end(); ++it) { | 632 it != shutdown_tasks_.end(); ++it) { |
606 (*it)->Run(); | 633 (*it)->Run(); |
607 delete *it; | 634 delete *it; |
608 } | 635 } |
609 shutdown_tasks_.clear(); | 636 shutdown_tasks_.clear(); |
610 } | 637 } |
611 | 638 |
612 } // namespace remoting | 639 } // namespace remoting |
OLD | NEW |