Chromium Code Reviews| Index: chromeos/audio/cras_audio_handler.cc |
| diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc |
| index 3a86d8676ff483bb52be7955b979ba21ad5de1bf..7fe0abfc4afc42654fb7f783304700df9dbba35b 100644 |
| --- a/chromeos/audio/cras_audio_handler.cc |
| +++ b/chromeos/audio/cras_audio_handler.cc |
| @@ -13,6 +13,7 @@ |
| #include "chromeos/audio/audio_devices_pref_handler.h" |
| #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "media/audio/audio_manager.h" |
| using std::max; |
| using std::min; |
| @@ -30,6 +31,10 @@ const int kMuteThresholdPercent = 1; |
| static CrasAudioHandler* g_cras_audio_handler = NULL; |
| +// audio_manager will point to a AudioManagerWrapperImpl object or |
| +// a mocked AudioManagerWrapper object for testing. |
| +static CrasAudioHandler::AudioManagerWrapper* audio_manager = NULL; |
|
Daniel Erat
2015/06/23 14:15:49
does this really need to be a global, or could it
cychiang
2015/06/24 08:11:29
Done.
Now this manager needs to be passed through
|
| + |
| bool IsSameAudioDevice(const AudioDevice& a, const AudioDevice& b) { |
| return a.id == b.id && a.is_input == b.is_input && a.type == b.type |
| && a.device_name == b.device_name; |
| @@ -81,11 +86,39 @@ void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() { |
| void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { |
| } |
| +CrasAudioHandler::AudioManagerWrapper::AudioManagerWrapper() { |
| +} |
| +CrasAudioHandler::AudioManagerWrapper::~AudioManagerWrapper() { |
| +} |
| + |
| +CrasAudioHandler::AudioManagerWrapperImpl::AudioManagerWrapperImpl() { |
| +} |
| +CrasAudioHandler::AudioManagerWrapperImpl::~AudioManagerWrapperImpl() { |
| +} |
| + |
| +void CrasAudioHandler::AudioManagerWrapperImpl::SetHasInputDevices( |
| + bool has_input_devices) { |
| + media::AudioManager::Get()->SetHasInputDevices(has_input_devices); |
| +} |
| + |
| +// static |
| +// Set audio manager wrapper for test. Must be called before Initialize |
|
Daniel Erat
2015/06/23 14:15:49
delete this comment; it's already present in the h
cychiang
2015/06/24 08:11:29
Done.
|
| +// for testing. CrasAudioHandler will delete this pointer at Shutdown. |
| +void CrasAudioHandler::SetUpAudioManagerWrapperForTesting( |
| + AudioManagerWrapper* test_wrapper) { |
| + DCHECK(!audio_manager); |
| + audio_manager = test_wrapper; |
| +} |
| + |
| // static |
| void CrasAudioHandler::Initialize( |
| scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { |
| CHECK(!g_cras_audio_handler); |
| g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); |
| + // Creates an AudioManagerWrapperImpl if audio_manager is not set |
| + // by SetUpAudioManagerWrapperForTesting. |
| + if (!audio_manager) |
| + audio_manager = new CrasAudioHandler::AudioManagerWrapperImpl(); |
| } |
| // static |
| @@ -99,6 +132,9 @@ void CrasAudioHandler::Shutdown() { |
| CHECK(g_cras_audio_handler); |
| delete g_cras_audio_handler; |
| g_cras_audio_handler = NULL; |
| + CHECK(audio_manager); |
| + delete audio_manager; |
| + audio_manager = NULL; |
| } |
| // static |
| @@ -903,6 +939,22 @@ void CrasAudioHandler::UpdateDevicesAndSwitchActive( |
| } |
| } |
| +void CrasAudioHandler::SetAudioManagerHasInputDevices(bool has_input_devices) { |
|
Daniel Erat
2015/06/23 14:15:49
this method is just one line; it seems simpler to
cychiang
2015/06/24 08:11:29
Done.
|
| + audio_manager->SetHasInputDevices(has_input_devices); |
| +} |
| + |
| +void CrasAudioHandler::UpdateAudioManagerHasInputDevices() { |
| + AudioDeviceList devices; |
| + GetAudioDevices(&devices); |
| + for (size_t i = 0; i < devices.size(); ++i) { |
| + if (devices[i].is_input && devices[i].IsForSimpleUsage()) { |
| + SetAudioManagerHasInputDevices(true); |
| + return; |
| + } |
| + } |
| + SetAudioManagerHasInputDevices(false); |
| +} |
| + |
| void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
| bool success) { |
| if (!success) { |
| @@ -911,6 +963,7 @@ void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
| } |
| UpdateDevicesAndSwitchActive(node_list); |
| + UpdateAudioManagerHasInputDevices(); |
| FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
| } |