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

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 3 years, 10 months 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
« no previous file with comments | « extensions/browser/api/audio/audio_api.h ('k') | extensions/browser/api/audio/audio_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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.is_muted = 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 AudioService* service = 140 AudioService* service =
134 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); 141 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
135 DCHECK(service); 142 DCHECK(service);
136 143
137 int volume_value = params->properties.volume.get() ? 144 int volume_value = params->properties.volume.get() ?
138 *params->properties.volume : -1; 145 *params->properties.volume : -1;
139 146
140 int gain_value = params->properties.gain.get() ? 147 int gain_value = params->properties.gain.get() ?
141 *params->properties.gain : -1; 148 *params->properties.gain : -1;
142 149
143 if (!service->SetDeviceProperties(params->id, params->properties.is_muted, 150 if (!service->SetDeviceSoundLevel(params->id, volume_value, gain_value))
144 volume_value, gain_value)) { 151 return RespondNow(Error("Could not set volume/gain properties"));
145 return RespondNow(Error("Could not set properties")); 152
153 if (params->properties.is_muted.get() &&
154 !service->SetMuteForDevice(params->id, *params->properties.is_muted)) {
155 return RespondNow(Error("Could not set mute property."));
156 }
157
158 return RespondNow(NoArguments());
159 }
160
161 ///////////////////////////////////////////////////////////////////////////////
162
163 ExtensionFunction::ResponseAction AudioSetMuteFunction::Run() {
164 std::unique_ptr<audio::SetMute::Params> params(
165 audio::SetMute::Params::Create(*args_));
166 EXTENSION_FUNCTION_VALIDATE(params.get());
167
168 AudioService* service =
169 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
170 DCHECK(service);
171
172 if (!service->SetMute(params->stream_type == audio::STREAM_TYPE_INPUT,
173 params->is_muted)) {
174 return RespondNow(Error("Could not set mute state."));
146 } 175 }
147 return RespondNow(NoArguments()); 176 return RespondNow(NoArguments());
148 } 177 }
149 178
150 /////////////////////////////////////////////////////////////////////////////// 179 ///////////////////////////////////////////////////////////////////////////////
151 180
181 ExtensionFunction::ResponseAction AudioGetMuteFunction::Run() {
182 std::unique_ptr<audio::GetMute::Params> params(
183 audio::GetMute::Params::Create(*args_));
184 EXTENSION_FUNCTION_VALIDATE(params.get());
185
186 AudioService* service =
187 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
188 DCHECK(service);
189
190 bool value = false;
191 if (!service->GetMute(params->stream_type == audio::STREAM_TYPE_INPUT,
192 &value)) {
193 return RespondNow(Error("Could not get mute state."));
194 }
195 return RespondNow(ArgumentList(audio::GetMute::Results::Create(value)));
196 }
197
152 } // namespace extensions 198 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/audio/audio_api.h ('k') | extensions/browser/api/audio/audio_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698