summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-13 03:44:24 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-13 03:44:24 +0000
commitd49801990067e7fe9a3caf141f31c6e6ba58fcfc (patch)
tree502fef7a064f7e1b67291d418b897117e2427822 /net/http
parent96508147cf0947fdd4ae19d9ee7f5f2e13268a5f (diff)
downloadchromium_src-d49801990067e7fe9a3caf141f31c6e6ba58fcfc.zip
chromium_src-d49801990067e7fe9a3caf141f31c6e6ba58fcfc.tar.gz
chromium_src-d49801990067e7fe9a3caf141f31c6e6ba58fcfc.tar.bz2
Use automatic memory management for URLRequestContext's members.
Also make ProxyService refcounted so the sharing between profiles is explicit. Review URL: http://codereview.chromium.org/13701 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_network_layer.h3
-rw-r--r--net/http/http_network_layer_unittest.cc11
-rw-r--r--net/http/http_network_session.h2
-rw-r--r--net/http/http_network_transaction_unittest.cc63
-rw-r--r--net/http/http_transaction_winhttp.cc2
-rw-r--r--net/http/http_transaction_winhttp.h2
-rw-r--r--net/http/http_transaction_winhttp_unittest.cc10
7 files changed, 30 insertions, 63 deletions
diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h
index 5364642..262cc55 100644
--- a/net/http/http_network_layer.h
+++ b/net/http/http_network_layer.h
@@ -17,7 +17,6 @@ class ProxyService;
class HttpNetworkLayer : public HttpTransactionFactory {
public:
- // |proxy_service| must remain valid for the lifetime of HttpNetworkLayer.
explicit HttpNetworkLayer(ProxyService* proxy_service);
~HttpNetworkLayer();
@@ -41,7 +40,7 @@ class HttpNetworkLayer : public HttpTransactionFactory {
#endif
// The proxy service being used for the session.
- ProxyService* proxy_service_;
+ scoped_refptr<ProxyService> proxy_service_;
scoped_refptr<HttpNetworkSession> session_;
bool suspended_;
diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc
index 0460947..deac71d 100644
--- a/net/http/http_network_layer_unittest.cc
+++ b/net/http/http_network_layer_unittest.cc
@@ -5,7 +5,6 @@
#include "net/base/scoped_host_mapper.h"
#include "net/http/http_network_layer.h"
#include "net/http/http_transaction_unittest.h"
-#include "net/proxy/proxy_resolver_null.h"
#include "net/proxy/proxy_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -22,15 +21,12 @@ class HttpNetworkLayerTest : public PlatformTest {
};
TEST_F(HttpNetworkLayerTest, CreateAndDestroy) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpNetworkLayer factory(&proxy_service);
-
+ net::HttpNetworkLayer factory(net::ProxyService::CreateNull());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
}
TEST_F(HttpNetworkLayerTest, Suspend) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpNetworkLayer factory(&proxy_service);
+ net::HttpNetworkLayer factory(net::ProxyService::CreateNull());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
trans.reset();
@@ -46,8 +42,7 @@ TEST_F(HttpNetworkLayerTest, Suspend) {
}
TEST_F(HttpNetworkLayerTest, GoogleGET) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpNetworkLayer factory(&proxy_service);
+ net::HttpNetworkLayer factory(net::ProxyService::CreateNull());
TestCompletionCallback callback;
diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h
index d998665..3e8c36e 100644
--- a/net/http/http_network_session.h
+++ b/net/http/http_network_session.h
@@ -38,7 +38,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> {
private:
HttpAuthCache auth_cache_;
scoped_refptr<ClientSocketPool> connection_pool_;
- ProxyService* proxy_service_;
+ scoped_refptr<ProxyService> proxy_service_;
#if defined(OS_WIN)
// TODO(port): Port the SSLConfigService class to Linux and Mac OS X.
SSLConfigService ssl_config_service_;
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 903f6d9..7393a191 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -12,7 +12,6 @@
#include "net/http/http_network_transaction.h"
#include "net/http/http_transaction_unittest.h"
#include "net/proxy/proxy_resolver_fixed.h"
-#include "net/proxy/proxy_resolver_null.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -200,13 +199,15 @@ class MockClientSocketFactory : public net::ClientSocketFactory {
MockClientSocketFactory mock_socket_factory;
-// Create a proxy service which fails on all requests (falls back to direct).
-net::ProxyService* CreateNullProxyService() {
- return new net::ProxyService(new net::ProxyResolverNull);
+net::HttpNetworkSession* CreateSessionWithProxy(const std::string& proxy) {
+ net::ProxyInfo proxy_info;
+ proxy_info.UseNamedProxy(proxy);
+ return new net::HttpNetworkSession(
+ new net::ProxyService(new net::ProxyResolverFixed(proxy_info)));
}
-net::HttpNetworkSession* CreateSession(net::ProxyService* proxy_service) {
- return new net::HttpNetworkSession(proxy_service);
+net::HttpNetworkSession* CreateSession() {
+ return new net::HttpNetworkSession(net::ProxyService::CreateNull());
}
class HttpNetworkTransactionTest : public PlatformTest {
@@ -236,9 +237,8 @@ struct SimpleGetHelperResult {
SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) {
SimpleGetHelperResult out;
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -289,9 +289,8 @@ void FillLargeHeadersString(std::string* str, int size) {
//-----------------------------------------------------------------------------
TEST_F(HttpNetworkTransactionTest, Basic) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
}
TEST_F(HttpNetworkTransactionTest, SimpleGET) {
@@ -398,9 +397,7 @@ TEST_F(HttpNetworkTransactionTest, StopsReading204) {
}
TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
- scoped_refptr<net::HttpNetworkSession> session =
- CreateSession(proxy_service.get());
+ scoped_refptr<net::HttpNetworkSession> session = CreateSession();
MockRead data_reads[] = {
MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
@@ -449,9 +446,8 @@ TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
}
TEST_F(HttpNetworkTransactionTest, Ignores100) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "POST";
@@ -495,9 +491,7 @@ TEST_F(HttpNetworkTransactionTest, Ignores100) {
// transaction to resend the request.
void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
const MockRead& read_failure) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
- scoped_refptr<net::HttpNetworkSession> session =
- CreateSession(proxy_service.get());
+ scoped_refptr<net::HttpNetworkSession> session = CreateSession();
net::HttpRequestInfo request;
request.method = "GET";
@@ -562,9 +556,8 @@ TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
}
TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -617,9 +610,8 @@ TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) {
// Test the request-challenge-retry sequence for basic auth.
// (basic auth is the easiest to mock, because it has no randomness).
TEST_F(HttpNetworkTransactionTest, BasicAuth) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -709,14 +701,9 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) {
// authentication. Again, this uses basic auth for both since that is
// the simplest to mock.
TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
- net::ProxyInfo proxy_info;
- proxy_info.UseNamedProxy("myproxy:70");
- net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
-
// Configure against proxy server "myproxy:70".
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(&proxy_service),
- &mock_socket_factory));
+ CreateSessionWithProxy("myproxy:70"), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -848,9 +835,8 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
// After some maximum number of bytes is consumed, the transaction should
// fail with ERR_RESPONSE_HEADERS_TOO_BIG.
TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -889,12 +875,8 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
// http://code.google.com/p/chromium/issues/detail?id=3772
TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) {
// Configure against proxy server "myproxy:70".
- net::ProxyInfo proxy_info;
- proxy_info.UseNamedProxy("myproxy:70");
- net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
-
scoped_refptr<net::HttpNetworkSession> session(
- CreateSession(&proxy_service));
+ CreateSessionWithProxy("myproxy:70"));
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
session.get(), &mock_socket_factory));
@@ -971,9 +953,7 @@ TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
request[1].upload_data->AppendBytes("foo", 3);
request[1].load_flags = 0;
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
- scoped_refptr<net::HttpNetworkSession> session =
- CreateSession(proxy_service.get());
+ scoped_refptr<net::HttpNetworkSession> session = CreateSession();
// The first socket is used for transaction 1 and the first attempt of
// transaction 2.
@@ -1049,9 +1029,8 @@ TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
// an identity in the URL. The request should be sent as normal, but when
// it fails the identity from the URL is used to answer the challenge.
TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
- CreateSession(proxy_service.get()), &mock_socket_factory));
+ CreateSession(), &mock_socket_factory));
net::HttpRequestInfo request;
request.method = "GET";
@@ -1119,9 +1098,7 @@ TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) {
// Test that previously tried username/passwords for a realm get re-used.
TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
- scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
- scoped_refptr<net::HttpNetworkSession> session =
- CreateSession(proxy_service.get());
+ scoped_refptr<net::HttpNetworkSession> session = CreateSession();
// Transaction 1: authenticate (foo, bar) on MyRealm1
{
diff --git a/net/http/http_transaction_winhttp.cc b/net/http/http_transaction_winhttp.cc
index b1ecf2a..e4023905 100644
--- a/net/http/http_transaction_winhttp.cc
+++ b/net/http/http_transaction_winhttp.cc
@@ -240,7 +240,7 @@ class HttpTransactionWinHttp::Session
HINTERNET internet_;
HINTERNET internet_no_tls_;
MessageLoop* message_loop_;
- ProxyService* proxy_service_;
+ scoped_refptr<ProxyService> proxy_service_;
AuthCache auth_cache_;
// This event object is used when destroying a transaction. It is given
diff --git a/net/http/http_transaction_winhttp.h b/net/http/http_transaction_winhttp.h
index 27ad730..fd6ad6b 100644
--- a/net/http/http_transaction_winhttp.h
+++ b/net/http/http_transaction_winhttp.h
@@ -40,7 +40,7 @@ class HttpTransactionWinHttp : public HttpTransaction {
private:
Session* session_;
- ProxyService* proxy_service_;
+ scoped_refptr<ProxyService> proxy_service_;
bool is_suspended_;
DISALLOW_EVIL_CONSTRUCTORS(Factory);
};
diff --git a/net/http/http_transaction_winhttp_unittest.cc b/net/http/http_transaction_winhttp_unittest.cc
index acc4e08..03787dd 100644
--- a/net/http/http_transaction_winhttp_unittest.cc
+++ b/net/http/http_transaction_winhttp_unittest.cc
@@ -4,19 +4,16 @@
#include "net/http/http_transaction_winhttp.h"
#include "net/http/http_transaction_unittest.h"
-#include "net/proxy/proxy_resolver_null.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(HttpTransactionWinHttp, CreateAndDestroy) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpTransactionWinHttp::Factory factory(&proxy_service);
+ net::HttpTransactionWinHttp::Factory factory(net::ProxyService::CreateNull());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
}
TEST(HttpTransactionWinHttp, Suspend) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpTransactionWinHttp::Factory factory(&proxy_service);
+ net::HttpTransactionWinHttp::Factory factory(net::ProxyService::CreateNull());
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());
trans.reset();
@@ -32,8 +29,7 @@ TEST(HttpTransactionWinHttp, Suspend) {
}
TEST(HttpTransactionWinHttp, GoogleGET) {
- net::ProxyService proxy_service(new net::ProxyResolverNull);
- net::HttpTransactionWinHttp::Factory factory(&proxy_service);
+ net::HttpTransactionWinHttp::Factory factory(net::ProxyService::CreateNull());
TestCompletionCallback callback;
scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction());