diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 21:49:30 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 21:49:30 +0000 |
commit | 92698ce853664cdd1dee6e7b4a7e6d382dfb8786 (patch) | |
tree | 7e81512de53a8d8a333e1a23743b83a5caa50996 /remoting/host/session_manager.cc | |
parent | 75f30cc2d6e90120b4ac43fcea1c38e783299f6e (diff) | |
download | chromium_src-92698ce853664cdd1dee6e7b4a7e6d382dfb8786.zip chromium_src-92698ce853664cdd1dee6e7b4a7e6d382dfb8786.tar.gz chromium_src-92698ce853664cdd1dee6e7b4a7e6d382dfb8786.tar.bz2 |
Fix thread usage in chromoting host
There are several things done in this patch:
1. Isloate thread start and stop to ChromotingHostContext
2. SessionManager now doesn't own capturer and encoder, ownership moved to ChromotingHost
3. Fix up the sequence of actions when ChromotingHost shuts down
TEST=remoting_unittests
BUG=none
Review URL: http://codereview.chromium.org/2829018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/session_manager.cc')
-rw-r--r-- | remoting/host/session_manager.cc | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/remoting/host/session_manager.cc b/remoting/host/session_manager.cc index cd6fc47..1e04482 100644 --- a/remoting/host/session_manager.cc +++ b/remoting/host/session_manager.cc @@ -139,6 +139,12 @@ void SessionManager::RemoveClient(scoped_refptr<ClientConnection> client) { NewRunnableMethod(this, &SessionManager::DoRemoveClient, client)); } +void SessionManager::RemoveAllClients() { + network_loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &SessionManager::DoRemoveAllClients)); +} + void SessionManager::DoCapture() { DCHECK_EQ(capture_loop_, MessageLoop::current()); @@ -166,8 +172,7 @@ void SessionManager::DoCapture() { ScheduleNextCapture(); // And finally perform one capture. - DCHECK(capturer_.get()); - capturer_->CaptureDirtyRects( + capturer()->CaptureDirtyRects( NewRunnableMethod(this, &SessionManager::CaptureDoneTask)); } @@ -190,13 +195,11 @@ void SessionManager::DoEncode(const CaptureData *capture_data) { DCHECK_EQ(encode_loop_, MessageLoop::current()); - DCHECK(encoder_.get()); - // TODO(hclam): Enable |force_refresh| if a new client was // added. - encoder_->SetSize(capture_data->width_, capture_data->height_); - encoder_->SetPixelFormat(capture_data->pixel_format_); - encoder_->Encode( + encoder()->SetSize(capture_data->width_, capture_data->height_); + encoder()->SetPixelFormat(capture_data->pixel_format_); + encoder()->Encode( capture_data->dirty_rects_, capture_data->data_, capture_data->data_strides_, @@ -239,7 +242,7 @@ void SessionManager::DoGetInitInfo(scoped_refptr<ClientConnection> client) { network_loop_->PostTask( FROM_HERE, NewRunnableMethod(this, &SessionManager::DoSendInit, client, - capturer_->GetWidth(), capturer_->GetHeight())); + capturer()->GetWidth(), capturer()->GetHeight())); // And then add the client to the list so it can receive update stream. // It is important we do so in such order or the client will receive @@ -288,8 +291,16 @@ void SessionManager::DoRemoveClient(scoped_refptr<ClientConnection> client) { // TODO(hclam): Is it correct to do to a scoped_refptr? ClientConnectionList::iterator it = std::find(clients_.begin(), clients_.end(), client); - if (it != clients_.end()) + if (it != clients_.end()) { clients_.erase(it); + } +} + +void SessionManager::DoRemoveAllClients() { + DCHECK_EQ(network_loop_, MessageLoop::current()); + + // Clear the list of clients. + clients_.clear(); } void SessionManager::DoRateControl() { @@ -354,12 +365,12 @@ void SessionManager::CaptureDoneTask() { scoped_ptr<CaptureData> data(new CaptureData); // Save results of the capture. - capturer_->GetData(data->data_); - capturer_->GetDataStride(data->data_strides_); - capturer_->GetDirtyRects(&data->dirty_rects_); - data->pixel_format_ = capturer_->GetPixelFormat(); - data->width_ = capturer_->GetWidth(); - data->height_ = capturer_->GetHeight(); + capturer()->GetData(data->data_); + capturer()->GetDataStride(data->data_strides_); + capturer()->GetDirtyRects(&data->dirty_rects_); + data->pixel_format_ = capturer()->GetPixelFormat(); + data->width_ = capturer()->GetWidth(); + data->height_ = capturer()->GetHeight(); encode_loop_->PostTask( FROM_HERE, @@ -384,10 +395,20 @@ void SessionManager::EncodeDataAvailableTask( data, state)); - if (state == Encoder::EncodingEnded) { + if (state & Encoder::EncodingEnded) { capture_loop_->PostTask( FROM_HERE, NewRunnableMethod(this, &SessionManager::DoFinishEncode)); } } +Capturer* SessionManager::capturer() { + DCHECK_EQ(capture_loop_, MessageLoop::current()); + return capturer_.get(); +} + +Encoder* SessionManager::encoder() { + DCHECK_EQ(encode_loop_, MessageLoop::current()); + return encoder_.get(); +} + } // namespace remoting |