Commit f664c15d authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Use appropriate task runners at RTCPeerConnection

This is part of efforts to replace base::ThreadTaskRunnerHandle::Get()
with other appropriate task runners in the renderer.

Bug: 786332
Change-Id: Ie55366522fb749fb895806b0ec423a22e9842330
Reviewed-on: https://chromium-review.googlesource.com/808093
Commit-Queue: Tommi <tommi@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarTommi <tommi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522043}
parent b304319f
......@@ -66,9 +66,8 @@ class RTCCertificateGeneratorRequest
DCHECK(main_thread_->BelongsToCurrentThread());
DCHECK(observer);
CertificateCallbackPtr transition(
observer.release(),
base::OnTaskRunnerDeleter(base::ThreadTaskRunnerHandle::Get()));
CertificateCallbackPtr transition(observer.release(),
base::OnTaskRunnerDeleter(main_thread_));
worker_thread_->PostTask(
FROM_HERE,
base::BindOnce(
......@@ -119,35 +118,36 @@ class RTCCertificateGeneratorRequest
void RTCCertificateGenerator::GenerateCertificate(
const blink::WebRTCKeyParams& key_params,
std::unique_ptr<blink::WebRTCCertificateCallback> observer) {
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
generateCertificateWithOptionalExpiration(
key_params, rtc::Optional<uint64_t>(), std::move(observer));
key_params, rtc::Optional<uint64_t>(), std::move(observer), task_runner);
}
void RTCCertificateGenerator::GenerateCertificateWithExpiration(
const blink::WebRTCKeyParams& key_params,
uint64_t expires_ms,
std::unique_ptr<blink::WebRTCCertificateCallback> observer) {
generateCertificateWithOptionalExpiration(
key_params, rtc::Optional<uint64_t>(expires_ms), std::move(observer));
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
generateCertificateWithOptionalExpiration(key_params,
rtc::Optional<uint64_t>(expires_ms),
std::move(observer), task_runner);
}
void RTCCertificateGenerator::generateCertificateWithOptionalExpiration(
const blink::WebRTCKeyParams& key_params,
const rtc::Optional<uint64_t>& expires_ms,
std::unique_ptr<blink::WebRTCCertificateCallback> observer) {
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK(IsSupportedKeyParams(key_params));
#if BUILDFLAG(ENABLE_WEBRTC)
const scoped_refptr<base::SingleThreadTaskRunner> main_thread =
base::ThreadTaskRunnerHandle::Get();
PeerConnectionDependencyFactory* pc_dependency_factory =
RenderThreadImpl::current()->GetPeerConnectionDependencyFactory();
pc_dependency_factory->EnsureInitialized();
scoped_refptr<RTCCertificateGeneratorRequest> request =
new RTCCertificateGeneratorRequest(
main_thread,
pc_dependency_factory->GetWebRtcWorkerThread());
task_runner, pc_dependency_factory->GetWebRtcWorkerThread());
request->GenerateCertificateAsync(
key_params, expires_ms, std::move(observer));
#else
......
......@@ -24,11 +24,13 @@ class RTCCertificateGenerator : public blink::WebRTCCertificateGenerator {
// blink::WebRTCCertificateGenerator implementation.
void GenerateCertificate(
const blink::WebRTCKeyParams& key_params,
std::unique_ptr<blink::WebRTCCertificateCallback> observer) override;
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
void GenerateCertificateWithExpiration(
const blink::WebRTCKeyParams& key_params,
uint64_t expires_ms,
std::unique_ptr<blink::WebRTCCertificateCallback> observer) override;
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
bool IsSupportedKeyParams(const blink::WebRTCKeyParams& key_params) override;
std::unique_ptr<blink::WebRTCCertificate> FromPEM(
blink::WebString pem_private_key,
......@@ -38,7 +40,8 @@ class RTCCertificateGenerator : public blink::WebRTCCertificateGenerator {
void generateCertificateWithOptionalExpiration(
const blink::WebRTCKeyParams& key_params,
const rtc::Optional<uint64_t>& expires_ms,
std::unique_ptr<blink::WebRTCCertificateCallback> observer);
std::unique_ptr<blink::WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
DISALLOW_COPY_AND_ASSIGN(RTCCertificateGenerator);
};
......
......@@ -331,13 +331,15 @@ class TestWebRTCCertificateGenerator
: public blink::WebRTCCertificateGenerator {
void GenerateCertificate(
const blink::WebRTCKeyParams& key_params,
std::unique_ptr<blink::WebRTCCertificateCallback> callback) override {
std::unique_ptr<blink::WebRTCCertificateCallback> callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override {
NOTIMPLEMENTED();
}
void GenerateCertificateWithExpiration(
const blink::WebRTCKeyParams& key_params,
uint64_t expires_ms,
std::unique_ptr<blink::WebRTCCertificateCallback> callback) override {
std::unique_ptr<blink::WebRTCCertificateCallback> callback,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override {
NOTIMPLEMENTED();
}
bool IsSupportedKeyParams(const blink::WebRTCKeyParams& key_params) override {
......
......@@ -956,12 +956,16 @@ ScriptPromise RTCPeerConnection::generateCertificate(
// Generate certificate. The |certificateObserver| will resolve the promise
// asynchronously upon completion. The observer will manage its own
// destruction as well as the resolver's destruction.
scoped_refptr<WebTaskRunner> task_runner =
ExecutionContext::From(script_state)
->GetTaskRunner(blink::TaskType::kUnthrottled);
if (expires.IsNull()) {
certificate_generator->GenerateCertificate(key_params.Get(),
std::move(certificate_observer));
certificate_generator->GenerateCertificate(
key_params.Get(), std::move(certificate_observer), task_runner);
} else {
certificate_generator->GenerateCertificateWithExpiration(
key_params.Get(), expires.Get(), std::move(certificate_observer));
key_params.Get(), expires.Get(), std::move(certificate_observer),
task_runner);
}
return promise;
......
......@@ -38,6 +38,10 @@
#include <memory>
namespace base {
class SingleThreadTaskRunner;
}
namespace blink {
using WebRTCCertificateCallback =
......@@ -54,11 +58,13 @@ class WebRTCCertificateGenerator {
// completed.
virtual void GenerateCertificate(
const WebRTCKeyParams&,
std::unique_ptr<WebRTCCertificateCallback> observer) = 0;
std::unique_ptr<WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner>) = 0;
virtual void GenerateCertificateWithExpiration(
const WebRTCKeyParams&,
uint64_t expires_ms,
std::unique_ptr<WebRTCCertificateCallback> observer) = 0;
std::unique_ptr<WebRTCCertificateCallback> observer,
scoped_refptr<base::SingleThreadTaskRunner>) = 0;
// Determines if the parameters are supported by |GenerateCertificate|.
// For example, if the number of bits of some parameter is too small or too
......
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