summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 17:37:16 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 17:37:16 +0000
commit529623ed3b5c444fa30203fb982c2e69c97825a5 (patch)
treef8370b8c8298ff73fc4081396b800fe9cc0dc8d9 /net
parent4799b2614d03ac69635c639a0936e6f1a352cd9d (diff)
downloadchromium_src-529623ed3b5c444fa30203fb982c2e69c97825a5.zip
chromium_src-529623ed3b5c444fa30203fb982c2e69c97825a5.tar.gz
chromium_src-529623ed3b5c444fa30203fb982c2e69c97825a5.tar.bz2
Create a URLRequestContextStorage object to provide storage for URLRequestContext objects.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6560001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_network_delegate.h5
-rw-r--r--net/net.gyp2
-rw-r--r--net/url_request/url_request_context.h4
-rw-r--r--net/url_request/url_request_context_storage.cc108
-rw-r--r--net/url_request/url_request_context_storage.h92
-rw-r--r--net/url_request/url_request_test_util.cc47
-rw-r--r--net/url_request/url_request_test_util.h3
7 files changed, 234 insertions, 27 deletions
diff --git a/net/http/http_network_delegate.h b/net/http/http_network_delegate.h
index 9a9300b..a4b217a 100644
--- a/net/http/http_network_delegate.h
+++ b/net/http/http_network_delegate.h
@@ -13,6 +13,8 @@ class URLRequest;
class HttpNetworkDelegate {
public:
+ virtual ~HttpNetworkDelegate() {}
+
// Called before a request is sent.
virtual void OnBeforeURLRequest(URLRequest* request) = 0;
@@ -25,9 +27,6 @@ class HttpNetworkDelegate {
// This corresponds to URLRequestDelegate::OnReadCompleted.
virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0;
-
- protected:
- virtual ~HttpNetworkDelegate() {}
};
} // namespace net
diff --git a/net/net.gyp b/net/net.gyp
index 3cfd242..a0c1252 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -678,6 +678,8 @@
'url_request/url_request_about_job.h',
'url_request/url_request_context.cc',
'url_request/url_request_context.h',
+ 'url_request/url_request_context_storage.cc',
+ 'url_request/url_request_context_storage.h',
'url_request/url_request_data_job.cc',
'url_request/url_request_data_job.h',
'url_request/url_request_error_job.cc',
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index 45240d7..fa61297 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -35,7 +35,9 @@ class SSLConfigService;
class URLRequest;
// Subclass to provide application-specific context for URLRequest
-// instances.
+// instances. Note that URLRequestContext typically does not provide storage for
+// these member variables, since they may be shared. For the ones that aren't
+// shared, URLRequestContextStorage can be helpful in defining their storage.
class URLRequestContext
: public base::RefCountedThreadSafe<URLRequestContext>,
public base::NonThreadSafe {
diff --git a/net/url_request/url_request_context_storage.cc b/net/url_request/url_request_context_storage.cc
new file mode 100644
index 0000000..24b49ce
--- /dev/null
+++ b/net/url_request/url_request_context_storage.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2011 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 "net/url_request/url_request_context_storage.h"
+
+#include "base/logging.h"
+#include "net/base/cert_verifier.h"
+#include "net/base/cookie_policy.h"
+#include "net/base/cookie_store.h"
+#include "net/base/dnsrr_resolver.h"
+#include "net/base/host_resolver.h"
+#include "net/base/net_log.h"
+#include "net/ftp/ftp_transaction_factory.h"
+#include "net/http/http_auth_handler_factory.h"
+#include "net/http/http_network_delegate.h"
+#include "net/http/http_transaction_factory.h"
+#include "net/proxy/proxy_service.h"
+#include "net/url_request/url_request_context.h"
+
+namespace net {
+
+URLRequestContextStorage::URLRequestContextStorage(URLRequestContext* context)
+ : context_(context) {
+ DCHECK(context);
+}
+
+URLRequestContextStorage::~URLRequestContextStorage() {}
+
+void URLRequestContextStorage::set_net_log(NetLog* net_log) {
+ context_->set_net_log(net_log);
+ net_log_.reset(net_log);
+}
+
+void URLRequestContextStorage::set_host_resolver(HostResolver* host_resolver) {
+ context_->set_host_resolver(host_resolver);
+ host_resolver_.reset(host_resolver);
+}
+
+void URLRequestContextStorage::set_cert_verifier(CertVerifier* cert_verifier) {
+ context_->set_cert_verifier(cert_verifier);
+ cert_verifier_.reset(cert_verifier);
+}
+
+void URLRequestContextStorage::set_dnsrr_resolver(
+ DnsRRResolver* dnsrr_resolver) {
+ context_->set_dnsrr_resolver(dnsrr_resolver);
+ dnsrr_resolver_.reset(dnsrr_resolver);
+}
+
+void URLRequestContextStorage::set_dns_cert_checker(
+ DnsCertProvenanceChecker* dns_cert_checker) {
+ context_->set_dns_cert_checker(dns_cert_checker);
+ dns_cert_checker_.reset(dns_cert_checker);
+}
+
+void URLRequestContextStorage::set_http_auth_handler_factory(
+ HttpAuthHandlerFactory* http_auth_handler_factory) {
+ context_->set_http_auth_handler_factory(http_auth_handler_factory);
+ http_auth_handler_factory_.reset(http_auth_handler_factory);
+}
+
+void URLRequestContextStorage::set_proxy_service(ProxyService* proxy_service) {
+ context_->set_proxy_service(proxy_service);
+ proxy_service_ = proxy_service;
+}
+
+void URLRequestContextStorage::set_ssl_config_service(
+ SSLConfigService* ssl_config_service) {
+ context_->set_ssl_config_service(ssl_config_service);
+ ssl_config_service_ = ssl_config_service;
+}
+
+void URLRequestContextStorage::set_network_delegate(
+ HttpNetworkDelegate* network_delegate) {
+ context_->set_network_delegate(network_delegate);
+ network_delegate_.reset(network_delegate);
+}
+
+void URLRequestContextStorage::set_cookie_store(CookieStore* cookie_store) {
+ context_->set_cookie_store(cookie_store);
+ cookie_store_ = cookie_store;
+}
+
+void URLRequestContextStorage::set_cookie_policy(CookiePolicy* cookie_policy) {
+ context_->set_cookie_policy(cookie_policy);
+ cookie_policy_.reset(cookie_policy);
+}
+
+void URLRequestContextStorage::set_transport_security_state(
+ TransportSecurityState* transport_security_state) {
+ context_->set_transport_security_state(transport_security_state);
+ transport_security_state_ = transport_security_state;
+}
+
+void URLRequestContextStorage::set_http_transaction_factory(
+ HttpTransactionFactory* http_transaction_factory) {
+ context_->set_http_transaction_factory(http_transaction_factory);
+ http_transaction_factory_.reset(http_transaction_factory);
+}
+
+void URLRequestContextStorage::set_ftp_transaction_factory(
+ FtpTransactionFactory* ftp_transaction_factory) {
+ context_->set_ftp_transaction_factory(ftp_transaction_factory);
+ ftp_transaction_factory_.reset(ftp_transaction_factory);
+}
+
+} // namespace net
diff --git a/net/url_request/url_request_context_storage.h b/net/url_request/url_request_context_storage.h
new file mode 100644
index 0000000..2bcd8f0a
--- /dev/null
+++ b/net/url_request/url_request_context_storage.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2011 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.
+
+#ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_
+#define NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+
+namespace net {
+
+class CertVerifier;
+class CookiePolicy;
+class CookieStore;
+class DnsCertProvenanceChecker;
+class DnsRRResolver;
+class FtpTransactionFactory;
+class HostResolver;
+class HttpAuthHandlerFactory;
+class HttpNetworkDelegate;
+class HttpTransactionFactory;
+class NetLog;
+class ProxyService;
+class SSLConfigService;
+class TransportSecurityState;
+class URLRequestContext;
+
+// URLRequestContextStorage is a helper class that provides storage for unowned
+// member variables of URLRequestContext.
+class URLRequestContextStorage {
+ public:
+ // Note that URLRequestContextStorage does not acquire a reference to
+ // URLRequestContext, since it is often designed to be embedded in a
+ // URLRequestContext subclass.
+ explicit URLRequestContextStorage(URLRequestContext* context);
+ ~URLRequestContextStorage();
+
+ // These setters will set both the member variables and call the setter on the
+ // URLRequestContext object.
+
+ void set_net_log(NetLog* net_log);
+ void set_host_resolver(HostResolver* host_resolver);
+ void set_cert_verifier(CertVerifier* cert_verifier);
+ void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver);
+ void set_dns_cert_checker(DnsCertProvenanceChecker* dns_cert_checker);
+ void set_http_auth_handler_factory(
+ HttpAuthHandlerFactory* http_auth_handler_factory);
+ void set_proxy_service(ProxyService* proxy_service);
+ void set_ssl_config_service(SSLConfigService* ssl_config_service);
+ void set_network_delegate(HttpNetworkDelegate* network_delegate);
+ void set_cookie_store(CookieStore* cookie_store);
+ void set_cookie_policy(CookiePolicy* cookie_policy);
+ void set_transport_security_state(
+ TransportSecurityState* transport_security_state);
+ void set_http_transaction_factory(
+ HttpTransactionFactory* http_transaction_factory);
+ void set_ftp_transaction_factory(
+ FtpTransactionFactory* ftp_transaction_factory);
+
+ private:
+ // We use a raw pointer to prevent reference cycles, since
+ // URLRequestContextStorage can often be contained within a URLRequestContext
+ // subclass.
+ URLRequestContext* const context_;
+
+ // Owned members.
+ scoped_ptr<NetLog> net_log_;
+ scoped_ptr<HostResolver> host_resolver_;
+ scoped_ptr<CertVerifier> cert_verifier_;
+ scoped_ptr<DnsRRResolver> dnsrr_resolver_;
+ scoped_ptr<DnsCertProvenanceChecker> dns_cert_checker_;
+ scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_;
+ // TODO(willchan): Remove refcounting on these members.
+ scoped_refptr<ProxyService> proxy_service_;
+ scoped_refptr<SSLConfigService> ssl_config_service_;
+ scoped_ptr<HttpNetworkDelegate> network_delegate_;
+ scoped_refptr<CookieStore> cookie_store_;
+ scoped_ptr<CookiePolicy> cookie_policy_;
+ scoped_refptr<TransportSecurityState> transport_security_state_;
+
+ scoped_ptr<HttpTransactionFactory> http_transaction_factory_;
+ scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLRequestContextStorage);
+};
+
+} // namespace net
+
+#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_STORAGE_H_
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index 0302ce5..4a518c0 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -4,6 +4,7 @@
#include "net/url_request/url_request_test_util.h"
+#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/threading/thread.h"
@@ -78,47 +79,47 @@ void TestCookiePolicy::DoSetCookiePolicy(const GURL& url,
}
-TestURLRequestContext::TestURLRequestContext() {
- set_host_resolver(
+TestURLRequestContext::TestURLRequestContext()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) {
+ context_storage_.set_host_resolver(
net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
NULL, NULL));
- set_proxy_service(net::ProxyService::CreateDirect());
+ context_storage_.set_proxy_service(net::ProxyService::CreateDirect());
Init();
}
-TestURLRequestContext::TestURLRequestContext(const std::string& proxy) {
- set_host_resolver(
+TestURLRequestContext::TestURLRequestContext(const std::string& proxy)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) {
+ context_storage_.set_host_resolver(
net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
NULL, NULL));
net::ProxyConfig proxy_config;
proxy_config.proxy_rules().ParseFromString(proxy);
- set_proxy_service(net::ProxyService::CreateFixed(proxy_config));
+ context_storage_.set_proxy_service(
+ net::ProxyService::CreateFixed(proxy_config));
Init();
}
TestURLRequestContext::TestURLRequestContext(const std::string& proxy,
- net::HostResolver* host_resolver) {
- set_host_resolver(host_resolver);
+ net::HostResolver* host_resolver)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) {
+ context_storage_.set_host_resolver(host_resolver);
net::ProxyConfig proxy_config;
proxy_config.proxy_rules().ParseFromString(proxy);
- set_proxy_service(net::ProxyService::CreateFixed(proxy_config));
+ context_storage_.set_proxy_service(
+ net::ProxyService::CreateFixed(proxy_config));
Init();
}
-TestURLRequestContext::~TestURLRequestContext() {
- delete ftp_transaction_factory();
- delete http_transaction_factory();
- delete http_auth_handler_factory();
- delete cert_verifier();
- delete host_resolver();
-}
+TestURLRequestContext::~TestURLRequestContext() {}
void TestURLRequestContext::Init() {
- set_cert_verifier(new net::CertVerifier);
- 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()));
+ context_storage_.set_cert_verifier(new net::CertVerifier);
+ context_storage_.set_ftp_transaction_factory(
+ new net::FtpNetworkLayer(host_resolver()));
+ context_storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
+ context_storage_.set_http_auth_handler_factory(
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
net::HttpNetworkSession::Params params;
params.host_resolver = host_resolver();
params.cert_verifier = cert_verifier();
@@ -127,11 +128,11 @@ void TestURLRequestContext::Init() {
params.http_auth_handler_factory = http_auth_handler_factory();
params.network_delegate = network_delegate();
- set_http_transaction_factory(new net::HttpCache(
+ context_storage_.set_http_transaction_factory(new net::HttpCache(
new net::HttpNetworkSession(params),
net::HttpCache::DefaultBackend::InMemory(0)));
// In-memory cookie store.
- set_cookie_store(new net::CookieMonster(NULL, NULL));
+ context_storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
set_accept_language("en-us,fr");
set_accept_charset("iso-8859-1,*,utf-8");
}
diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h
index 1b75205..c02344c 100644
--- a/net/url_request/url_request_test_util.h
+++ b/net/url_request/url_request_test_util.h
@@ -33,6 +33,7 @@
#include "net/test/test_server.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"
#include "net/proxy/proxy_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "googleurl/src/url_util.h"
@@ -84,6 +85,8 @@ class TestURLRequestContext : public net::URLRequestContext {
private:
void Init();
+
+ net::URLRequestContextStorage context_storage_;
};
//-----------------------------------------------------------------------------