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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
diff --git a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
index baf803d0bb7d4bdabe86ab932f74c27d6af63844..9dd9e5d819267ff58e171f115d4db8b5587ebe1a 100644
--- a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
+++ b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
@@ -4,12 +4,14 @@
#include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h"
+#include <memory>
#include <utility>
#include <vector>
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_tab_util.h"
@@ -217,6 +219,45 @@ std::string WebrtcAudioPrivateFunction::device_id_salt() const {
return device_id_salt_;
}
+// TODO(hlundin): Stolen from WebrtcLoggingPrivateFunction. Maybe consolidate?
+content::RenderProcessHost* WebrtcAudioPrivateFunction::RphFromRequest(
+ const RequestInfo& request,
+ const std::string& security_origin) {
+ // If |guest_process_id| is defined, directly use this id to find the
+ // corresponding RenderProcessHost.
+ if (request.guest_process_id.get())
+ return content::RenderProcessHost::FromID(*request.guest_process_id);
+
+ // Otherwise, use the |tab_id|. If there's no |tab_id| and no
+ // |guest_process_id|, we can't look up the RenderProcessHost.
+ if (!request.tab_id.get()) {
+ error_ = "No tab ID or guest process ID specified.";
+ return nullptr;
+ }
+
+ int tab_id = *request.tab_id;
+ content::WebContents* contents = nullptr;
+ if (!ExtensionTabUtil::GetTabById(tab_id, GetProfile(), true, nullptr,
+ nullptr, &contents, nullptr)) {
+ error_ = extensions::ErrorUtils::FormatErrorMessage(
+ extensions::tabs_constants::kTabNotFoundError,
+ base::IntToString(tab_id));
+ return nullptr;
+ }
+ if (!contents) {
+ error_ = "Web contents for tab not found.";
+ return nullptr;
+ }
+ GURL expected_origin = contents->GetLastCommittedURL().GetOrigin();
+ if (expected_origin.spec() != security_origin) {
+ error_ = base::StringPrintf(
+ "Invalid security origin. Expected=%s, actual=%s",
+ expected_origin.spec().c_str(), security_origin.c_str());
+ return nullptr;
+ }
+ return contents->GetRenderProcessHost();
+}
+
bool WebrtcAudioPrivateGetSinksFunction::RunAsync() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -504,4 +545,28 @@ void WebrtcAudioPrivateGetAssociatedSinkFunction::OnHMACCalculated(
SendResponse(true);
}
+WebrtcAudioPrivateSetAudioExperimentsFunction::
+ WebrtcAudioPrivateSetAudioExperimentsFunction() {}
+
+WebrtcAudioPrivateSetAudioExperimentsFunction::
+ ~WebrtcAudioPrivateSetAudioExperimentsFunction() {}
+
+bool WebrtcAudioPrivateSetAudioExperimentsFunction::RunAsync() {
Henrik Grunell 2017/04/10 08:13:28 DCHECK_CURRENTLY_ON(BrowserThread::UI);
hlundin-chromium 2017/04/10 10:10:16 Done.
+ std::unique_ptr<wap::SetAudioExperiments::Params> params(
+ wap::SetAudioExperiments::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ if (params->audio_experiments.enable_aec3.get()) {
+ content::RenderProcessHost* host =
+ RphFromRequest(params->request, params->security_origin);
+ if (!host)
+ return false;
Henrik Grunell 2017/04/10 08:13:28 Also SendResponse(false);
hlundin-chromium 2017/04/10 10:10:16 Done.
+
+ host->SetEchoCanceller3(*params->audio_experiments.enable_aec3);
Henrik Grunell 2017/04/10 08:13:28 The optional callback in the interface is never us
hlundin-chromium 2017/04/10 10:10:16 It should probably be removed. Done.
Henrik Grunell 2017/04/10 12:33:47 Acknowledged.
+ }
+
+ SendResponse(true);
+ return true;
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698