Index: chromeos/audio/cras_audio_handler.cc |
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc |
index b374402baa7acb3383e7b7ce26a0aa41756fd103..a0980a69c195a29688f2a8c801ee0ad5a6e44bc0 100644 |
--- a/chromeos/audio/cras_audio_handler.cc |
+++ b/chromeos/audio/cras_audio_handler.cc |
@@ -11,6 +11,7 @@ |
#include "base/bind_helpers.h" |
#include "base/logging.h" |
#include "chromeos/audio/audio_pref_handler.h" |
+#include "chromeos/audio/mock_cras_audio_handler.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
using std::max; |
@@ -63,6 +64,12 @@ void CrasAudioHandler::Initialize( |
} |
// static |
+void CrasAudioHandler::InitializeForTesting() { |
+ CHECK(!g_cras_audio_handler); |
+ g_cras_audio_handler = new MockCrasAudioHandler(); |
+} |
+ |
+// static |
void CrasAudioHandler::Shutdown() { |
CHECK(g_cras_audio_handler); |
delete g_cras_audio_handler; |
@@ -191,13 +198,24 @@ CrasAudioHandler::CrasAudioHandler( |
has_alternative_output_(false), |
output_mute_locked_(false), |
input_mute_locked_(false) { |
+ if (!audio_pref_handler) |
+ return; |
+ // If the DBusThreadManager or the CrasAudioClient aren't available, there |
+ // isn't much we can do. This should only happen when running tests. |
+ if (!chromeos::DBusThreadManager::IsInitialized() || |
+ !chromeos::DBusThreadManager::Get() || |
+ !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) |
+ return; |
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); |
- DCHECK(audio_pref_handler_.get()); |
audio_pref_handler_->AddAudioPrefObserver(this); |
SetupInitialAudioState(); |
} |
CrasAudioHandler::~CrasAudioHandler() { |
+ if (!chromeos::DBusThreadManager::IsInitialized() || |
James Cook
2013/04/30 23:31:21
Do you need to check audio_pref_handler_ here?
rkc
2013/04/30 23:36:37
Yeah; in case we're running in a test, we also nee
|
+ !chromeos::DBusThreadManager::Get() || |
+ !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) |
+ return; |
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
RemoveObserver(this); |
audio_pref_handler_->RemoveAudioPrefObserver(this); |