| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/api/audio/audio_api.h" | 5 #include "extensions/browser/api/audio/audio_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 std::unique_ptr<base::ListValue> args = | 52 std::unique_ptr<base::ListValue> args = |
| 53 audio::OnLevelChanged::Create(id, level); | 53 audio::OnLevelChanged::Create(id, level); |
| 54 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, | 54 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, |
| 55 audio::OnLevelChanged::kEventName, | 55 audio::OnLevelChanged::kEventName, |
| 56 std::move(args))); | 56 std::move(args))); |
| 57 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 57 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { | 61 void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { |
| 62 if (EventRouter::Get(browser_context_)) { | 62 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 63 std::unique_ptr<base::ListValue> args = | 63 if (!event_router) |
| 64 audio::OnMuteChanged::Create(is_input, is_muted); | 64 return; |
| 65 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_MUTE_CHANGED, | 65 |
| 66 audio::OnMuteChanged::kEventName, | 66 // Dispatch onMuteChanged event. |
| 67 std::move(args))); | 67 audio::MuteChangedEvent raw_event; |
| 68 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 68 raw_event.stream_type = |
| 69 } | 69 is_input ? audio::STREAM_TYPE_INPUT : audio::STREAM_TYPE_OUTPUT; |
| 70 raw_event.value = is_muted; |
| 71 std::unique_ptr<base::ListValue> event_args = |
| 72 audio::OnMuteChanged::Create(raw_event); |
| 73 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_MUTE_CHANGED, |
| 74 audio::OnMuteChanged::kEventName, |
| 75 std::move(event_args))); |
| 76 event_router->BroadcastEvent(std::move(event)); |
| 70 } | 77 } |
| 71 | 78 |
| 72 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { | 79 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { |
| 73 if (EventRouter::Get(browser_context_)) { | 80 if (EventRouter::Get(browser_context_)) { |
| 74 std::unique_ptr<base::ListValue> args = | 81 std::unique_ptr<base::ListValue> args = |
| 75 audio::OnDevicesChanged::Create(devices); | 82 audio::OnDevicesChanged::Create(devices); |
| 76 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, | 83 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, |
| 77 audio::OnDevicesChanged::kEventName, | 84 audio::OnDevicesChanged::kEventName, |
| 78 std::move(args))); | 85 std::move(args))); |
| 79 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 86 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 AudioService* service = | 129 AudioService* service = |
| 123 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); | 130 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 124 DCHECK(service); | 131 DCHECK(service); |
| 125 | 132 |
| 126 int volume_value = params->properties.volume.get() ? | 133 int volume_value = params->properties.volume.get() ? |
| 127 *params->properties.volume : -1; | 134 *params->properties.volume : -1; |
| 128 | 135 |
| 129 int gain_value = params->properties.gain.get() ? | 136 int gain_value = params->properties.gain.get() ? |
| 130 *params->properties.gain : -1; | 137 *params->properties.gain : -1; |
| 131 | 138 |
| 132 if (!service->SetDeviceProperties(params->id, params->properties.is_muted, | 139 if (!service->SetDeviceSoundLevel(params->id, volume_value, gain_value)) |
| 133 volume_value, gain_value)) { | 140 return RespondNow(Error("Could not set volume/gain properties")); |
| 134 return RespondNow(Error("Could not set properties")); | 141 |
| 142 if (params->properties.is_muted.get() && |
| 143 !service->SetMuteForDevice(params->id, *params->properties.is_muted)) { |
| 144 return RespondNow(Error("Could not set mute property.")); |
| 145 } |
| 146 |
| 147 return RespondNow(NoArguments()); |
| 148 } |
| 149 |
| 150 /////////////////////////////////////////////////////////////////////////////// |
| 151 |
| 152 ExtensionFunction::ResponseAction AudioSetMuteFunction::Run() { |
| 153 std::unique_ptr<audio::SetMute::Params> params( |
| 154 audio::SetMute::Params::Create(*args_)); |
| 155 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 156 |
| 157 AudioService* service = |
| 158 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 159 DCHECK(service); |
| 160 |
| 161 if (!service->SetMute(params->stream_type == audio::STREAM_TYPE_INPUT, |
| 162 params->value)) { |
| 163 return RespondNow(Error("Could not set mute state.")); |
| 135 } | 164 } |
| 136 return RespondNow(NoArguments()); | 165 return RespondNow(NoArguments()); |
| 137 } | 166 } |
| 138 | 167 |
| 139 /////////////////////////////////////////////////////////////////////////////// | 168 /////////////////////////////////////////////////////////////////////////////// |
| 140 | 169 |
| 170 ExtensionFunction::ResponseAction AudioGetMuteFunction::Run() { |
| 171 std::unique_ptr<audio::GetMute::Params> params( |
| 172 audio::GetMute::Params::Create(*args_)); |
| 173 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 174 |
| 175 AudioService* service = |
| 176 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 177 DCHECK(service); |
| 178 |
| 179 bool value = false; |
| 180 if (!service->GetMute(params->stream_type == audio::STREAM_TYPE_INPUT, |
| 181 &value)) { |
| 182 return RespondNow(Error("Could not get mute state.")); |
| 183 } |
| 184 return RespondNow(ArgumentList(audio::GetMute::Results::Create(value))); |
| 185 } |
| 186 |
| 141 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |