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

Unified Diff: chrome/browser/renderer_host/audio_renderer_host.h

Issue 20131: Create AudioRendererHost in BrowserRenderProcessHost and hook with ResourceMessageFilter (Closed)
Patch Set: mac project files Created 11 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 | « chrome/browser/browser.scons ('k') | chrome/browser/renderer_host/audio_renderer_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/audio_renderer_host.h
diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h
index 4df24ba9214fa600e66b772db4d2f45e661ef5ef..8128d61f545c88205ff9d17fcb9b54285092aae8 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.h
+++ b/chrome/browser/renderer_host/audio_renderer_host.h
@@ -17,11 +17,31 @@
// passing a SharedMemoryHandle for filling the buffer.
// NotifyPacketReady(|stream_id|) would be called when the buffer is filled
// and ready to be consumed.
+//
+// This class is owned by BrowserRenderProcessHost, and instantiated on UI
+// thread, but all other operations and method calls (except Destroy()) happens
+// in IO thread, so we need to be extra careful about the lifetime of this
+// object. AudioManager is a singleton and created in IO thread, audio output
+// streams are also created in the IO thread, so we need to destroy them also
+// in IO thread. After this class is created, a task of OnInitialized() is
+// posted on IO thread in which singleton of AudioManager is created and
+// AddRef() is called to increase one ref count of this object. Owner of this
+// class should call Destroy() before decrementing the ref count to this object,
+// which essentially post a task of OnDestroyed() on IO thread. Inside
+// OnDestroyed(), audio output streams are destroyed and Release() is called
+// which may result in self-destruction.
+//
+// TODO(hclam): Have these things done before having real implementations:
+// 1. Make sure this class has greater or equal lifetime to
+// IPC:Message::Sender, essentially ResourceMessageFilter.
+// 2. Listen to destruction event of the browser and do cleanup in case this
+// class is not destructed nicely during browser close.
#ifndef CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_
#define CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_
#include "base/id_map.h"
+#include "base/ref_counted.h"
#include "base/shared_memory.h"
#include "chrome/common/ipc_message.h"
#include "media/audio/audio_output.h"
@@ -29,7 +49,7 @@
class AudioManager;
class MessageLoop;
-class AudioRendererHost {
+class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> {
public:
static const int32 INVALID_ID = 0;
@@ -74,14 +94,24 @@ class AudioRendererHost {
// consumed.
void NotifyPacketReady(int32 stream_id);
- // Destroy all audio output streams.
- void DestroyAllStreams();
+ // Called from UI thread from the owner of this object.
+ void Destroy();
// Destroy the stream specified by |stream_id| and remove it from map.
// *DO NOT* call this method other than from IPCAudioSource.
void DestroySource(int32 stream_id);
private:
+ // Methods called on IO thread.
+ // Called on IO thread when this object is created and initialized.
+ void OnInitialized();
+ // Called on IO thread when this object needs to be destroyed and after
+ // Destroy() is called from owner of this class in UI thread.
+ void OnDestroyed();
+
+ // Destroy all audio output streams.
+ void DestroyAllStreams();
+
// The container for AudioOutputStream and serves audio packet for it by IPC.
class IPCAudioSource : public AudioOutputStream::AudioSourceCallback {
public:
@@ -124,7 +154,7 @@ class AudioRendererHost {
// Only used for DCHECKs to make sure all methods calls are from the same
// thread as this object is created.
- MessageLoop* message_loop_;
+ MessageLoop* io_loop_;
DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
};
« no previous file with comments | « chrome/browser/browser.scons ('k') | chrome/browser/renderer_host/audio_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698