Chromium Code Reviews| Index: remoting/host/chromoting_host.cc |
| diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc |
| index 1d42059425fd92743d49edec0e46b872983a5221..313622ff77832978ae9906c9892fa4665ca77236 100644 |
| --- a/remoting/host/chromoting_host.cc |
| +++ b/remoting/host/chromoting_host.cc |
| @@ -55,6 +55,7 @@ ChromotingHost::ChromotingHost(ChromotingHostContext* context, |
| access_verifier_(access_verifier), |
| allow_nat_traversal_(allow_nat_traversal), |
| state_(kInitial), |
| + stopping_recorders_(0), |
| protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), |
| is_curtained_(false), |
| is_it2me_(false) { |
| @@ -376,13 +377,11 @@ void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { |
| recorder_->RemoveConnection(connection); |
| // The recorder only exists to serve the unique authenticated client. |
| // If that client has disconnected, then we can kill the recorder. |
| - if (client->get()->authenticated()) { |
| - recorder_->Stop(NULL); |
| - recorder_ = NULL; |
| - } |
| + if (client->get()->authenticated()) |
| + StopScreenRecorder(); |
| } |
| - // Close the connection to connection just to be safe. |
| + // Close the connection to client just to be safe. |
| connection->Disconnect(); |
| // Also remove reference to ConnectionToClient from this object. |
| @@ -542,6 +541,34 @@ void ChromotingHost::ProcessPreAuthentication( |
| client->get()->OnAuthorizationComplete(true); |
| } |
| +void ChromotingHost::StopScreenRecorder() { |
| + DCHECK(MessageLoop::current() == context_->main_message_loop()); |
| + |
| + ++stopping_recorders_; |
| + 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.
|
| + recorder_ = NULL; |
| +} |
| + |
| +void ChromotingHost::OnScreenRecorderStopped() { |
| + if (MessageLoop::current() != context_->main_message_loop()) { |
| + context_->main_message_loop()->PostTask( |
| + FROM_HERE, base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); |
| + return; |
| + } |
| + |
| + --stopping_recorders_; |
| + DCHECK_GE(stopping_recorders_, 0); |
| + |
| + bool stopping; |
| + { |
| + base::AutoLock auto_lock(lock_); |
| + stopping = state_ == kStopping; |
| + } |
| + |
| + if (!stopping_recorders_ && stopping) |
| + ShutdownFinish(); |
| +} |
| + |
| void ChromotingHost::ShutdownNetwork() { |
| if (MessageLoop::current() != context_->network_message_loop()) { |
| context_->network_message_loop()->PostTask( |
| @@ -577,8 +604,8 @@ void ChromotingHost::ShutdownRecorder() { |
| } |
| if (recorder_.get()) { |
| - recorder_->Stop(NewRunnableMethod(this, &ChromotingHost::ShutdownFinish)); |
| - } else { |
| + StopScreenRecorder(); |
| + } else if (!stopping_recorders_) { |
| ShutdownFinish(); |
| } |
| } |