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

Unified Diff: content/renderer/media/scoped_loop_observer.h

Issue 9104043: Monitor the IO message loop in the AudioDevice classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix indent Created 8 years, 10 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 | « content/renderer/media/audio_input_device.cc ('k') | content/renderer/media/scoped_loop_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/scoped_loop_observer.h
diff --git a/content/renderer/media/scoped_loop_observer.h b/content/renderer/media/scoped_loop_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..127d992cc65a4a4ce79700ccb6a9b68fa86be208
--- /dev/null
+++ b/content/renderer/media/scoped_loop_observer.h
@@ -0,0 +1,45 @@
+// 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 CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_
+#define CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+
+namespace base {
+class WaitableEvent;
+}
+
+// A common base class for AudioDevice and AudioInputDevice that manages
+// a message loop pointer and monitors it for destruction. If the object goes
+// out of scope before the message loop, the object will automatically remove
+// itself from the message loop's list of destruction observers.
+// NOTE: The class that inherits from this class must implement the
+// WillDestroyCurrentMessageLoop virtual method from DestructionObserver.
+class ScopedLoopObserver
+ : public MessageLoop::DestructionObserver {
+ public:
+ explicit ScopedLoopObserver(MessageLoop* message_loop);
+ virtual ~ScopedLoopObserver();
+
+ protected:
+ // Accessor to the loop that's used by the derived class.
+ base::MessageLoopProxy* message_loop() { return loop_; }
+
+ 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 message loop's proxy. In case the loop gets destroyed
+ // before this object goes out of scope, PostTask etc will fail but not crash.
+ scoped_refptr<base::MessageLoopProxy> loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedLoopObserver);
+};
+
+#endif // CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_
« no previous file with comments | « content/renderer/media/audio_input_device.cc ('k') | content/renderer/media/scoped_loop_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698