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

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

Issue 2236703002: [Extensions] Convert some SyncExtensionFunctions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nulltpr Created 4 years, 4 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') | no next file » | 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 audio::OnDevicesChanged::Create(devices); 75 audio::OnDevicesChanged::Create(devices);
76 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, 76 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED,
77 audio::OnDevicesChanged::kEventName, 77 audio::OnDevicesChanged::kEventName,
78 std::move(args))); 78 std::move(args)));
79 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); 79 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
80 } 80 }
81 } 81 }
82 82
83 /////////////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////////////
84 84
85 bool AudioGetInfoFunction::RunSync() { 85 ExtensionFunction::ResponseAction AudioGetInfoFunction::Run() {
86 AudioService* service = 86 AudioService* service =
87 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); 87 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
88 DCHECK(service); 88 DCHECK(service);
89 OutputInfo output_info; 89 OutputInfo output_info;
90 InputInfo input_info; 90 InputInfo input_info;
91 if (!service->GetInfo(&output_info, &input_info)) { 91 if (!service->GetInfo(&output_info, &input_info)) {
92 SetError("Error occurred when querying audio device information."); 92 return RespondNow(
93 return false; 93 Error("Error occurred when querying audio device information."));
94 } 94 }
95 95
96 results_ = audio::GetInfo::Results::Create(output_info, input_info); 96 return RespondNow(
97 return true; 97 ArgumentList(audio::GetInfo::Results::Create(output_info, input_info)));
98 } 98 }
99 99
100 /////////////////////////////////////////////////////////////////////////////// 100 ///////////////////////////////////////////////////////////////////////////////
101 101
102 bool AudioSetActiveDevicesFunction::RunSync() { 102 ExtensionFunction::ResponseAction AudioSetActiveDevicesFunction::Run() {
103 std::unique_ptr<audio::SetActiveDevices::Params> params( 103 std::unique_ptr<audio::SetActiveDevices::Params> params(
104 audio::SetActiveDevices::Params::Create(*args_)); 104 audio::SetActiveDevices::Params::Create(*args_));
105 EXTENSION_FUNCTION_VALIDATE(params.get()); 105 EXTENSION_FUNCTION_VALIDATE(params.get());
106 106
107 AudioService* service = 107 AudioService* service =
108 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); 108 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
109 DCHECK(service); 109 DCHECK(service);
110 110
111 service->SetActiveDevices(params->ids); 111 service->SetActiveDevices(params->ids);
112 return true; 112 return RespondNow(NoArguments());
113 } 113 }
114 114
115 /////////////////////////////////////////////////////////////////////////////// 115 ///////////////////////////////////////////////////////////////////////////////
116 116
117 bool AudioSetPropertiesFunction::RunSync() { 117 ExtensionFunction::ResponseAction AudioSetPropertiesFunction::Run() {
118 std::unique_ptr<audio::SetProperties::Params> params( 118 std::unique_ptr<audio::SetProperties::Params> params(
119 audio::SetProperties::Params::Create(*args_)); 119 audio::SetProperties::Params::Create(*args_));
120 EXTENSION_FUNCTION_VALIDATE(params.get()); 120 EXTENSION_FUNCTION_VALIDATE(params.get());
121 121
122 AudioService* service = 122 AudioService* service =
123 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); 123 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService();
124 DCHECK(service); 124 DCHECK(service);
125 125
126 int volume_value = params->properties.volume.get() ? 126 int volume_value = params->properties.volume.get() ?
127 *params->properties.volume : -1; 127 *params->properties.volume : -1;
128 128
129 int gain_value = params->properties.gain.get() ? 129 int gain_value = params->properties.gain.get() ?
130 *params->properties.gain : -1; 130 *params->properties.gain : -1;
131 131
132 if (!service->SetDeviceProperties(params->id, 132 if (!service->SetDeviceProperties(params->id, params->properties.is_muted,
133 params->properties.is_muted, 133 volume_value, gain_value)) {
134 volume_value, 134 return RespondNow(Error("Could not set properties"));
135 gain_value)) 135 }
136 return false; 136 return RespondNow(NoArguments());
137 else
138 return true;
139 } 137 }
140 138
141 /////////////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////////////
142 140
143 } // namespace extensions 141 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/audio/audio_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698