summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 21:37:12 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 21:37:12 +0000
commit6104ea5d0b3eb19a923ae94a5f7fcae8e0e091e2 (patch)
tree93a11c09778f638718cd19be3249e54defd1f90f /chrome
parent418e953e7285de2f29f6523c741cbca951f26562 (diff)
downloadchromium_src-6104ea5d0b3eb19a923ae94a5f7fcae8e0e091e2.zip
chromium_src-6104ea5d0b3eb19a923ae94a5f7fcae8e0e091e2.tar.gz
chromium_src-6104ea5d0b3eb19a923ae94a5f7fcae8e0e091e2.tar.bz2
Stop refcounting ProxyService.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6873096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_util.cc1
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc1
-rw-r--r--chrome/browser/io_thread.cc13
-rw-r--r--chrome/browser/io_thread.h4
-rw-r--r--chrome/browser/memory_purger.cc1
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc1
-rw-r--r--chrome/browser/net/chrome_url_request_context.h9
-rw-r--r--chrome/browser/net/connection_tester.cc51
-rw-r--r--chrome/browser/net/connection_tester_unittest.cc9
-rw-r--r--chrome/browser/net/proxy_service_factory.cc1
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper.cc9
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper.h6
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper_unittest.cc3
-rw-r--r--chrome/browser/profiles/profile_io_data.cc4
-rw-r--r--chrome/browser/profiles/profile_io_data.h2
-rw-r--r--chrome/service/net/service_url_request_context.cc54
-rw-r--r--chrome/service/net/service_url_request_context.h7
17 files changed, 95 insertions, 81 deletions
diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc
index 89224ef..2291a37 100644
--- a/chrome/browser/automation/automation_util.cc
+++ b/chrome/browser/automation/automation_util.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/waitable_event.h"
#include "base/time.h"
#include "base/values.h"
#include "chrome/browser/automation/automation_provider.h"
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 5045ba9..cda8366 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -54,6 +54,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/cookie_store.h"
#include "net/proxy/proxy_config_service.h"
+#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "views/widget/widget_gtk.h"
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index fd3b443..faef46c 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -40,7 +40,6 @@
#include "net/base/host_resolver_impl.h"
#include "net/base/mapped_host_resolver.h"
#include "net/base/net_util.h"
-#include "net/proxy/proxy_config_service.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_auth_filter.h"
#include "net/http/http_auth_handler_factory.h"
@@ -49,7 +48,9 @@
#if defined(USE_NSS)
#include "net/ocsp/nss_ocsp.h"
#endif // defined(USE_NSS)
+#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
+#include "net/proxy/proxy_service.h"
#include "webkit/glue/webkit_glue.h"
namespace {
@@ -428,8 +429,8 @@ void IOThread::Init() {
globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
globals_->host_resolver.get()));
// For the ProxyScriptFetcher, we use a direct ProxyService.
- globals_->proxy_script_fetcher_proxy_service =
- net::ProxyService::CreateDirectWithNetLog(net_log_);
+ globals_->proxy_script_fetcher_proxy_service.reset(
+ net::ProxyService::CreateDirectWithNetLog(net_log_));
net::HttpNetworkSession::Params session_params;
session_params.host_resolver = globals_->host_resolver.get();
session_params.cert_verifier = globals_->cert_verifier.get();
@@ -625,16 +626,16 @@ void IOThread::ClearHostCache() {
void IOThread::InitSystemRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(!globals_->system_proxy_service);
+ DCHECK(!globals_->system_proxy_service.get());
DCHECK(system_proxy_config_service_.get());
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- globals_->system_proxy_service =
+ globals_->system_proxy_service.reset(
ProxyServiceFactory::CreateProxyService(
net_log_,
globals_->proxy_script_fetcher_context,
system_proxy_config_service_.release(),
- command_line);
+ command_line));
net::HttpNetworkSession::Params system_params;
system_params.host_resolver = globals_->host_resolver.get();
system_params.cert_verifier = globals_->cert_verifier.get();
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index 050067b..a989c93 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -59,16 +59,16 @@ class IOThread : public BrowserProcessSubThread {
scoped_ptr<net::DnsRRResolver> dnsrr_resolver;
scoped_refptr<net::SSLConfigService> ssl_config_service;
scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
- scoped_refptr<net::ProxyService> proxy_script_fetcher_proxy_service;
+ scoped_ptr<net::ProxyService> proxy_script_fetcher_proxy_service;
scoped_ptr<net::HttpTransactionFactory>
proxy_script_fetcher_http_transaction_factory;
scoped_ptr<net::FtpTransactionFactory>
proxy_script_fetcher_ftp_transaction_factory;
scoped_ptr<net::URLSecurityManager> url_security_manager;
scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context;
+ scoped_ptr<net::ProxyService> system_proxy_service;
scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
scoped_ptr<net::FtpTransactionFactory> system_ftp_transaction_factory;
- scoped_refptr<net::ProxyService> system_proxy_service;
// NOTE(willchan): This request context is unusable until a system
// SSLConfigService is provided that doesn't rely on
// Profiles. Do NOT use this yet.
diff --git a/chrome/browser/memory_purger.cc b/chrome/browser/memory_purger.cc
index 80a884e..241d0d0 100644
--- a/chrome/browser/memory_purger.cc
+++ b/chrome/browser/memory_purger.cc
@@ -20,6 +20,7 @@
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/common/notification_service.h"
#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 53d8490..c90a9d2 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -6,6 +6,7 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
+#include "base/synchronization/waitable_event.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/profiles/profile.h"
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index b8f1582..3bfeaf40 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -28,16 +28,19 @@
class ChromeURLDataManagerBackend;
class ChromeURLRequestContextFactory;
class IOThread;
+class PrefService;
+class Profile;
+class ProfileIOData;
+namespace base {
+class WaitableEvent;
+}
namespace net {
class DnsCertProvenanceChecker;
class NetworkDelegate;
}
-class PrefService;
namespace prerender {
class PrerenderManager;
}
-class Profile;
-class ProfileIOData;
// Subclass of net::URLRequestContext which can be used to store extra
// information for requests.
diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc
index e046ac1..47023e3 100644
--- a/chrome/browser/net/connection_tester.cc
+++ b/chrome/browser/net/connection_tester.cc
@@ -28,8 +28,10 @@
#include "net/http/http_network_session.h"
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
+#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_storage.h"
namespace {
@@ -42,62 +44,58 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
public:
explicit ExperimentURLRequestContext(
net::URLRequestContext* proxy_request_context)
- : proxy_request_context_(proxy_request_context) {}
+ : proxy_request_context_(proxy_request_context),
+ ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {}
int Init(const ConnectionTester::Experiment& experiment) {
int rv;
// Create a custom HostResolver for this experiment.
- net::HostResolver* host_resolver_tmp = NULL;
+ scoped_ptr<net::HostResolver> host_resolver_tmp;
rv = CreateHostResolver(experiment.host_resolver_experiment,
&host_resolver_tmp);
if (rv != net::OK)
return rv; // Failure.
- set_host_resolver(host_resolver_tmp);
+ storage_.set_host_resolver(host_resolver_tmp.release());
// Create a custom ProxyService for this this experiment.
- scoped_refptr<net::ProxyService> proxy_service_tmp = NULL;
+ scoped_ptr<net::ProxyService> proxy_service_tmp;
rv = CreateProxyService(experiment.proxy_settings_experiment,
&proxy_service_tmp);
if (rv != net::OK)
return rv; // Failure.
- set_proxy_service(proxy_service_tmp);
+ storage_.set_proxy_service(proxy_service_tmp.release());
// The rest of the dependencies are standard, and don't depend on the
// experiment being run.
- set_cert_verifier(new net::CertVerifier);
- set_dnsrr_resolver(new net::DnsRRResolver);
- set_ftp_transaction_factory(new net::FtpNetworkLayer(host_resolver_tmp));
- set_ssl_config_service(new net::SSLConfigServiceDefaults);
- set_http_auth_handler_factory(net::HttpAuthHandlerFactory::CreateDefault(
- host_resolver_tmp));
+ storage_.set_cert_verifier(new net::CertVerifier);
+ storage_.set_dnsrr_resolver(new net::DnsRRResolver);
+ storage_.set_ftp_transaction_factory(
+ new net::FtpNetworkLayer(host_resolver()));
+ storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
+ storage_.set_http_auth_handler_factory(
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
net::HttpNetworkSession::Params session_params;
- session_params.host_resolver = host_resolver_tmp;
+ session_params.host_resolver = host_resolver();
session_params.dnsrr_resolver = dnsrr_resolver();
session_params.cert_verifier = cert_verifier();
- session_params.proxy_service = proxy_service_tmp;
+ session_params.proxy_service = proxy_service();
session_params.http_auth_handler_factory = http_auth_handler_factory();
session_params.ssl_config_service = ssl_config_service();
scoped_refptr<net::HttpNetworkSession> network_session(
new net::HttpNetworkSession(session_params));
- set_http_transaction_factory(new net::HttpCache(
+ storage_.set_http_transaction_factory(new net::HttpCache(
network_session,
net::HttpCache::DefaultBackend::InMemory(0)));
// In-memory cookie store.
- set_cookie_store(new net::CookieMonster(NULL, NULL));
+ storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
return net::OK;
}
protected:
virtual ~ExperimentURLRequestContext() {
- delete ftp_transaction_factory();
- delete http_transaction_factory();
- delete http_auth_handler_factory();
- delete dnsrr_resolver();
- delete cert_verifier();
- delete host_resolver();
}
private:
@@ -106,13 +104,13 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
// error code.
int CreateHostResolver(
ConnectionTester::HostResolverExperiment experiment,
- net::HostResolver** host_resolver) {
+ scoped_ptr<net::HostResolver>* host_resolver) {
// Create a vanilla HostResolver that disables caching.
const size_t kMaxJobs = 50u;
net::HostResolverImpl* impl =
new net::HostResolverImpl(NULL, NULL, kMaxJobs, NULL);
- *host_resolver = impl;
+ host_resolver->reset(impl);
// Modify it slightly based on the experiment being run.
switch (experiment) {
@@ -170,7 +168,7 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
// error code.
int CreateProxyService(
ConnectionTester::ProxySettingsExperiment experiment,
- scoped_refptr<net::ProxyService>* proxy_service) {
+ scoped_ptr<net::ProxyService>* proxy_service) {
// Create an appropriate proxy config service.
scoped_ptr<net::ProxyConfigService> config_service;
int rv = CreateProxyConfigService(experiment, &config_service);
@@ -184,12 +182,12 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
return net::ERR_NOT_IMPLEMENTED;
}
- *proxy_service = net::ProxyService::CreateUsingV8ProxyResolver(
+ proxy_service->reset(net::ProxyService::CreateUsingV8ProxyResolver(
config_service.release(),
0u,
new net::ProxyScriptFetcherImpl(proxy_request_context_),
host_resolver(),
- NULL);
+ NULL));
return net::OK;
}
@@ -235,6 +233,7 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
}
const scoped_refptr<net::URLRequestContext> proxy_request_context_;
+ net::URLRequestContextStorage storage_;
};
} // namespace
diff --git a/chrome/browser/net/connection_tester_unittest.cc b/chrome/browser/net/connection_tester_unittest.cc
index 4192495..457b850 100644
--- a/chrome/browser/net/connection_tester_unittest.cc
+++ b/chrome/browser/net/connection_tester_unittest.cc
@@ -16,6 +16,7 @@
#include "net/http/http_network_layer.h"
#include "net/http/http_network_session.h"
#include "net/proxy/proxy_config_service_fixed.h"
+#include "net/proxy/proxy_service.h"
#include "net/test/test_server.h"
#include "net/url_request/url_request_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -105,7 +106,7 @@ class ConnectionTesterTest : public PlatformTest {
net::MockHostResolver host_resolver_;
net::CertVerifier cert_verifier_;
net::DnsRRResolver dnsrr_resolver_;
- scoped_refptr<net::ProxyService> proxy_service_;
+ scoped_ptr<net::ProxyService> proxy_service_;
scoped_refptr<net::SSLConfigService> ssl_config_service_;
scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_;
net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_;
@@ -118,8 +119,8 @@ class ConnectionTesterTest : public PlatformTest {
proxy_script_fetcher_context_->set_dnsrr_resolver(&dnsrr_resolver_);
proxy_script_fetcher_context_->set_http_auth_handler_factory(
&http_auth_handler_factory_);
- proxy_service_ = net::ProxyService::CreateDirect();
- proxy_script_fetcher_context_->set_proxy_service(proxy_service_);
+ proxy_service_.reset(net::ProxyService::CreateDirect());
+ proxy_script_fetcher_context_->set_proxy_service(proxy_service_.get());
ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService();
net::HttpNetworkSession::Params session_params;
session_params.host_resolver = &host_resolver_;
@@ -127,7 +128,7 @@ class ConnectionTesterTest : public PlatformTest {
session_params.dnsrr_resolver = &dnsrr_resolver_;
session_params.http_auth_handler_factory = &http_auth_handler_factory_;
session_params.ssl_config_service = ssl_config_service_;
- session_params.proxy_service = proxy_service_;
+ session_params.proxy_service = proxy_service_.get();
scoped_refptr<net::HttpNetworkSession> network_session(
new net::HttpNetworkSession(session_params));
http_transaction_factory_.reset(
diff --git a/chrome/browser/net/proxy_service_factory.cc b/chrome/browser/net/proxy_service_factory.cc
index 8a34ea9..ad9afd0 100644
--- a/chrome/browser/net/proxy_service_factory.cc
+++ b/chrome/browser/net/proxy_service_factory.cc
@@ -14,6 +14,7 @@
#include "net/base/net_log.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_script_fetcher_impl.h"
+#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#if defined(OS_CHROMEOS)
diff --git a/chrome/browser/net/resolve_proxy_msg_helper.cc b/chrome/browser/net/resolve_proxy_msg_helper.cc
index b2ad9f9..49ce3e4 100644
--- a/chrome/browser/net/resolve_proxy_msg_helper.cc
+++ b/chrome/browser/net/resolve_proxy_msg_helper.cc
@@ -82,8 +82,7 @@ void ResolveProxyMsgHelper::StartPendingRequest() {
OnResolveProxyCompleted(result);
}
-bool ResolveProxyMsgHelper::GetProxyService(
- scoped_refptr<net::ProxyService>* out) const {
+bool ResolveProxyMsgHelper::GetProxyService(net::ProxyService** out) const {
// Unit-tests specify their own proxy service to use.
if (proxy_service_override_) {
*out = proxy_service_override_;
@@ -102,8 +101,10 @@ bool ResolveProxyMsgHelper::GetProxyService(
}
ResolveProxyMsgHelper::~ResolveProxyMsgHelper() {
- // Clear all pending requests.
- if (!pending_requests_.empty()) {
+ // Clear all pending requests if the ProxyService is still alive (if we have a
+ // default request context or override).
+ if (!pending_requests_.empty() &&
+ (Profile::GetDefaultRequestContext() || proxy_service_override_)) {
PendingRequest req = pending_requests_.front();
proxy_service_->CancelPacRequest(req.pac_req);
}
diff --git a/chrome/browser/net/resolve_proxy_msg_helper.h b/chrome/browser/net/resolve_proxy_msg_helper.h
index ac20c96..95ebaf9 100644
--- a/chrome/browser/net/resolve_proxy_msg_helper.h
+++ b/chrome/browser/net/resolve_proxy_msg_helper.h
@@ -50,7 +50,7 @@ class ResolveProxyMsgHelper : public BrowserMessageFilter {
// Get the proxy service instance to use. On success returns true and
// sets |*out|. Otherwise returns false.
- bool GetProxyService(scoped_refptr<net::ProxyService>* out) const;
+ bool GetProxyService(net::ProxyService** out) const;
// A PendingRequest is a resolve request that is in progress, or queued.
struct PendingRequest {
@@ -69,7 +69,7 @@ class ResolveProxyMsgHelper : public BrowserMessageFilter {
};
// Members for the current outstanding proxy request.
- scoped_refptr<net::ProxyService> proxy_service_;
+ net::ProxyService* proxy_service_;
net::CompletionCallbackImpl<ResolveProxyMsgHelper> callback_;
net::ProxyInfo proxy_info_;
@@ -79,7 +79,7 @@ class ResolveProxyMsgHelper : public BrowserMessageFilter {
// Specified by unit-tests, to use this proxy service in place of the
// global one.
- scoped_refptr<net::ProxyService> proxy_service_override_;
+ net::ProxyService* proxy_service_override_;
};
#endif // CHROME_BROWSER_NET_RESOLVE_PROXY_MSG_HELPER_H_
diff --git a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
index bb3c1d8..a32ab78 100644
--- a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
+++ b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
@@ -9,6 +9,7 @@
#include "net/base/net_errors.h"
#include "net/proxy/mock_proxy_resolver.h"
#include "net/proxy/proxy_config_service.h"
+#include "net/proxy/proxy_service.h"
#include "testing/gtest/include/gtest/gtest.h"
// This ProxyConfigService always returns "http://pac" as the PAC url to use.
@@ -61,7 +62,7 @@ class ResolveProxyMsgHelperTest : public testing::Test,
}
net::MockAsyncProxyResolver* resolver_;
- scoped_refptr<net::ProxyService> service_;
+ scoped_ptr<net::ProxyService> service_;
scoped_refptr<ResolveProxyMsgHelper> helper_;
scoped_ptr<PendingResult> pending_result_;
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index 16c3c88..2eb46b6 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -302,12 +302,12 @@ void ProfileIOData::LazyInitialize() const {
CreateDnsCertProvenanceChecker(io_thread_globals->dnsrr_resolver.get(),
main_request_context_));
- proxy_service_ =
+ proxy_service_.reset(
ProxyServiceFactory::CreateProxyService(
io_thread->net_log(),
io_thread_globals->proxy_script_fetcher_context.get(),
profile_params_->proxy_config_service.release(),
- command_line);
+ command_line));
// Take ownership over these parameters.
database_tracker_ = profile_params_->database_tracker;
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index ce5f954..544e9f4 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -213,7 +213,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
// Pointed to by URLRequestContext.
mutable scoped_ptr<net::NetworkDelegate> network_delegate_;
mutable scoped_ptr<net::DnsCertProvenanceChecker> dns_cert_checker_;
- mutable scoped_refptr<net::ProxyService> proxy_service_;
+ mutable scoped_ptr<net::ProxyService> proxy_service_;
mutable scoped_ptr<net::CookiePolicy> cookie_policy_;
// Pointed to by ResourceContext.
diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc
index b3f47f6..9e876d9 100644
--- a/chrome/service/net/service_url_request_context.cc
+++ b/chrome/service/net/service_url_request_context.cc
@@ -8,6 +8,7 @@
#include <sys/utsname.h>
#endif
+#include "base/compiler_specific.h"
#include "base/message_loop_proxy.h"
#include "base/string_util.h"
#include "base/sys_info.h"
@@ -105,17 +106,20 @@ std::string MakeUserAgentForServiceProcess() {
ServiceURLRequestContext::ServiceURLRequestContext(
const std::string& user_agent,
- net::ProxyService* net_proxy_service) : user_agent_(user_agent) {
- set_host_resolver(
+ net::ProxyService* net_proxy_service)
+ : user_agent_(user_agent),
+ ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {
+ storage_.set_host_resolver(
net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
NULL));
- set_proxy_service(net_proxy_service);
- set_cert_verifier(new net::CertVerifier);
- set_dnsrr_resolver(new net::DnsRRResolver);
- set_ftp_transaction_factory(new net::FtpNetworkLayer(host_resolver()));
- set_ssl_config_service(new net::SSLConfigServiceDefaults);
- set_http_auth_handler_factory(net::HttpAuthHandlerFactory::CreateDefault(
- host_resolver()));
+ storage_.set_proxy_service(net_proxy_service);
+ storage_.set_cert_verifier(new net::CertVerifier);
+ storage_.set_dnsrr_resolver(new net::DnsRRResolver);
+ storage_.set_ftp_transaction_factory(
+ new net::FtpNetworkLayer(host_resolver()));
+ storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
+ storage_.set_http_auth_handler_factory(
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
net::HttpNetworkSession::Params session_params;
session_params.host_resolver = host_resolver();
@@ -126,12 +130,12 @@ ServiceURLRequestContext::ServiceURLRequestContext(
session_params.http_auth_handler_factory = http_auth_handler_factory();
scoped_refptr<net::HttpNetworkSession> network_session(
new net::HttpNetworkSession(session_params));
- set_http_transaction_factory(
+ storage_.set_http_transaction_factory(
new net::HttpCache(
network_session,
net::HttpCache::DefaultBackend::InMemory(0)));
// In-memory cookie store.
- set_cookie_store(new net::CookieMonster(NULL, NULL));
+ storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
set_accept_language("en-us,fr");
set_accept_charset("iso-8859-1,*,utf-8");
}
@@ -145,12 +149,6 @@ const std::string& ServiceURLRequestContext::GetUserAgent(
}
ServiceURLRequestContext::~ServiceURLRequestContext() {
- delete ftp_transaction_factory();
- delete http_transaction_factory();
- delete http_auth_handler_factory();
- delete cert_verifier();
- delete dnsrr_resolver();
- delete host_resolver();
}
ServiceURLRequestContextGetter::ServiceURLRequestContextGetter()
@@ -162,19 +160,23 @@ ServiceURLRequestContextGetter::ServiceURLRequestContextGetter()
#if defined(OS_LINUX)
// Create the proxy service now, at initialization time, on the main thread,
// only for Linux, which requires that.
- CreateProxyService();
+ CreateProxyConfigService();
#endif
}
net::URLRequestContext*
ServiceURLRequestContextGetter::GetURLRequestContext() {
#if !defined(OS_LINUX)
- if (!proxy_service_)
- CreateProxyService();
+ if (!proxy_config_service_.get())
+ CreateProxyConfigService();
#endif
- if (!url_request_context_)
+ if (!url_request_context_) {
+ net::ProxyService* proxy_service =
+ net::ProxyService::CreateUsingSystemProxyResolver(
+ proxy_config_service_.release(), 0u, NULL);
url_request_context_ = new ServiceURLRequestContext(user_agent_,
- proxy_service_);
+ proxy_service);
+ }
return url_request_context_;
}
@@ -185,14 +187,12 @@ ServiceURLRequestContextGetter::GetIOMessageLoopProxy() const {
ServiceURLRequestContextGetter::~ServiceURLRequestContextGetter() {}
-void ServiceURLRequestContextGetter::CreateProxyService() {
+void ServiceURLRequestContextGetter::CreateProxyConfigService() {
// TODO(sanjeevr): Change CreateSystemProxyConfigService to accept a
// MessageLoopProxy* instead of MessageLoop*.
DCHECK(g_service_process);
- net::ProxyConfigService * proxy_config_service =
+ proxy_config_service_.reset(
net::ProxyService::CreateSystemProxyConfigService(
g_service_process->io_thread()->message_loop(),
- g_service_process->file_thread()->message_loop());
- proxy_service_ = net::ProxyService::CreateUsingSystemProxyResolver(
- proxy_config_service, 0u, NULL);
+ g_service_process->file_thread()->message_loop()));
}
diff --git a/chrome/service/net/service_url_request_context.h b/chrome/service/net/service_url_request_context.h
index 6d3463d..3cf286e 100644
--- a/chrome/service/net/service_url_request_context.h
+++ b/chrome/service/net/service_url_request_context.h
@@ -20,6 +20,7 @@
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_context_storage.h"
namespace base {
class MessageLoopProxy;
@@ -31,6 +32,7 @@ class MessageLoopProxy;
//
class ServiceURLRequestContext : public net::URLRequestContext {
public:
+ // This context takes ownership of |net_proxy_service|.
explicit ServiceURLRequestContext(const std::string& user_agent,
net::ProxyService* net_proxy_service);
@@ -42,6 +44,7 @@ class ServiceURLRequestContext : public net::URLRequestContext {
private:
std::string user_agent_;
+ net::URLRequestContextStorage storage_;
};
class ServiceURLRequestContextGetter : public net::URLRequestContextGetter {
@@ -61,12 +64,12 @@ class ServiceURLRequestContextGetter : public net::URLRequestContextGetter {
ServiceURLRequestContextGetter();
virtual ~ServiceURLRequestContextGetter();
- void CreateProxyService();
+ void CreateProxyConfigService();
std::string user_agent_;
scoped_refptr<net::URLRequestContext> url_request_context_;
scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
- scoped_refptr<net::ProxyService> proxy_service_;
+ scoped_ptr<net::ProxyConfigService> proxy_config_service_;
};
#endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_