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

Side by Side Diff: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc

Issue 2801853005: Create a private API for controlling WebRTC's AEC3 (Closed)
Patch Set: Fixing typo Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat e_api.h" 5 #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat e_api.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h"
13 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
14 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
17 #include "content/public/browser/media_device_id.h" 19 #include "content/public/browser/media_device_id.h"
18 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/event_router.h" 21 #include "extensions/browser/event_router.h"
20 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/error_utils.h" 23 #include "extensions/common/error_utils.h"
22 #include "extensions/common/permissions/permissions_data.h" 24 #include "extensions/common/permissions/permissions_data.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 212 }
211 213
212 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() { 214 void WebrtcAudioPrivateFunction::InitDeviceIDSalt() {
213 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt(); 215 device_id_salt_ = GetProfile()->GetResourceContext()->GetMediaDeviceIDSalt();
214 } 216 }
215 217
216 std::string WebrtcAudioPrivateFunction::device_id_salt() const { 218 std::string WebrtcAudioPrivateFunction::device_id_salt() const {
217 return device_id_salt_; 219 return device_id_salt_;
218 } 220 }
219 221
222 // TODO(hlundin): Stolen from WebrtcLoggingPrivateFunction.
223 // Consolidate and improve. http://crbug.com/710371
224 content::RenderProcessHost*
225 WebrtcAudioPrivateFunction::GetRenderProcessHostFromRequest(
226 const RequestInfo& request,
227 const std::string& security_origin) {
228 // If |guest_process_id| is defined, directly use this id to find the
229 // corresponding RenderProcessHost.
230 if (request.guest_process_id)
231 return content::RenderProcessHost::FromID(*request.guest_process_id);
232
233 // Otherwise, use the |tab_id|. If there's no |tab_id| and no
234 // |guest_process_id|, we can't look up the RenderProcessHost.
235 if (!request.tab_id) {
236 error_ = "No tab ID or guest process ID specified.";
237 return nullptr;
238 }
239
240 int tab_id = *request.tab_id;
241 content::WebContents* contents = nullptr;
242 if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, nullptr,
243 nullptr, &contents, nullptr)) {
244 error_ = extensions::ErrorUtils::FormatErrorMessage(
245 extensions::tabs_constants::kTabNotFoundError,
246 base::IntToString(tab_id));
247 return nullptr;
248 }
249 GURL expected_origin = contents->GetLastCommittedURL().GetOrigin();
250 if (expected_origin.spec() != security_origin) {
251 error_ = base::StringPrintf(
252 "Invalid security origin. Expected=%s, actual=%s",
253 expected_origin.spec().c_str(), security_origin.c_str());
254 return nullptr;
255 }
256 return contents->GetRenderProcessHost();
257 }
258
220 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() { 259 bool WebrtcAudioPrivateGetSinksFunction::RunAsync() {
221 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
222 261
223 InitDeviceIDSalt(); 262 InitDeviceIDSalt();
224 GetOutputDeviceDescriptions(); 263 GetOutputDeviceDescriptions();
225 264
226 return true; 265 return true;
227 } 266 }
228 267
229 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceDescriptions( 268 void WebrtcAudioPrivateGetSinksFunction::OnOutputDeviceDescriptions(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) { 536 if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) {
498 DVLOG(2) << "Got default ID, replacing with empty ID."; 537 DVLOG(2) << "Got default ID, replacing with empty ID.";
499 results_ = wap::GetAssociatedSink::Results::Create(""); 538 results_ = wap::GetAssociatedSink::Results::Create("");
500 } else { 539 } else {
501 results_ = wap::GetAssociatedSink::Results::Create(associated_sink_id); 540 results_ = wap::GetAssociatedSink::Results::Create(associated_sink_id);
502 } 541 }
503 542
504 SendResponse(true); 543 SendResponse(true);
505 } 544 }
506 545
546 WebrtcAudioPrivateSetAudioExperimentsFunction::
547 WebrtcAudioPrivateSetAudioExperimentsFunction() {}
548
549 WebrtcAudioPrivateSetAudioExperimentsFunction::
550 ~WebrtcAudioPrivateSetAudioExperimentsFunction() {}
551
552 bool WebrtcAudioPrivateSetAudioExperimentsFunction::RunAsync() {
553 DCHECK_CURRENTLY_ON(BrowserThread::UI);
554 std::unique_ptr<wap::SetAudioExperiments::Params> params(
555 wap::SetAudioExperiments::Params::Create(*args_));
556 EXTENSION_FUNCTION_VALIDATE(params.get());
557
558 if (params->audio_experiments.enable_aec3.get()) {
559 content::RenderProcessHost* host = GetRenderProcessHostFromRequest(
560 params->request, params->security_origin);
561 if (!host) {
562 SendResponse(false);
563 return false;
564 }
565
566 host->SetEchoCanceller3(*params->audio_experiments.enable_aec3);
567 }
568
569 SendResponse(true);
570 return true;
571 }
572
507 } // namespace extensions 573 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698