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

Unified Diff: chromeos/audio/cras_audio_handler.cc

Issue 14678004: cros: Enable new cras audio handler by default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang fix. Created 7 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 | « chromeos/audio/cras_audio_handler.h ('k') | chromeos/audio/mock_cras_audio_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fc0a2eb844ce9544474b0af81e63ca2d906ca5c1 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;
@@ -125,6 +132,14 @@ bool CrasAudioHandler::GetActiveOutputDevice(AudioDevice* device) const {
return false;
}
+bool CrasAudioHandler::has_alternative_input() const {
+ return has_alternative_input_;
+}
+
+bool CrasAudioHandler::has_alternative_output() const {
+ return has_alternative_output_;
+}
+
void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) {
volume_percent = min(max(volume_percent, 0), 100);
if (volume_percent <= kMuteThresholdPercent)
@@ -191,16 +206,28 @@ 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() ||
+ !chromeos::DBusThreadManager::Get() ||
+ !chromeos::DBusThreadManager::Get()->GetCrasAudioClient())
+ return;
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
RemoveObserver(this);
- audio_pref_handler_->RemoveAudioPrefObserver(this);
+ if (audio_pref_handler_)
+ audio_pref_handler_->RemoveAudioPrefObserver(this);
audio_pref_handler_ = NULL;
}
« no previous file with comments | « chromeos/audio/cras_audio_handler.h ('k') | chromeos/audio/mock_cras_audio_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698