| Index: extensions/browser/api/audio/audio_service_chromeos.cc
|
| diff --git a/extensions/browser/api/audio/audio_service_chromeos.cc b/extensions/browser/api/audio/audio_service_chromeos.cc
|
| index 8005ac69f22175600364894e4e8c047976ce9e33..58b1ff9c35f44c16163c6f26484d7b094e3d1466 100644
|
| --- a/extensions/browser/api/audio/audio_service_chromeos.cc
|
| +++ b/extensions/browser/api/audio/audio_service_chromeos.cc
|
| @@ -17,6 +17,7 @@ namespace extensions {
|
|
|
| using core_api::audio::OutputDeviceInfo;
|
| using core_api::audio::InputDeviceInfo;
|
| +using core_api::audio::AudioDeviceInfo;
|
|
|
| class AudioServiceImpl : public AudioService,
|
| public chromeos::CrasAudioHandler::AudioObserver {
|
| @@ -35,10 +36,11 @@ class AudioServiceImpl : public AudioService,
|
| bool muted,
|
| int volume,
|
| int gain) override;
|
| + void StartGetDeviceInfo(const GetDeviceInfoCallback& callback) override;
|
|
|
| protected:
|
| // chromeos::CrasAudioHandler::AudioObserver overrides.
|
| - void OnOutputVolumeChanged() override;
|
| + void OnOutputNodeVolumeChanged(uint64 id, double volume) override;
|
| void OnInputGainChanged() override;
|
| void OnOutputMuteChanged() override;
|
| void OnInputMuteChanged() override;
|
| @@ -170,6 +172,45 @@ bool AudioServiceImpl::SetDeviceProperties(const std::string& device_id,
|
| return false;
|
| }
|
|
|
| +void AudioServiceImpl::StartGetDeviceInfo(
|
| + const GetDeviceInfoCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(cras_audio_handler_);
|
| + DCHECK(!callback.is_null());
|
| +
|
| + if (callback.is_null())
|
| + return;
|
| +
|
| + DevicesInfo devices_info;
|
| + if (!cras_audio_handler_) {
|
| + callback.Run(devices_info, false);
|
| + return;
|
| + }
|
| +
|
| + chromeos::AudioDeviceList devices;
|
| + cras_audio_handler_->GetAudioDevices(&devices);
|
| + for (size_t i = 0; i < devices.size(); ++i) {
|
| + linked_ptr<AudioDeviceInfo> info(new AudioDeviceInfo());
|
| + info->id = base::Uint64ToString(devices[i].id);
|
| + info->display_name = devices[i].display_name;
|
| + info->device_name = devices[i].device_name;
|
| + info->is_input = devices[i].is_input;
|
| + info->is_active = devices[i].active;
|
| + info->volume_gain =
|
| + devices[i].is_input
|
| + ? cras_audio_handler_->GetInputGainPercentForDevice(devices[i].id)
|
| + : cras_audio_handler_->GetOutputVolumePercentForDevice(
|
| + devices[i].id);
|
| + info->is_muted =
|
| + devices[i].is_input
|
| + ? cras_audio_handler_->IsInputMutedForDevice(devices[i].id)
|
| + : cras_audio_handler_->IsOutputMutedForDevice(devices[i].id);
|
| + devices_info.push_back(info);
|
| + }
|
| +
|
| + callback.Run(devices_info, true);
|
| +}
|
| +
|
| bool AudioServiceImpl::FindDevice(uint64 id, chromeos::AudioDevice* device) {
|
| chromeos::AudioDeviceList devices;
|
| cras_audio_handler_->GetAudioDevices(&devices);
|
| @@ -191,7 +232,13 @@ uint64 AudioServiceImpl::GetIdFromStr(const std::string& id_str) {
|
| return device_id;
|
| }
|
|
|
| -void AudioServiceImpl::OnOutputVolumeChanged() {
|
| +void AudioServiceImpl::OnOutputNodeVolumeChanged(uint64 id, double volume) {
|
| + FOR_EACH_OBSERVER(
|
| + AudioService::Observer, observer_list_,
|
| + OnOutputNodeVolumeChanged(base::Uint64ToString(id), volume));
|
| +
|
| + // Notify DeviceChanged event for backward compatibility.
|
| + // TODO(jennyz): remove this code when the old version of hotrod retires.
|
| NotifyDeviceChanged();
|
| }
|
|
|
|
|