| 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..cd6c11ea24a102a12c4357b07eb4770cf8ad1c42 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.get(), &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,21 @@ ExtensionFunction::ResponseAction AudioSetPropertiesFunction::Run() {
|
| AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
|
| DCHECK(service);
|
|
|
| + bool level_set = !!params->properties.level;
|
| + int level_value = level_set ? *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))
|
| + // |volume_value| and |gain_value| are deprecated in favor of |level_value|;
|
| + // they are kept around only to ensure backward-compatibility and should be
|
| + // ignored if |level_value| is set.
|
| + if (!service->SetDeviceSoundLevel(params->id,
|
| + level_set ? level_value : volume_value,
|
| + level_set ? level_value : gain_value))
|
| return RespondNow(Error("Could not set volume/gain properties"));
|
|
|
| if (params->properties.is_muted.get() &&
|
|
|