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[] = ...@@ -70,7 +70,10 @@ constexpr char kThrottledErrorDescription[] =
AwContentRendererClient::AwContentRendererClient() {} AwContentRendererClient::AwContentRendererClient() {}
AwContentRendererClient::~AwContentRendererClient() {} AwContentRendererClient::~AwContentRendererClient() {
DCHECK(!render_thread_connector_for_io_thread_ ||
!render_thread_connector_for_io_thread_->IsBound());
}
void AwContentRendererClient::RenderThreadStarted() { void AwContentRendererClient::RenderThreadStarted() {
RenderThread* thread = RenderThread::Get(); RenderThread* thread = RenderThread::Get();
...@@ -79,6 +82,9 @@ void AwContentRendererClient::RenderThreadStarted() { ...@@ -79,6 +82,9 @@ void AwContentRendererClient::RenderThreadStarted() {
visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); 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>(); auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(visited_link_slave_->GetBindCallback(), registry->AddInterface(visited_link_slave_->GetBindCallback(),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
...@@ -265,13 +271,31 @@ void AwContentRendererClient::AddSupportedKeySystems( ...@@ -265,13 +271,31 @@ void AwContentRendererClient::AddSupportedKeySystems(
std::unique_ptr<content::WebSocketHandshakeThrottleProvider> std::unique_ptr<content::WebSocketHandshakeThrottleProvider>
AwContentRendererClient::CreateWebSocketHandshakeThrottleProvider() { 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> std::unique_ptr<content::URLLoaderThrottleProvider>
AwContentRendererClient::CreateURLLoaderThrottleProvider( AwContentRendererClient::CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) { 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( void AwContentRendererClient::GetInterface(
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
class SpellCheck; class SpellCheck;
#endif #endif
namespace service_manager {
class Connector;
}
namespace visitedlink { namespace visitedlink {
class VisitedLinkSlave; class VisitedLinkSlave;
} }
...@@ -70,6 +74,12 @@ class AwContentRendererClient : public content::ContentRendererClient, ...@@ -70,6 +74,12 @@ class AwContentRendererClient : public content::ContentRendererClient,
std::unique_ptr<AwRenderThreadObserver> aw_render_thread_observer_; std::unique_ptr<AwRenderThreadObserver> aw_render_thread_observer_;
std::unique_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_; 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) #if BUILDFLAG(ENABLE_SPELLCHECK)
std::unique_ptr<SpellCheck> spellcheck_; std::unique_ptr<SpellCheck> spellcheck_;
#endif #endif
......
...@@ -17,12 +17,13 @@ ...@@ -17,12 +17,13 @@
namespace android_webview { namespace android_webview {
AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider( AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider(
service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type) content::URLLoaderThrottleProviderType type)
: type_(type) { : type_(type) {
DCHECK(connector);
DETACH_FROM_THREAD(thread_checker_); DETACH_FROM_THREAD(thread_checker_);
content::RenderThread::Get()->GetConnector()->BindInterface( connector->BindInterface(content::mojom::kBrowserServiceName,
content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_)); mojo::MakeRequest(&safe_browsing_info_));
} }
......
...@@ -9,13 +9,17 @@ ...@@ -9,13 +9,17 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h" #include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "content/public/renderer/url_loader_throttle_provider.h" #include "content/public/renderer/url_loader_throttle_provider.h"
namespace service_manager {
class Connector;
}
namespace android_webview { namespace android_webview {
// Instances must be constructed on the render thread, and then used and // 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. // destructed on a single thread, which can be different from the render thread.
class AwURLLoaderThrottleProvider : public content::URLLoaderThrottleProvider { class AwURLLoaderThrottleProvider : public content::URLLoaderThrottleProvider {
public: public:
explicit AwURLLoaderThrottleProvider( AwURLLoaderThrottleProvider(service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type); content::URLLoaderThrottleProviderType type);
~AwURLLoaderThrottleProvider() override; ~AwURLLoaderThrottleProvider() override;
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
namespace android_webview { namespace android_webview {
AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider() { AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider(
service_manager::Connector* connector) {
DCHECK(connector);
DETACH_FROM_THREAD(thread_checker_); DETACH_FROM_THREAD(thread_checker_);
content::RenderThread::Get()->GetConnector()->BindInterface(
content::mojom::kBrowserServiceName, connector->BindInterface(content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_)); mojo::MakeRequest(&safe_browsing_info_));
} }
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include "components/safe_browsing/common/safe_browsing.mojom.h" #include "components/safe_browsing/common/safe_browsing.mojom.h"
#include "content/public/renderer/websocket_handshake_throttle_provider.h" #include "content/public/renderer/websocket_handshake_throttle_provider.h"
namespace service_manager {
class Connector;
}
namespace android_webview { namespace android_webview {
// This must be constructed on the render thread, and then used and destructed // This must be constructed on the render thread, and then used and destructed
...@@ -19,7 +23,7 @@ namespace android_webview { ...@@ -19,7 +23,7 @@ namespace android_webview {
class AwWebSocketHandshakeThrottleProvider final class AwWebSocketHandshakeThrottleProvider final
: public content::WebSocketHandshakeThrottleProvider { : public content::WebSocketHandshakeThrottleProvider {
public: public:
AwWebSocketHandshakeThrottleProvider(); AwWebSocketHandshakeThrottleProvider(service_manager::Connector* connector);
~AwWebSocketHandshakeThrottleProvider() override; ~AwWebSocketHandshakeThrottleProvider() override;
// Implements content::WebSocketHandshakeThrottleProvider. // 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