Commit aedd7d91 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

[Extensions Functions] Migrate webrtcAudioPrivate API to ExtensionFunction

Bug: 634140
Change-Id: I43c748a416ae83dc51394fd98c5e8ac7f4e4e6a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065769Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742996}
parent d8c30b96
......@@ -15,8 +15,8 @@
#include "base/task_runner_util.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/audio_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/media_device_id.h"
#include "content/public/browser/render_frame_host.h"
......@@ -123,7 +123,7 @@ std::string WebrtcAudioPrivateFunction::CalculateHMAC(
}
void WebrtcAudioPrivateFunction::InitDeviceIDSalt() {
device_id_salt_ = GetProfile()->GetMediaDeviceIDSalt();
device_id_salt_ = browser_context()->GetMediaDeviceIDSalt();
}
std::string WebrtcAudioPrivateFunction::device_id_salt() const {
......@@ -137,7 +137,7 @@ media::AudioSystem* WebrtcAudioPrivateFunction::GetAudioSystem() {
return audio_system_.get();
}
bool WebrtcAudioPrivateGetSinksFunction::RunAsync() {
ExtensionFunction::ResponseAction WebrtcAudioPrivateGetSinksFunction::Run() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
InitDeviceIDSalt();
GetAudioSystem()->GetDeviceDescriptions(
......@@ -145,7 +145,7 @@ bool WebrtcAudioPrivateGetSinksFunction::RunAsync() {
base::BindOnce(
&WebrtcAudioPrivateGetSinksFunction::ReceiveOutputDeviceDescriptions,
this));
return true;
return RespondLater();
}
void WebrtcAudioPrivateGetSinksFunction::ReceiveOutputDeviceDescriptions(
......@@ -159,8 +159,7 @@ void WebrtcAudioPrivateGetSinksFunction::ReceiveOutputDeviceDescriptions(
// TODO(joi): Add other parameters.
results->push_back(std::move(info));
}
SetResultList(wap::GetSinks::Results::Create(*results));
SendResponse(true);
Respond(ArgumentList(wap::GetSinks::Results::Create(*results)));
}
WebrtcAudioPrivateGetAssociatedSinkFunction::
......@@ -169,7 +168,8 @@ WebrtcAudioPrivateGetAssociatedSinkFunction::
WebrtcAudioPrivateGetAssociatedSinkFunction::
~WebrtcAudioPrivateGetAssociatedSinkFunction() {}
bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunAsync() {
ExtensionFunction::ResponseAction
WebrtcAudioPrivateGetAssociatedSinkFunction::Run() {
params_ = wap::GetAssociatedSink::Params::Create(*args_);
DCHECK_CURRENTLY_ON(BrowserThread::UI);
EXTENSION_FUNCTION_VALIDATE(params_.get());
......@@ -179,7 +179,7 @@ bool WebrtcAudioPrivateGetAssociatedSinkFunction::RunAsync() {
true, base::BindOnce(&WebrtcAudioPrivateGetAssociatedSinkFunction::
ReceiveInputDeviceDescriptions,
this));
return true;
return RespondLater();
}
void WebrtcAudioPrivateGetAssociatedSinkFunction::
......@@ -224,13 +224,13 @@ void WebrtcAudioPrivateGetAssociatedSinkFunction::CalculateHMACAndReply(
void WebrtcAudioPrivateGetAssociatedSinkFunction::Reply(
const std::string& associated_sink_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::string sink_id;
if (associated_sink_id == media::AudioDeviceDescription::kDefaultDeviceId) {
DVLOG(2) << "Got default ID, replacing with empty ID.";
SetResult(std::make_unique<base::Value>(""));
} else {
SetResult(std::make_unique<base::Value>(associated_sink_id));
sink_id = associated_sink_id;
}
SendResponse(true);
Respond(OneArgument(std::make_unique<base::Value>(sink_id)));
}
} // namespace extensions
......@@ -12,11 +12,11 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/system/system_monitor.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/common/extensions/api/webrtc_audio_private.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_context.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_function.h"
#include "media/audio/audio_device_description.h"
namespace media {
......@@ -52,7 +52,7 @@ class WebrtcAudioPrivateEventService
// Common base for WebrtcAudioPrivate functions, that provides a
// couple of optionally-used common implementations.
class WebrtcAudioPrivateFunction : public ChromeAsyncExtensionFunction {
class WebrtcAudioPrivateFunction : public ExtensionFunction {
protected:
WebrtcAudioPrivateFunction();
~WebrtcAudioPrivateFunction() override;
......@@ -88,7 +88,7 @@ class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction {
DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks",
WEBRTC_AUDIO_PRIVATE_GET_SINKS)
bool RunAsync() override;
ResponseAction Run() override;
// Receives output device descriptions, calculates HMACs for them and sends
// the response.
......@@ -109,7 +109,7 @@ class WebrtcAudioPrivateGetAssociatedSinkFunction
WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK)
// UI thread: Entry point, posts GetInputDeviceDescriptions() to IO thread.
bool RunAsync() override;
ResponseAction Run() override;
// Receives the input device descriptions, looks up the raw source device ID
// basing on |params|, and requests the associated raw sink ID for it.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment