Chromium Code Reviews| Index: extensions/browser/api/audio/audio_api.cc |
| diff --git a/extensions/browser/api/audio/audio_api.cc b/extensions/browser/api/audio/audio_api.cc |
| index dabb853b1a277ce58ee9d4361b662e30a28d5d02..35cd9fc868acd9c5abe51135d8a0c3b50391dd53 100644 |
| --- a/extensions/browser/api/audio/audio_api.cc |
| +++ b/extensions/browser/api/audio/audio_api.cc |
| @@ -48,14 +48,20 @@ void AudioAPI::OnDeviceChanged() { |
| } |
| void AudioAPI::OnLevelChanged(const std::string& id, int level) { |
| - if (EventRouter::Get(browser_context_)) { |
| - std::unique_ptr<base::ListValue> args = |
| - audio::OnLevelChanged::Create(id, level); |
| - std::unique_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, |
| - audio::OnLevelChanged::kEventName, |
| - std::move(args))); |
| - EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| - } |
| + EventRouter* event_router = EventRouter::Get(browser_context_); |
| + if (!event_router) |
| + return; |
| + |
| + audio::LevelChangedEvent raw_event; |
| + raw_event.device_id = id; |
| + raw_event.level = level; |
| + |
| + std::unique_ptr<base::ListValue> event_args = |
| + audio::OnLevelChanged::Create(raw_event); |
| + std::unique_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, |
| + audio::OnLevelChanged::kEventName, |
| + std::move(event_args))); |
| + event_router->BroadcastEvent(std::move(event)); |
| } |
| void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { |
| @@ -77,14 +83,16 @@ void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { |
| } |
| void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { |
| - if (EventRouter::Get(browser_context_)) { |
| - std::unique_ptr<base::ListValue> args = |
| - audio::OnDevicesChanged::Create(devices); |
| - std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, |
| - audio::OnDevicesChanged::kEventName, |
| - std::move(args))); |
| - EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| - } |
| + EventRouter* event_router = EventRouter::Get(browser_context_); |
| + if (!event_router) |
| + return; |
| + |
| + std::unique_ptr<base::ListValue> args = |
| + audio::OnDeviceListChanged::Create(devices); |
| + std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, |
| + audio::OnDeviceListChanged::kEventName, |
| + std::move(args))); |
| + event_router->BroadcastEvent(std::move(event)); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| @@ -106,6 +114,26 @@ ExtensionFunction::ResponseAction AudioGetInfoFunction::Run() { |
| /////////////////////////////////////////////////////////////////////////////// |
| +ExtensionFunction::ResponseAction AudioGetDevicesFunction::Run() { |
| + std::unique_ptr<audio::GetDevices::Params> params( |
| + audio::GetDevices::Params::Create(*args_)); |
| + EXTENSION_FUNCTION_VALIDATE(params.get()); |
| + |
| + AudioService* service = |
| + AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| + DCHECK(service); |
| + |
| + std::vector<api::audio::AudioDeviceInfo> devices; |
| + if (!service->GetDevices(params->filter, &devices)) { |
| + return RespondNow( |
| + Error("Error occurred when querying audio device information.")); |
| + } |
| + |
| + return RespondNow(ArgumentList(audio::GetDevices::Results::Create(devices))); |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
| ExtensionFunction::ResponseAction AudioSetActiveDevicesFunction::Run() { |
| std::unique_ptr<audio::SetActiveDevices::Params> params( |
| audio::SetActiveDevices::Params::Create(*args_)); |
| @@ -141,13 +169,18 @@ ExtensionFunction::ResponseAction AudioSetPropertiesFunction::Run() { |
| AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| DCHECK(service); |
| + int level_value = |
| + params->properties.level.get() ? *params->properties.level : -1; |
| + |
| int volume_value = params->properties.volume.get() ? |
| *params->properties.volume : -1; |
| int gain_value = params->properties.gain.get() ? |
| *params->properties.gain : -1; |
| - if (!service->SetDeviceSoundLevel(params->id, volume_value, gain_value)) |
| + if (!service->SetDeviceSoundLevel( |
| + params->id, level_value >= 0 ? level_value : volume_value, |
| + level_value >= 0 ? level_value : gain_value)) |
|
jennyz
2017/02/02 01:10:44
Please add a comment about the migration.
tbarzic
2017/02/02 01:24:41
Done.
|
| return RespondNow(Error("Could not set volume/gain properties")); |
| if (params->properties.is_muted.get() && |