Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: extensions/browser/api/audio/audio_api.cc

Issue 2578473002: chrome.audio API: treat mute as system wide property (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 deprecated onMuteChanged event.
67 std::move(args))); 67 std::unique_ptr<base::ListValue> deprecated_event_args =
68 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); 68 audio::OnMuteChanged::Create(is_input, is_muted);
69 } 69 std::unique_ptr<Event> deprecated_event(
70 new Event(events::AUDIO_ON_MUTE_CHANGED, audio::OnMuteChanged::kEventName,
71 std::move(deprecated_event_args)));
72 event_router->BroadcastEvent(std::move(deprecated_event));
73
74 // Dispatch onMuteStateChanged event.
75 audio::MuteStateChangedEvent mute_event;
76 mute_event.stream_type =
77 is_input ? audio::STREAM_TYPE_INPUT : audio::STREAM_TYPE_OUTPUT;
78 mute_event.value = is_muted;
79 std::unique_ptr<base::ListValue> event_args =
80 audio::OnMuteStateChanged::Create(mute_event);
81 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_MUTE_STATE_CHANGED,
82 audio::OnMuteStateChanged::kEventName,
83 std::move(event_args)));
84 event_router->BroadcastEvent(std::move(event));
70 } 85 }
71 86
72 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { 87 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) {
73 if (EventRouter::Get(browser_context_)) { 88 if (EventRouter::Get(browser_context_)) {
74 std::unique_ptr<base::ListValue> args = 89 std::unique_ptr<base::ListValue> args =
75 audio::OnDevicesChanged::Create(devices); 90 audio::OnDevicesChanged::Create(devices);
76 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, 91 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED,
77 audio::OnDevicesChanged::kEventName, 92 audio::OnDevicesChanged::kEventName,
78 std::move(args))); 93 std::move(args)));
79 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); 94 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 AudioService* service = 137 AudioService* service =
123 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); 138 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
124 DCHECK(service); 139 DCHECK(service);
125 140
126 int volume_value = params->properties.volume.get() ? 141 int volume_value = params->properties.volume.get() ?
127 *params->properties.volume : -1; 142 *params->properties.volume : -1;
128 143
129 int gain_value = params->properties.gain.get() ? 144 int gain_value = params->properties.gain.get() ?
130 *params->properties.gain : -1; 145 *params->properties.gain : -1;
131 146
132 if (!service->SetDeviceProperties(params->id, params->properties.is_muted, 147 if (!service->SetDeviceSoundLevel(params->id, volume_value, gain_value))
133 volume_value, gain_value)) { 148 return RespondNow(Error("Could not set volume/gain properties"));
134 return RespondNow(Error("Could not set properties")); 149
150 if (params->properties.is_muted.get() &&
151 !service->SetMuteForDevice(params->id, *params->properties.is_muted)) {
152 return RespondNow(Error("Could not set mute property."));
153 }
154
155 return RespondNow(NoArguments());
156 }
157
158 ///////////////////////////////////////////////////////////////////////////////
159
160 ExtensionFunction::ResponseAction AudioSetMuteFunction::Run() {
161 std::unique_ptr<audio::SetMute::Params> params(
162 audio::SetMute::Params::Create(*args_));
163 EXTENSION_FUNCTION_VALIDATE(params.get());
164
165 AudioService* service =
166 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
167 DCHECK(service);
168
169 if (!service->SetMute(params->stream_type == audio::STREAM_TYPE_INPUT,
170 params->value)) {
171 return RespondNow(Error("Could not set mute state."));
135 } 172 }
136 return RespondNow(NoArguments()); 173 return RespondNow(NoArguments());
137 } 174 }
138 175
139 /////////////////////////////////////////////////////////////////////////////// 176 ///////////////////////////////////////////////////////////////////////////////
140 177
178 ExtensionFunction::ResponseAction AudioGetMuteFunction::Run() {
179 std::unique_ptr<audio::GetMute::Params> params(
180 audio::GetMute::Params::Create(*args_));
181 EXTENSION_FUNCTION_VALIDATE(params.get());
182
183 AudioService* service =
184 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
185 DCHECK(service);
186
187 bool value = false;
188 if (!service->GetMute(params->stream_type == audio::STREAM_TYPE_INPUT,
189 &value)) {
190 return RespondNow(Error("Could not get mute state."));
191 }
192 return RespondNow(ArgumentList(audio::GetMute::Results::Create(value)));
193 }
194
141 } // namespace extensions 195 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698