Commit 28032e00 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Clone service_manager::Connector for IO thread

URLLoaderThrottleProviderImpl and WebSocketHandshakeThrottleProviderImpl
used content::RenderThread::Get()->GetConnector() to connect mojo
interfaces. This prevented us from creating these throttle providers
on the IO thread. To allow these throttle providers can be constructed
without going to the main thread, create a clone of the main thread's
connector in ChromeContentRendererClient::RenderThreadStarted().
The cloned connector is bound to the IO thread and will be used
to create throttle providers for off-the-main-thread service worker
startup.

Bug: 989781
Change-Id: Ic4d20813e18c6238700545946cbcfd6f4534d974
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724754Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684169}
parent 57c1df38
...@@ -328,7 +328,10 @@ ChromeContentRendererClient::ChromeContentRendererClient() ...@@ -328,7 +328,10 @@ ChromeContentRendererClient::ChromeContentRendererClient()
#endif #endif
} }
ChromeContentRendererClient::~ChromeContentRendererClient() = default; ChromeContentRendererClient::~ChromeContentRendererClient() {
DCHECK(!render_thread_connector_for_io_thread_ ||
!render_thread_connector_for_io_thread_->IsBound());
}
void ChromeContentRendererClient::RenderThreadStarted() { void ChromeContentRendererClient::RenderThreadStarted() {
RenderThread* thread = RenderThread::Get(); RenderThread* thread = RenderThread::Get();
...@@ -353,6 +356,9 @@ void ChromeContentRendererClient::RenderThreadStarted() { ...@@ -353,6 +356,9 @@ void ChromeContentRendererClient::RenderThreadStarted() {
thread->GetIOTaskRunner(), thread->GetConnector()); thread->GetIOTaskRunner(), thread->GetConnector());
#endif #endif
io_thread_task_runner_ = thread->GetIOTaskRunner();
render_thread_connector_for_io_thread_ = thread->GetConnector()->Clone();
chrome_observer_.reset(new ChromeRenderThreadObserver()); chrome_observer_.reset(new ChromeRenderThreadObserver());
web_cache_impl_.reset(new web_cache::WebCacheImpl()); web_cache_impl_.reset(new web_cache::WebCacheImpl());
...@@ -1361,7 +1367,16 @@ ChromeRenderThreadObserver* ChromeContentRendererClient::GetChromeObserver() ...@@ -1361,7 +1367,16 @@ ChromeRenderThreadObserver* ChromeContentRendererClient::GetChromeObserver()
std::unique_ptr<content::WebSocketHandshakeThrottleProvider> std::unique_ptr<content::WebSocketHandshakeThrottleProvider>
ChromeContentRendererClient::CreateWebSocketHandshakeThrottleProvider() { ChromeContentRendererClient::CreateWebSocketHandshakeThrottleProvider() {
return std::make_unique<WebSocketHandshakeThrottleProviderImpl>(); if (content::RenderThread::Get()) {
return std::make_unique<WebSocketHandshakeThrottleProviderImpl>(
content::RenderThread::Get()->GetConnector());
}
if (io_thread_task_runner_->BelongsToCurrentThread()) {
return std::make_unique<WebSocketHandshakeThrottleProviderImpl>(
render_thread_connector_for_io_thread_.get());
}
NOTREACHED();
return nullptr;
} }
std::unique_ptr<blink::WebSpeechSynthesizer> std::unique_ptr<blink::WebSpeechSynthesizer>
...@@ -1570,7 +1585,16 @@ GURL ChromeContentRendererClient::OverrideFlashEmbedWithHTML(const GURL& url) { ...@@ -1570,7 +1585,16 @@ GURL ChromeContentRendererClient::OverrideFlashEmbedWithHTML(const GURL& url) {
std::unique_ptr<content::URLLoaderThrottleProvider> std::unique_ptr<content::URLLoaderThrottleProvider>
ChromeContentRendererClient::CreateURLLoaderThrottleProvider( ChromeContentRendererClient::CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) { content::URLLoaderThrottleProviderType provider_type) {
return std::make_unique<URLLoaderThrottleProviderImpl>(provider_type, this); if (content::RenderThread::Get()) {
return std::make_unique<URLLoaderThrottleProviderImpl>(
content::RenderThread::Get()->GetConnector(), provider_type, this);
}
if (io_thread_task_runner_->BelongsToCurrentThread()) {
return std::make_unique<URLLoaderThrottleProviderImpl>(
render_thread_connector_for_io_thread_.get(), provider_type, this);
}
NOTREACHED();
return nullptr;
} }
blink::WebFrame* ChromeContentRendererClient::FindFrame( blink::WebFrame* ChromeContentRendererClient::FindFrame(
......
...@@ -295,6 +295,12 @@ class ChromeContentRendererClient ...@@ -295,6 +295,12 @@ class ChromeContentRendererClient
service_manager::BinderRegistry registry_; service_manager::BinderRegistry registry_;
// 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_;
DISALLOW_COPY_AND_ASSIGN(ChromeContentRendererClient); DISALLOW_COPY_AND_ASSIGN(ChromeContentRendererClient);
}; };
......
...@@ -112,19 +112,17 @@ void SetExtensionThrottleManagerTestPolicy( ...@@ -112,19 +112,17 @@ void SetExtensionThrottleManagerTestPolicy(
} // namespace } // namespace
URLLoaderThrottleProviderImpl::URLLoaderThrottleProviderImpl( URLLoaderThrottleProviderImpl::URLLoaderThrottleProviderImpl(
service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type, content::URLLoaderThrottleProviderType type,
ChromeContentRendererClient* chrome_content_renderer_client) ChromeContentRendererClient* chrome_content_renderer_client)
: type_(type), : type_(type),
chrome_content_renderer_client_(chrome_content_renderer_client) { chrome_content_renderer_client_(chrome_content_renderer_client) {
DETACH_FROM_THREAD(thread_checker_); DETACH_FROM_THREAD(thread_checker_);
connector->BindInterface(content::mojom::kBrowserServiceName,
content::RenderThread::Get()->GetConnector()->BindInterface(
content::mojom::kBrowserServiceName,
mojo::MakeRequest(&safe_browsing_info_)); mojo::MakeRequest(&safe_browsing_info_));
if (data_reduction_proxy::params::IsEnabledWithNetworkService()) { if (data_reduction_proxy::params::IsEnabledWithNetworkService()) {
content::RenderThread::Get()->GetConnector()->BindInterface( connector->BindInterface(content::mojom::kBrowserServiceName,
content::mojom::kBrowserServiceName,
mojo::MakeRequest(&data_reduction_proxy_info_)); mojo::MakeRequest(&data_reduction_proxy_info_));
} }
} }
......
...@@ -22,6 +22,10 @@ namespace data_reduction_proxy { ...@@ -22,6 +22,10 @@ namespace data_reduction_proxy {
class DataReductionProxyThrottleManager; class DataReductionProxyThrottleManager;
} }
namespace service_manager {
class Connector;
}
class ChromeContentRendererClient; class ChromeContentRendererClient;
// Instances must be constructed on the render thread, and then used and // Instances must be constructed on the render thread, and then used and
...@@ -30,6 +34,7 @@ class URLLoaderThrottleProviderImpl ...@@ -30,6 +34,7 @@ class URLLoaderThrottleProviderImpl
: public content::URLLoaderThrottleProvider { : public content::URLLoaderThrottleProvider {
public: public:
URLLoaderThrottleProviderImpl( URLLoaderThrottleProviderImpl(
service_manager::Connector* connector,
content::URLLoaderThrottleProviderType type, content::URLLoaderThrottleProviderType type,
ChromeContentRendererClient* chrome_content_renderer_client); ChromeContentRendererClient* chrome_content_renderer_client);
......
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/platform/websocket_handshake_throttle.h" #include "third_party/blink/public/platform/websocket_handshake_throttle.h"
WebSocketHandshakeThrottleProviderImpl:: WebSocketHandshakeThrottleProviderImpl::WebSocketHandshakeThrottleProviderImpl(
WebSocketHandshakeThrottleProviderImpl() { service_manager::Connector* 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_));
} }
......
...@@ -12,12 +12,17 @@ ...@@ -12,12 +12,17 @@
#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;
}
// 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
// on a single thread, which can be different from the render thread. // on a single thread, which can be different from the render thread.
class WebSocketHandshakeThrottleProviderImpl final class WebSocketHandshakeThrottleProviderImpl final
: public content::WebSocketHandshakeThrottleProvider { : public content::WebSocketHandshakeThrottleProvider {
public: public:
WebSocketHandshakeThrottleProviderImpl(); explicit WebSocketHandshakeThrottleProviderImpl(
service_manager::Connector* connector);
~WebSocketHandshakeThrottleProviderImpl() override; ~WebSocketHandshakeThrottleProviderImpl() 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