Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: remoting/host/chromoting_host.cc

Issue 7635005: Properly handle screen recorder shutdown in ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/chromoting_host.h ('k') | remoting/host/screen_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 DCHECK(recorder_.get());
547
548 ++stopping_recorders_;
549 recorder_->Stop(base::Bind(&ChromotingHost::OnScreenRecorderStopped, this));
550 recorder_ = NULL;
551 }
552
553 void ChromotingHost::OnScreenRecorderStopped() {
554 if (MessageLoop::current() != context_->main_message_loop()) {
555 context_->main_message_loop()->PostTask(
556 FROM_HERE, base::Bind(&ChromotingHost::OnScreenRecorderStopped, this));
557 return;
558 }
559
560 --stopping_recorders_;
561 DCHECK_GE(stopping_recorders_, 0);
562
563 bool stopping;
564 {
565 base::AutoLock auto_lock(lock_);
566 stopping = state_ == kStopping;
567 }
568
569 if (!stopping_recorders_ && stopping)
570 ShutdownFinish();
571 }
572
545 void ChromotingHost::ShutdownNetwork() { 573 void ChromotingHost::ShutdownNetwork() {
546 if (MessageLoop::current() != context_->network_message_loop()) { 574 if (MessageLoop::current() != context_->network_message_loop()) {
547 context_->network_message_loop()->PostTask( 575 context_->network_message_loop()->PostTask(
548 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this)); 576 FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this));
549 return; 577 return;
550 } 578 }
551 579
552 // Stop chromotocol session manager. 580 // Stop chromotocol session manager.
553 if (session_manager_.get()) { 581 if (session_manager_.get()) {
554 session_manager_->Close(); 582 session_manager_->Close();
(...skipping 15 matching lines...) Expand all
570 } 598 }
571 599
572 void ChromotingHost::ShutdownRecorder() { 600 void ChromotingHost::ShutdownRecorder() {
573 if (MessageLoop::current() != context_->main_message_loop()) { 601 if (MessageLoop::current() != context_->main_message_loop()) {
574 context_->main_message_loop()->PostTask( 602 context_->main_message_loop()->PostTask(
575 FROM_HERE, base::Bind(&ChromotingHost::ShutdownRecorder, this)); 603 FROM_HERE, base::Bind(&ChromotingHost::ShutdownRecorder, this));
576 return; 604 return;
577 } 605 }
578 606
579 if (recorder_.get()) { 607 if (recorder_.get()) {
580 recorder_->Stop(NewRunnableMethod(this, &ChromotingHost::ShutdownFinish)); 608 StopScreenRecorder();
581 } else { 609 } else if (!stopping_recorders_) {
582 ShutdownFinish(); 610 ShutdownFinish();
583 } 611 }
584 } 612 }
585 613
586 void ChromotingHost::ShutdownFinish() { 614 void ChromotingHost::ShutdownFinish() {
587 if (MessageLoop::current() != context_->main_message_loop()) { 615 if (MessageLoop::current() != context_->main_message_loop()) {
588 context_->main_message_loop()->PostTask( 616 context_->main_message_loop()->PostTask(
589 FROM_HERE, base::Bind(&ChromotingHost::ShutdownFinish, this)); 617 FROM_HERE, base::Bind(&ChromotingHost::ShutdownFinish, this));
590 return; 618 return;
591 } 619 }
(...skipping 11 matching lines...) Expand all
603 631
604 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin(); 632 for (std::vector<Task*>::iterator it = shutdown_tasks_.begin();
605 it != shutdown_tasks_.end(); ++it) { 633 it != shutdown_tasks_.end(); ++it) {
606 (*it)->Run(); 634 (*it)->Run();
607 delete *it; 635 delete *it;
608 } 636 }
609 shutdown_tasks_.clear(); 637 shutdown_tasks_.clear();
610 } 638 }
611 639
612 } // namespace remoting 640 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.h ('k') | remoting/host/screen_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698