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

Unified Diff: media/audio/scoped_task_runner_observer.h

Issue 66183002: Replace MessageLoopProxy with SingleThreadTaskRunner for the rest of media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win and audio tests Created 6 years, 11 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
« no previous file with comments | « media/audio/scoped_loop_observer.cc ('k') | media/audio/scoped_task_runner_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/scoped_task_runner_observer.h
diff --git a/media/audio/scoped_task_runner_observer.h b/media/audio/scoped_task_runner_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..ce9adf96713a5d2235a0786d4d73c9502e48d7c4
--- /dev/null
+++ b/media/audio/scoped_task_runner_observer.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_
+#define MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+class WaitableEvent;
+}
+
+namespace media {
+
+// A common base class for AudioOutputDevice and AudioInputDevice that manages
+// a task runner and monitors it for destruction. If the object goes out of
+// scope before the task runner, the object will automatically remove itself
+// from the task runner's list of destruction observers.
+// NOTE: The class that inherits from this class must implement the
+// WillDestroyCurrentMessageLoop virtual method from DestructionObserver.
+class ScopedTaskRunnerObserver
+ : public base::MessageLoop::DestructionObserver {
+ public:
+ explicit ScopedTaskRunnerObserver(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
+
+ protected:
+ virtual ~ScopedTaskRunnerObserver();
+
+ // Accessor to the loop that's used by the derived class.
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() {
+ return task_runner_;
+ }
+
+ private:
+ // Call to add or remove ourselves from the list of destruction observers for
+ // the message loop.
+ void ObserveLoopDestruction(bool enable, base::WaitableEvent* done);
+
+ // A pointer to the task runner. In case it gets destroyed before this object
+ // goes out of scope, PostTask() etc will fail but not crash.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTaskRunnerObserver);
+};
+
+} // namespace media.
+
+#endif // MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_
« no previous file with comments | « media/audio/scoped_loop_observer.cc ('k') | media/audio/scoped_task_runner_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698