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

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

Issue 1076083002: Shut down proxy resolver utility processes when no longer needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-service-with-factory-restart
Patch Set: Created 5 years, 8 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
index a01ba16665b622c57a86d08d5ae1540272fdf288..a1a761622248370e37a6b149dc3dc152cb4a576b 100644
--- a/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc
+++ b/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc
@@ -14,6 +14,10 @@
#include "net/proxy/mojo_proxy_resolver_factory.h"
#include "ui/base/l10n/l10n_util.h"
+namespace {
+const int kUtilityProcessIdleTimeoutSeconds = 5;
+}
+
// static
UtilityProcessMojoProxyResolverFactory*
UtilityProcessMojoProxyResolverFactory::GetInstance() {
@@ -47,12 +51,14 @@ void UtilityProcessMojoProxyResolverFactory::CreateProcessAndConnect() {
utility_process_host->GetServiceRegistry();
service_registry->ConnectToRemoteService(&resolver_factory_);
resolver_factory_.set_error_handler(this);
+ weak_utility_process_host_ = utility_process_host->AsWeakPtr();
} else {
LOG(ERROR) << "Unable to connect to utility process";
}
}
-void UtilityProcessMojoProxyResolverFactory::Create(
+scoped_ptr<base::ScopedClosureRunner>
+UtilityProcessMojoProxyResolverFactory::Create(
mojo::InterfaceRequest<net::interfaces::ProxyResolver> req,
net::interfaces::HostResolverPtr host_resolver) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -63,12 +69,39 @@ void UtilityProcessMojoProxyResolverFactory::Create(
// 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;
+ return nullptr;
}
+ idle_timer_.Stop();
+ num_proxy_resolvers_++;
resolver_factory_->CreateResolver(req.Pass(), host_resolver.Pass());
+ return make_scoped_ptr(new base::ScopedClosureRunner(
+ base::Bind(&UtilityProcessMojoProxyResolverFactory::OnResolverDestroyed,
+ base::Unretained(this))));
}
void UtilityProcessMojoProxyResolverFactory::OnConnectionError() {
DVLOG(1) << "Disconnection from utility process detected";
resolver_factory_.reset();
}
+
+void UtilityProcessMojoProxyResolverFactory::OnResolverDestroyed() {
eroman 2015/05/02 02:22:31 The assumption is that this code always runs on a
Sam McNally 2015/05/04 06:17:23 Done.
+ DCHECK_GT(num_proxy_resolvers_, 0u);
+ if (--num_proxy_resolvers_ == 0) {
+ // When all proxy resolvers have been destroyed, the proxy resolver utility
+ // process is no longer needed. However, new proxy resolvers may be created
+ // shortly after being destroyed (e.g. due to a network change). If the
+ // utility process is shut down immediately, this would cause unnecessary
+ // process churn, so wait for an idle timeout before shutting down the
+ // proxy resolver utility process.
+ idle_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromSeconds(kUtilityProcessIdleTimeoutSeconds), this,
+ &UtilityProcessMojoProxyResolverFactory::OnIdleTimeout);
+ }
+}
+
+void UtilityProcessMojoProxyResolverFactory::OnIdleTimeout() {
+ delete weak_utility_process_host_.get();
+ weak_utility_process_host_.reset();
+ resolver_factory_.reset();
+}

Powered by Google App Engine
This is Rietveld 408576698