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

Unified Diff: media/audio/audio_manager.cc

Issue 1104583002: Adds method to provide custom AudioManager at runtime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor fixes, update to test factory. Created 5 years, 8 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/audio_manager.h ('k') | media/audio/audio_manager_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_manager.cc
diff --git a/media/audio/audio_manager.cc b/media/audio/audio_manager.cc
index 6ee61d16cd7bd6ad3beb3a2cf912b7f4ac1aeffe..4cb3278e6297fe519e282f0b0172a6ce7952e0dd 100644
--- a/media/audio/audio_manager.cc
+++ b/media/audio/audio_manager.cc
@@ -12,12 +12,22 @@
#include "base/message_loop/message_loop.h"
#include "base/power_monitor/power_monitor.h"
#include "build/build_config.h"
+#include "media/audio/audio_manager_factory.h"
#include "media/audio/fake_audio_log_factory.h"
namespace media {
namespace {
+
+// The singleton instance of AudioManager. This is set when Create() is called.
AudioManager* g_last_created = NULL;
+// The singleton instance of AudioManagerFactory. This is only set if
+// SetFactory() is called. If it is set when Create() is called, its
+// CreateInstance() function is used to set |g_last_created|. Otherwise, the
+// linked implementation of media::CreateAudioManager is used to set
+// |g_last_created|.
+AudioManagerFactory* g_audio_manager_factory = NULL;
+
// Maximum number of failed pings to the audio thread allowed. A crash will be
// issued once this count is reached. We require at least two pings before
// crashing to ensure unobservable power events aren't mistakenly caught (e.g.,
@@ -123,7 +133,7 @@ class AudioManagerHelper : public base::PowerObserver {
static base::LazyInstance<AudioManagerHelper>::Leaky g_helper =
LAZY_INSTANCE_INITIALIZER;
-}
+} // namespace
// Forward declaration of the platform specific AudioManager factory function.
AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory);
@@ -136,9 +146,29 @@ AudioManager::~AudioManager() {
}
// static
+void AudioManager::SetFactory(AudioManagerFactory* factory) {
+ CHECK(factory);
+ CHECK(!g_last_created);
+ CHECK(!g_audio_manager_factory);
+ g_audio_manager_factory = factory;
+}
+
+// static
+void AudioManager::ResetFactoryForTesting() {
+ if (g_audio_manager_factory) {
+ delete g_audio_manager_factory;
+ g_audio_manager_factory = nullptr;
+ }
+}
+
+// static
AudioManager* AudioManager::Create(AudioLogFactory* audio_log_factory) {
CHECK(!g_last_created);
- g_last_created = CreateAudioManager(audio_log_factory);
+ if (g_audio_manager_factory)
+ g_last_created = g_audio_manager_factory->CreateInstance(audio_log_factory);
+ else
+ g_last_created = CreateAudioManager(audio_log_factory);
+
return g_last_created;
}
« no previous file with comments | « media/audio/audio_manager.h ('k') | media/audio/audio_manager_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698