Commit 92734c6d authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

android_webview: Clone service_manager::Connector for the IO thread

This is the same as crrev.com/c/1724754 but for android webview.
We need a didicated connector for the IO thread to create
{URLLoader,WebSocketHandshake}ThrottleProviders.

Bug: 989781
Change-Id: Ia0c883d243e8f856ede2d2747e124b80c2253dec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760646Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688510}
parent 45bcab0c
......@@ -70,7 +70,10 @@ constexpr char kThrottledErrorDescription[] =
AwContentRendererClient::AwContentRendererClient() {}
AwContentRendererClient::~AwContentRendererClient() {}
AwContentRendererClient::~AwContentRendererClient() {
DCHECK(!render_thread_connector_for_io_thread_ ||
!render_thread_connector_for_io_thread_->IsBound());
}
void AwContentRendererClient::RenderThreadStarted() {
RenderThread* thread = RenderThread::Get();
......@@ -79,6 +82,9 @@ void AwContentRendererClient::RenderThreadStarted() {
visited_link_slave_.reset(new visitedlink::VisitedLinkSlave);
io_thread_task_runner_ = thread->GetIOTaskRunner();
render_thread_connector_for_io_thread_ = thread->GetConnector()->Clone();
auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(visited_link_slave_->GetBindCallback(),
base::ThreadTaskRunnerHandle::Get());
......@@ -265,13 +271,31 @@ void AwContentRendererClient::AddSupportedKeySystems(
std::unique_ptr<content::WebSocketHandshakeThrottleProvider>
AwContentRendererClient::CreateWebSocketHandshakeThrottleProvider() {
return std::make_unique<AwWebSocketHandshakeThrottleProvider>();
if (content::RenderThread::Get()) {
return std::make_unique<AwWebSocketHandshakeThrottleProvider>(
content::RenderThread::Get()->GetConnector());
}
if (io_thread_task_runner_->BelongsToCurrentThread()) {
return std::make_unique<AwWebSocketHandshakeThrottleProvider>(
render_thread_connector_for_io_thread_.get());
}
NOTREACHED();
return nullptr;
}
std::unique_ptr<content::URLLoaderThrottleProvider>
AwContentRendererClient::CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) {
return std::make_unique<AwURLLoaderThrottleProvider>(provider_type);
if (content::RenderThread::Get()) {
return std::make_unique<AwURLLoaderThrottleProvider>(
content::RenderThread::Get()->GetConnector(), provider_type);
}
if (io_thread_task_runner_->BelongsToCurrentThread()) {
return std::make_unique<AwURLLoaderThrottleProvider>(
render_thread_connector_for_io_thread_.get(), provider_type);
}
NOTREACHED();
return nullptr;
}
void AwContentRendererClient::GetInterface(
......
......@@ -19,6 +19,10 @@
class SpellCheck;
#endif
namespace service_manager {
class Connector;
}
namespace visitedlink {
class VisitedLinkSlave;
}
......@@ -70,6 +74,12 @@ class AwContentRendererClient : public content::ContentRendererClient,
std::unique_ptr<AwRenderThreadObserver> aw_render_thread_observer_;
std::unique_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
// These are initialized in RenderThreadStarted() and used to create throttle
// providers on the IO thread.
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
std::unique_ptr<service_manager::Connector>
render_thread_connector_for_io_thread_;
#if BUILDFLAG(ENABLE_SPELLCHECK)
std::unique_ptr<SpellCheck> spellcheck_;
#endif
......
......@@ -17,13 +17,14 @@
namespace android_webview {
AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider(
service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type)
: type_(type) {
DCHECK(connector);
DETACH_FROM_THREAD(thread_checker_);
content::RenderThread::Get()->GetConnector()->BindInterface(
content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_));
connector->BindInterface(content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_));
}
AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider(
......
......@@ -9,14 +9,18 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "content/public/renderer/url_loader_throttle_provider.h"
namespace service_manager {
class Connector;
}
namespace android_webview {
// Instances must be constructed on the render thread, and then used and
// destructed on a single thread, which can be different from the render thread.
class AwURLLoaderThrottleProvider : public content::URLLoaderThrottleProvider {
public:
explicit AwURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType type);
AwURLLoaderThrottleProvider(service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type);
~AwURLLoaderThrottleProvider() override;
......
......@@ -17,11 +17,13 @@
namespace android_webview {
AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider() {
AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider(
service_manager::Connector* connector) {
DCHECK(connector);
DETACH_FROM_THREAD(thread_checker_);
content::RenderThread::Get()->GetConnector()->BindInterface(
content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_));
connector->BindInterface(content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_));
}
AwWebSocketHandshakeThrottleProvider::~AwWebSocketHandshakeThrottleProvider() {
......
......@@ -12,6 +12,10 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "content/public/renderer/websocket_handshake_throttle_provider.h"
namespace service_manager {
class Connector;
}
namespace android_webview {
// This must be constructed on the render thread, and then used and destructed
......@@ -19,7 +23,7 @@ namespace android_webview {
class AwWebSocketHandshakeThrottleProvider final
: public content::WebSocketHandshakeThrottleProvider {
public:
AwWebSocketHandshakeThrottleProvider();
AwWebSocketHandshakeThrottleProvider(service_manager::Connector* connector);
~AwWebSocketHandshakeThrottleProvider() override;
// Implements content::WebSocketHandshakeThrottleProvider.
......
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