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

Unified Diff: remoting/host/screen_recorder.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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/screen_recorder.cc
diff --git a/remoting/host/screen_recorder.cc b/remoting/host/screen_recorder.cc
index 1a05797f8faa7e1631b8cf7dbec23f8f38fc8dfe..8f5f5fb43ef6a748478dfcda300a8d56abad1f09 100644
--- a/remoting/host/screen_recorder.cc
+++ b/remoting/host/screen_recorder.cc
@@ -6,6 +6,7 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
@@ -67,9 +68,20 @@ void ScreenRecorder::Start() {
FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoStart));
}
-void ScreenRecorder::Stop(Task* done_task) {
- capture_loop_->PostTask(
- FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoStop, done_task));
+void ScreenRecorder::Stop(const base::Closure& done_task) {
+ if (MessageLoop::current() != capture_loop_) {
+ capture_loop_->PostTask(FROM_HERE, base::Bind(
+ &ScreenRecorder::Stop, this, done_task));
+ return;
+ }
+
+ DCHECK(!done_task.is_null());
+
+ capture_timer_.Stop();
+ is_recording_ = false;
+
+ network_loop_->PostTask(FROM_HERE, base::Bind(
+ &ScreenRecorder::DoStopOnNetworkThread, this, done_task));
}
void ScreenRecorder::SetMaxRate(double rate) {
@@ -148,30 +160,6 @@ void ScreenRecorder::DoStart() {
DoCapture();
}
-void ScreenRecorder::DoStop(Task* done_task) {
- DCHECK_EQ(capture_loop_, MessageLoop::current());
-
- base::ScopedTaskRunner done_runner(done_task);
-
- // We might have not started when we receive a stop command, simply run the
- // task and then return.
- if (!is_recording_)
- return;
-
- capture_timer_.Stop();
- is_recording_ = false;
-
- DCHECK_GE(recordings_, 0);
- if (recordings_) {
- network_loop_->PostTask(
- FROM_HERE,
- NewTracedMethod(this,
- &ScreenRecorder::DoStopOnNetworkThread,
- done_runner.Release()));
- return;
- }
-}
-
void ScreenRecorder::DoSetMaxRate(double max_rate) {
DCHECK_EQ(capture_loop_, MessageLoop::current());
@@ -341,7 +329,7 @@ void ScreenRecorder::DoRemoveAllClients() {
connections_.clear();
}
-void ScreenRecorder::DoStopOnNetworkThread(Task* done_task) {
+void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) {
DCHECK_EQ(network_loop_, MessageLoop::current());
// There could be tasks on the network thread when this method is being
@@ -385,7 +373,7 @@ void ScreenRecorder::DoEncode(
TraceContext::tracer()->PrintString("Encode Done");
}
-void ScreenRecorder::DoStopOnEncodeThread(Task* done_task) {
+void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) {
DCHECK_EQ(encode_loop_, MessageLoop::current());
encoder_stopped_ = true;
@@ -393,8 +381,7 @@ void ScreenRecorder::DoStopOnEncodeThread(Task* done_task) {
// When this method is being executed there are no more tasks on encode thread
// for this object. We can then post a task to capture thread to finish the
// stop sequence.
- if (done_task)
- capture_loop_->PostTask(FROM_HERE, done_task);
+ capture_loop_->PostTask(FROM_HERE, done_task);
}
void ScreenRecorder::EncodedDataAvailableCallback(VideoPacket* packet) {

Powered by Google App Engine
This is Rietveld 408576698