Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2912)

Unified Diff: chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc

Issue 940813003: Use a utility process for the Mojo v8 proxy resolver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-pac-in-process-enable
Patch Set: Address review comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc
diff --git a/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc b/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3eefea6484420135deb7fe4c9d90f262c7b869fa
--- /dev/null
+++ b/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/utility_process_mojo_proxy_resolver_factory.h"
+
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
+#include "content/public/common/service_registry.h"
+#include "net/proxy/mojo_proxy_resolver_factory.h"
+
+namespace chrome_browser_net {
+
+// static
+UtilityProcessMojoProxyResolverFactory*
+UtilityProcessMojoProxyResolverFactory::GetInstance() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ return Singleton<
+ UtilityProcessMojoProxyResolverFactory,
+ LeakySingletonTraits<UtilityProcessMojoProxyResolverFactory>>::get();
+}
+
+UtilityProcessMojoProxyResolverFactory::
+ UtilityProcessMojoProxyResolverFactory() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+}
+
+UtilityProcessMojoProxyResolverFactory::
+ ~UtilityProcessMojoProxyResolverFactory() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+}
+
+void UtilityProcessMojoProxyResolverFactory::CreateProcessAndConnect() {
+ DVLOG(1) << "Attempting to create utility process for proxy resolver";
+ content::UtilityProcessHost* utility_process_host =
+ content::UtilityProcessHost::Create(
eroman 2015/03/06 05:48:21 What is the lifetime of this process? It seems lik
Anand Mistry (off Chromium) 2015/03/10 07:24:23 Yes, for now. For other Mojo services, I'm plannin
eroman 2015/03/11 18:48:35 One way we could solve this is to make ProxyServic
+ scoped_refptr<content::UtilityProcessHostClient>(),
+ base::MessageLoopProxy::current().get());
+ bool process_started = utility_process_host->StartMojoMode();
+ if (process_started) {
+ content::ServiceRegistry* service_registry =
+ utility_process_host->GetServiceRegistry();
+ service_registry->ConnectToRemoteService(&resolver_factory_);
+ resolver_factory_.set_error_handler(this);
+ } else {
+ LOG(ERROR) << "Unable to connect to utility process";
+ }
+}
+
+void UtilityProcessMojoProxyResolverFactory::Create(
+ mojo::InterfaceRequest<net::interfaces::ProxyResolver> req,
+ net::interfaces::HostResolverPtr host_resolver) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ if (!resolver_factory_)
+ CreateProcessAndConnect();
+
+ if (!resolver_factory_) {
+ // If there's still no factory, then utility process creation failed so
+ // close |req|'s message pipe, which should cause a connection error.
+ req = nullptr;
+ return;
+ }
+ resolver_factory_->CreateResolver(req.Pass(), host_resolver.Pass());
+}
+
+void UtilityProcessMojoProxyResolverFactory::OnConnectionError() {
+ DVLOG(1) << "Disconnection from utility process detected";
+ resolver_factory_.reset();
+}
+
+} // namespace chrome_browser_net

Powered by Google App Engine
This is Rietveld 408576698