diff options
Diffstat (limited to 'net')
22 files changed, 121 insertions, 116 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index a912661..0b5c3fc 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -57,7 +57,7 @@ class HostMapper; // Thread safety: This class is not threadsafe, and must only be called // from one thread! // -class HostResolver : public base::RefCounted<HostResolver> { +class HostResolver { public: // The parameters for doing a Resolve(). |hostname| and |port| are required, // the rest are optional (and have reasonable defaults). @@ -236,7 +236,7 @@ class SingleRequestHostResolver { void OnResolveCompletion(int result); // The actual host resolver that will handle the request. - scoped_refptr<HostResolver> resolver_; + HostResolver* resolver_; // The current request (if any). HostResolver::Request* cur_request_; diff --git a/net/base/host_resolver_unittest.cc b/net/base/host_resolver_unittest.cc index 32b6af6..8fb0d16 100644 --- a/net/base/host_resolver_unittest.cc +++ b/net/base/host_resolver_unittest.cc @@ -140,8 +140,6 @@ class ResolveRequest { int result_; net::AddressList addrlist_; - // We don't use a scoped_refptr, to simplify deleting shared resolver in - // DeleteWithinCallback test. net::HostResolver* resolver_; Delegate* delegate_; @@ -172,7 +170,7 @@ class HostResolverTest : public testing::Test { }; TEST_F(HostResolverTest, SynchronousLookup) { - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 80; @@ -181,7 +179,7 @@ TEST_F(HostResolverTest, SynchronousLookup) { ScopedHostMapper scoped_mapper(mapper.get()); net::HostResolver::RequestInfo info("just.testing", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, NULL, NULL); + int err = host_resolver.Resolve(info, &adrlist, NULL, NULL); EXPECT_EQ(net::OK, err); const struct addrinfo* ainfo = adrlist.head(); @@ -195,7 +193,7 @@ TEST_F(HostResolverTest, SynchronousLookup) { } TEST_F(HostResolverTest, AsynchronousLookup) { - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 80; @@ -204,7 +202,7 @@ TEST_F(HostResolverTest, AsynchronousLookup) { ScopedHostMapper scoped_mapper(mapper.get()); net::HostResolver::RequestInfo info("just.testing", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL); + int err = host_resolver.Resolve(info, &adrlist, &callback_, NULL); EXPECT_EQ(net::ERR_IO_PENDING, err); MessageLoop::current()->Run(); @@ -227,12 +225,12 @@ TEST_F(HostResolverTest, CanceledAsynchronousLookup) { ScopedHostMapper scoped_mapper(mapper.get()); { - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 80; net::HostResolver::RequestInfo info("just.testing", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, &callback_, NULL); + int err = host_resolver.Resolve(info, &adrlist, &callback_, NULL); EXPECT_EQ(net::ERR_IO_PENDING, err); // Make sure we will exit the queue even when callback is not called. @@ -254,11 +252,11 @@ TEST_F(HostResolverTest, NumericIPv4Address) { mapper->AllowDirectLookup("*"); ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 5555; net::HostResolver::RequestInfo info("127.1.2.3", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, NULL, NULL); + int err = host_resolver.Resolve(info, &adrlist, NULL, NULL); EXPECT_EQ(net::OK, err); const struct addrinfo* ainfo = adrlist.head(); @@ -278,14 +276,14 @@ TEST_F(HostResolverTest, NumericIPv6Address) { // Resolve a plain IPv6 address. Don't worry about [brackets], because // the caller should have removed them. - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 5555; net::HostResolver::RequestInfo info("2001:db8::1", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, NULL, NULL); + int err = host_resolver.Resolve(info, &adrlist, NULL, NULL); // On computers without IPv6 support, getaddrinfo cannot convert IPv6 // address literals to addresses (getaddrinfo returns EAI_NONAME). So this - // test has to allow host_resolver->Resolve to fail. + // test has to allow host_resolver.Resolve to fail. if (err == net::ERR_NAME_NOT_RESOLVED) return; EXPECT_EQ(net::OK, err); @@ -312,11 +310,11 @@ TEST_F(HostResolverTest, EmptyHost) { mapper->AllowDirectLookup("*"); ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; net::AddressList adrlist; const int kPortnum = 5555; net::HostResolver::RequestInfo info("", kPortnum); - int err = host_resolver->Resolve(info, &adrlist, NULL, NULL); + int err = host_resolver.Resolve(info, &adrlist, NULL, NULL); EXPECT_EQ(net::ERR_NAME_NOT_RESOLVED, err); } @@ -372,7 +370,7 @@ TEST_F(HostResolverTest, DeDupeRequests) { scoped_refptr<CapturingHostMapper> mapper = new CapturingHostMapper(); ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -381,11 +379,11 @@ TEST_F(HostResolverTest, DeDupeRequests) { // Start 5 requests, duplicating hosts "a" and "b". Since the mapper is // blocked, these should all pile up until we signal it. - ResolveRequest req1(host_resolver, "a", 80, &verifier); - ResolveRequest req2(host_resolver, "b", 80, &verifier); - ResolveRequest req3(host_resolver, "b", 81, &verifier); - ResolveRequest req4(host_resolver, "a", 82, &verifier); - ResolveRequest req5(host_resolver, "b", 83, &verifier); + ResolveRequest req1(&host_resolver, "a", 80, &verifier); + ResolveRequest req2(&host_resolver, "b", 80, &verifier); + ResolveRequest req3(&host_resolver, "b", 81, &verifier); + ResolveRequest req4(&host_resolver, "a", 82, &verifier); + ResolveRequest req5(&host_resolver, "b", 83, &verifier); // Ready, Set, GO!!! mapper->Signal(); @@ -421,7 +419,7 @@ TEST_F(HostResolverTest, CancelMultipleRequests) { scoped_refptr<CapturingHostMapper> mapper = new CapturingHostMapper(); ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -430,11 +428,11 @@ TEST_F(HostResolverTest, CancelMultipleRequests) { // Start 5 requests, duplicating hosts "a" and "b". Since the mapper is // blocked, these should all pile up until we signal it. - ResolveRequest req1(host_resolver, "a", 80, &verifier); - ResolveRequest req2(host_resolver, "b", 80, &verifier); - ResolveRequest req3(host_resolver, "b", 81, &verifier); - ResolveRequest req4(host_resolver, "a", 82, &verifier); - ResolveRequest req5(host_resolver, "b", 83, &verifier); + ResolveRequest req1(&host_resolver, "a", 80, &verifier); + ResolveRequest req2(&host_resolver, "b", 80, &verifier); + ResolveRequest req3(&host_resolver, "b", 81, &verifier); + ResolveRequest req4(&host_resolver, "a", 82, &verifier); + ResolveRequest req5(&host_resolver, "b", 83, &verifier); // Cancel everything except request 4. req1.Cancel(); @@ -506,7 +504,7 @@ TEST_F(HostResolverTest, CancelWithinCallback) { scoped_refptr<CapturingHostMapper> mapper = new CapturingHostMapper(); ScopedHostMapper scoped_mapper(mapper.get()); - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -515,10 +513,10 @@ TEST_F(HostResolverTest, CancelWithinCallback) { // Start 4 requests, duplicating hosts "a". Since the mapper is // blocked, these should all pile up until we signal it. - ResolveRequest req1(host_resolver, "a", 80, &verifier); - ResolveRequest req2(host_resolver, "a", 81, &verifier); - ResolveRequest req3(host_resolver, "a", 82, &verifier); - ResolveRequest req4(host_resolver, "a", 83, &verifier); + ResolveRequest req1(&host_resolver, "a", 80, &verifier); + ResolveRequest req2(&host_resolver, "a", 81, &verifier); + ResolveRequest req3(&host_resolver, "a", 82, &verifier); + ResolveRequest req4(&host_resolver, "a", 83, &verifier); // Once "a:80" completes, it will cancel "a:81" and "a:82". verifier.SetRequestsToCancel(&req2, &req3); @@ -533,18 +531,12 @@ TEST_F(HostResolverTest, CancelWithinCallback) { // Helper class used by HostResolverTest.DeleteWithinCallback. class DeleteWithinCallbackVerifier : public ResolveRequest::Delegate { public: - // |host_resolver| is the resolver that the the resolve requests were started - // with. - DeleteWithinCallbackVerifier(net::HostResolver* host_resolver) - : host_resolver_(host_resolver) {} + DeleteWithinCallbackVerifier() {} virtual void OnCompleted(ResolveRequest* resolve) { EXPECT_EQ("a", resolve->hostname()); EXPECT_EQ(80, resolve->port()); - - // Release the last reference to the host resolver that started the - // requests. - host_resolver_ = NULL; + delete resolve->resolver(); // Quit after returning from OnCompleted (to give it a chance at // incorrectly running the cancelled tasks). @@ -552,7 +544,6 @@ class DeleteWithinCallbackVerifier : public ResolveRequest::Delegate { } private: - scoped_refptr<net::HostResolver> host_resolver_; DISALLOW_COPY_AND_ASSIGN(DeleteWithinCallbackVerifier); }; @@ -562,11 +553,13 @@ TEST_F(HostResolverTest, DeleteWithinCallback) { scoped_refptr<CapturingHostMapper> mapper = new CapturingHostMapper(); ScopedHostMapper scoped_mapper(mapper.get()); - // The class will receive callbacks for when each resolve completes. It - // checks that the right things happened. Note that the verifier holds the - // only reference to |host_resolver|, so it can delete it within callback. + // This should be deleted by DeleteWithinCallbackVerifier -- if it leaks + // then the test has failed. net::HostResolver* host_resolver = new net::HostResolver; - DeleteWithinCallbackVerifier verifier(host_resolver); + + // The class will receive callbacks for when each resolve completes. It + // checks that the right things happened. + DeleteWithinCallbackVerifier verifier; // Start 4 requests, duplicating hosts "a". Since the mapper is // blocked, these should all pile up until we signal it. @@ -616,7 +609,7 @@ TEST_F(HostResolverTest, StartWithinCallback) { ScopedHostMapper scoped_mapper(mapper.get()); // Turn off caching for this host resolver. - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver(0, 0)); + net::HostResolver host_resolver(0, 0); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -625,10 +618,10 @@ TEST_F(HostResolverTest, StartWithinCallback) { // Start 4 requests, duplicating hosts "a". Since the mapper is // blocked, these should all pile up until we signal it. - ResolveRequest req1(host_resolver, "a", 80, &verifier); - ResolveRequest req2(host_resolver, "a", 81, &verifier); - ResolveRequest req3(host_resolver, "a", 82, &verifier); - ResolveRequest req4(host_resolver, "a", 83, &verifier); + ResolveRequest req1(&host_resolver, "a", 80, &verifier); + ResolveRequest req2(&host_resolver, "a", 81, &verifier); + ResolveRequest req3(&host_resolver, "a", 82, &verifier); + ResolveRequest req4(&host_resolver, "a", 83, &verifier); // Ready, Set, GO!!! mapper->Signal(); @@ -680,14 +673,14 @@ class BypassCacheVerifier : public ResolveRequest::Delegate { }; TEST_F(HostResolverTest, BypassCache) { - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. BypassCacheVerifier verifier; // Start a request. - ResolveRequest req1(host_resolver, "a", 80, &verifier); + ResolveRequest req1(&host_resolver, "a", 80, &verifier); // |verifier| will send quit message once all the requests have finished. MessageLoop::current()->Run(); @@ -763,17 +756,17 @@ class CapturingObserver : public net::HostResolver::Observer { // Does not test the cancellation notification since all resolves are // synchronous. TEST_F(HostResolverTest, Observers) { - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; CapturingObserver observer; - host_resolver->AddObserver(&observer); + host_resolver.AddObserver(&observer); net::AddressList addrlist; // Resolve "host1". net::HostResolver::RequestInfo info1("host1", 70); - int rv = host_resolver->Resolve(info1, &addrlist, NULL, NULL); + int rv = host_resolver.Resolve(info1, &addrlist, NULL, NULL); EXPECT_EQ(net::OK, rv); EXPECT_EQ(1U, observer.start_log.size()); @@ -787,7 +780,7 @@ TEST_F(HostResolverTest, Observers) { // Resolve "host1" again -- this time it will be served from cache, but it // should still notify of completion. TestCompletionCallback callback; - rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL); + rv = host_resolver.Resolve(info1, &addrlist, &callback, NULL); ASSERT_EQ(net::OK, rv); // Should complete synchronously. EXPECT_EQ(2U, observer.start_log.size()); @@ -801,7 +794,7 @@ TEST_F(HostResolverTest, Observers) { // Resolve "host2", setting referrer to "http://foobar.com" net::HostResolver::RequestInfo info2("host2", 70); info2.set_referrer(GURL("http://foobar.com")); - rv = host_resolver->Resolve(info2, &addrlist, NULL, NULL); + rv = host_resolver.Resolve(info2, &addrlist, NULL, NULL); EXPECT_EQ(net::OK, rv); EXPECT_EQ(3U, observer.start_log.size()); @@ -813,11 +806,11 @@ TEST_F(HostResolverTest, Observers) { CapturingObserver::FinishEntry(2, true, info2)); // Unregister the observer. - host_resolver->RemoveObserver(&observer); + host_resolver.RemoveObserver(&observer); // Resolve "host3" net::HostResolver::RequestInfo info3("host3", 70); - host_resolver->Resolve(info3, &addrlist, NULL, NULL); + host_resolver.Resolve(info3, &addrlist, NULL, NULL); // No effect this time, since observer was removed. EXPECT_EQ(3U, observer.start_log.size()); @@ -833,8 +826,8 @@ TEST_F(HostResolverTest, CancellationObserver) { CapturingObserver observer; { // Create a host resolver and attach an observer. - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); - host_resolver->AddObserver(&observer); + net::HostResolver host_resolver; + host_resolver.AddObserver(&observer); TestCompletionCallback callback; @@ -846,7 +839,7 @@ TEST_F(HostResolverTest, CancellationObserver) { net::HostResolver::RequestInfo info1("host1", 70); net::HostResolver::Request* req = NULL; net::AddressList addrlist; - int rv = host_resolver->Resolve(info1, &addrlist, &callback, &req); + int rv = host_resolver.Resolve(info1, &addrlist, &callback, &req); EXPECT_EQ(net::ERR_IO_PENDING, rv); EXPECT_TRUE(NULL != req); @@ -858,7 +851,7 @@ TEST_F(HostResolverTest, CancellationObserver) { CapturingObserver::StartOrCancelEntry(0, info1)); // Cancel the request (host mapper is blocked so it cant be finished yet). - host_resolver->CancelRequest(req); + host_resolver.CancelRequest(req); EXPECT_EQ(1U, observer.start_log.size()); EXPECT_EQ(0U, observer.finish_log.size()); @@ -869,7 +862,7 @@ TEST_F(HostResolverTest, CancellationObserver) { // Start an async request for (host2:60) net::HostResolver::RequestInfo info2("host2", 60); - rv = host_resolver->Resolve(info2, &addrlist, &callback, NULL); + rv = host_resolver.Resolve(info2, &addrlist, &callback, NULL); EXPECT_EQ(net::ERR_IO_PENDING, rv); EXPECT_TRUE(NULL != req); diff --git a/net/ftp/ftp_network_session.h b/net/ftp/ftp_network_session.h index dcaacad..29c34d2 100644 --- a/net/ftp/ftp_network_session.h +++ b/net/ftp/ftp_network_session.h @@ -22,7 +22,7 @@ class FtpNetworkSession : public base::RefCounted<FtpNetworkSession> { FtpAuthCache* auth_cache() { return &auth_cache_; } private: - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; FtpAuthCache auth_cache_; }; diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index d381b0b..b45156b 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -224,7 +224,7 @@ class FtpMockControlSocketFileDownloadRetrFail class FtpNetworkTransactionTest : public PlatformTest { public: FtpNetworkTransactionTest() - : session_(new FtpNetworkSession(new HostResolver)), + : session_(new FtpNetworkSession(&resolver_)), transaction_(session_.get(), &mock_socket_factory_) { } @@ -253,6 +253,7 @@ class FtpNetworkTransactionTest : public PlatformTest { EXPECT_EQ(FtpMockControlSocket::QUIT, ctrl_socket->state()); } + HostResolver resolver_; scoped_refptr<FtpNetworkSession> session_; MockClientSocketFactory mock_socket_factory_; FtpNetworkTransaction transaction_; diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index b4b430f..74cf3df 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -52,7 +52,7 @@ class HttpNetworkLayer : public HttpTransactionFactory { ClientSocketFactory* socket_factory_; // The host resolver being used for the session. - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; // The proxy service being used for the session. ProxyService* proxy_service_; diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 9fd35ea..32888f0 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -14,17 +14,17 @@ class HttpNetworkLayerTest : public PlatformTest { }; TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { + net::HostResolver host_resolver; scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); - net::HttpNetworkLayer factory( - NULL, new net::HostResolver, proxy_service.get()); + net::HttpNetworkLayer factory(NULL, &host_resolver, proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); } TEST_F(HttpNetworkLayerTest, Suspend) { + net::HostResolver host_resolver; scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); - net::HttpNetworkLayer factory( - NULL, new net::HostResolver, proxy_service.get()); + net::HttpNetworkLayer factory(NULL, &host_resolver, proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); trans.reset(); @@ -55,8 +55,9 @@ TEST_F(HttpNetworkLayerTest, GET) { net::StaticMockSocket data(data_reads, data_writes); mock_socket_factory.AddMockSocket(&data); + net::HostResolver host_resolver; scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); - net::HttpNetworkLayer factory(&mock_socket_factory, new net::HostResolver, + net::HttpNetworkLayer factory(&mock_socket_factory, &host_resolver, proxy_service.get()); TestCompletionCallback callback; diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 3529bc8..a084ec7 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -54,7 +54,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { HttpAuthCache auth_cache_; SSLClientAuthCache ssl_client_auth_cache_; scoped_refptr<ClientSocketPool> connection_pool_; - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; ProxyService* proxy_service_; #if defined(OS_WIN) // TODO(port): Port the SSLConfigService class to Linux and Mac OS X. diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index bcb22a9..ba68db1 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -35,14 +35,13 @@ ProxyService* CreateNullProxyService() { class SessionDependencies { public: // Default set of dependencies -- "null" proxy service. - SessionDependencies() : host_resolver(new HostResolver), - proxy_service(CreateNullProxyService()) {} + SessionDependencies() : proxy_service(CreateNullProxyService()) {} // Custom proxy service dependency. explicit SessionDependencies(ProxyService* proxy_service) - : host_resolver(new HostResolver), proxy_service(proxy_service) {} + : proxy_service(proxy_service) {} - scoped_refptr<HostResolver> host_resolver; + HostResolver host_resolver; scoped_ptr<ProxyService> proxy_service; MockClientSocketFactory socket_factory; }; @@ -55,7 +54,7 @@ ProxyService* CreateFixedProxyService(const std::string& proxy) { HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, + return new HttpNetworkSession(&session_deps->host_resolver, session_deps->proxy_service.get(), &session_deps->socket_factory); } @@ -3303,7 +3302,7 @@ TEST_F(HttpNetworkTransactionTest, ResolveMadeWithReferrer) { CreateSession(&session_deps), &session_deps.socket_factory)); // Attach an observer to watch the host resolutions being made. - session_deps.host_resolver->AddObserver(&resolution_observer); + session_deps.host_resolver.AddObserver(&resolution_observer); // Connect up a mock socket which will fail when reading. MockRead data_reads[] = { @@ -3339,14 +3338,14 @@ TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { // Warm up the host cache so it has an entry for "www.google.com" (by doing // a synchronous lookup.) AddressList addrlist; - int rv = session_deps.host_resolver->Resolve( + int rv = session_deps.host_resolver.Resolve( HostResolver::RequestInfo("www.google.com", 80), &addrlist, NULL, NULL); EXPECT_EQ(OK, rv); // Verify that it was added to host cache, by doing a subsequent async lookup // and confirming it completes synchronously. TestCompletionCallback resolve_callback; - rv = session_deps.host_resolver->Resolve( + rv = session_deps.host_resolver.Resolve( HostResolver::RequestInfo("www.google.com", 80), &addrlist, &resolve_callback, NULL); EXPECT_EQ(OK, rv); diff --git a/net/proxy/proxy_resolver_perftest.cc b/net/proxy/proxy_resolver_perftest.cc index 22f2350..85ad554 100644 --- a/net/proxy/proxy_resolver_perftest.cc +++ b/net/proxy/proxy_resolver_perftest.cc @@ -185,8 +185,10 @@ TEST(ProxyResolverPerfTest, ProxyResolverMac) { #endif TEST(ProxyResolverPerfTest, ProxyResolverV8) { + net::HostResolver host_resolver; + net::ProxyResolverV8::JSBindings* js_bindings = - net::ProxyResolverV8::CreateDefaultBindings(new net::HostResolver, NULL); + net::ProxyResolverV8::CreateDefaultBindings(&host_resolver, NULL); net::ProxyResolverV8 resolver(js_bindings); PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 6bbffec..ad4f1eb6 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -103,7 +103,7 @@ class SyncHostResolverBridge event_.Signal(); } - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; MessageLoop* host_resolver_loop_; // Event to notify completion of resolve request. diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc index 7fab7d7..0e8ba47 100644 --- a/net/proxy/proxy_resolver_v8_unittest.cc +++ b/net/proxy/proxy_resolver_v8_unittest.cc @@ -378,8 +378,9 @@ TEST(ProxyResolverV8Test, V8Bindings) { TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { // Get a hold of a DefaultJSBindings* (it is a hidden impl class). + net::HostResolver host_resolver; scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( - net::ProxyResolverV8::CreateDefaultBindings(new net::HostResolver, NULL)); + net::ProxyResolverV8::CreateDefaultBindings(&host_resolver, NULL)); // Considered an error. EXPECT_EQ("", bindings->DnsResolve("")); @@ -429,8 +430,9 @@ TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { // Get a hold of a DefaultJSBindings* (it is a hidden impl class). + net::HostResolver host_resolver; scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( - net::ProxyResolverV8::CreateDefaultBindings(new net::HostResolver, NULL)); + net::ProxyResolverV8::CreateDefaultBindings(&host_resolver, NULL)); // Our ip address is always going to be 127.0.0.1, since we are using a // mock host mapper when running in unit-test mode. diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index 8a7cfb5..5b16738b 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -41,6 +41,7 @@ class RequestContext : public URLRequestContext { ~RequestContext() { delete http_transaction_factory_; delete proxy_service_; + delete host_resolver_; } }; diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index c642b48..6280048 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -218,9 +218,9 @@ class ClientSocketPoolBase : public base::RefCounted<ClientSocketPoolBase> { // The maximum number of sockets kept per group. const int max_sockets_per_group_; - // The host resolver that will be used to do host lookups for connecting + // The host resolver that will be used to do DNS lookups for connecting // sockets. - scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; scoped_ptr<ConnectJobFactory> connect_job_factory_; diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 1d68bd1..c6308fa 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -86,11 +86,11 @@ TEST_F(SSLClientSocketTest, MAYBE_Connect) { StartOKServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(net::OK, rv); net::ClientSocket *transport = new net::TCPClientSocket(addr); @@ -124,11 +124,11 @@ TEST_F(SSLClientSocketTest, MAYBE_ConnectExpired) { StartExpiredServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kHostName, server_.kBadHTTPSPort); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(net::OK, rv); net::ClientSocket *transport = new net::TCPClientSocket(addr); @@ -161,12 +161,12 @@ TEST_F(SSLClientSocketTest, MAYBE_ConnectMismatched) { StartMismatchedServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kMismatchedHostName, server_.kOKHTTPSPort); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(net::OK, rv); net::ClientSocket *transport = new net::TCPClientSocket(addr); @@ -204,11 +204,11 @@ TEST_F(SSLClientSocketTest, MAYBE_Read) { StartOKServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver->Resolve(info, &addr, &callback, NULL); + int rv = resolver.Resolve(info, &addr, &callback, NULL); EXPECT_EQ(net::ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -265,11 +265,11 @@ TEST_F(SSLClientSocketTest, MAYBE_Read_SmallChunks) { StartOKServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(net::OK, rv); net::ClientSocket *transport = new net::TCPClientSocket(addr); @@ -321,11 +321,11 @@ TEST_F(SSLClientSocketTest, MAYBE_Read_Interrupted) { StartOKServer(); net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; TestCompletionCallback callback; net::HostResolver::RequestInfo info(server_.kHostName, server_.kOKHTTPSPort); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(net::OK, rv); net::ClientSocket *transport = new net::TCPClientSocket(addr); diff --git a/net/socket/ssl_test_util.cc b/net/socket/ssl_test_util.cc index 101cbf5..f615662 100644 --- a/net/socket/ssl_test_util.cc +++ b/net/socket/ssl_test_util.cc @@ -246,9 +246,9 @@ bool TestServerLauncher::WaitToStart(const std::string& host_name, int port) { // Verify that the webserver is actually started. // Otherwise tests can fail if they run faster than Python can start. net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; net::HostResolver::RequestInfo info(host_name, port); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); if (rv != net::OK) return false; diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index 5d9e630..9cd62e8 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -225,7 +225,7 @@ class TCPClientSocketPoolTest : public testing::Test { protected: TCPClientSocketPoolTest() : pool_(new TCPClientSocketPool(kMaxSocketsPerGroup, - new HostResolver, + &host_resolver_, &client_socket_factory_)) {} virtual void SetUp() { @@ -242,6 +242,7 @@ class TCPClientSocketPoolTest : public testing::Test { } ScopedHostMapper scoped_host_mapper_; + HostResolver host_resolver_; MockClientSocketFactory client_socket_factory_; scoped_refptr<ClientSocketPool> pool_; std::vector<TestSocketRequest*> request_order_; diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index 91b0e57..519d938 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -86,9 +86,9 @@ void TCPClientSocketTest::SetUp() { listen_port_ = port; AddressList addr; - scoped_refptr<HostResolver> resolver(new HostResolver); + HostResolver resolver; HostResolver::RequestInfo info("localhost", listen_port_); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); CHECK(rv == OK); sock_.reset(new TCPClientSocket(addr)); } diff --git a/net/socket/tcp_pinger_unittest.cc b/net/socket/tcp_pinger_unittest.cc index c807007..1d94ddd 100644 --- a/net/socket/tcp_pinger_unittest.cc +++ b/net/socket/tcp_pinger_unittest.cc @@ -65,10 +65,10 @@ void TCPPingerTest::SetUp() { TEST_F(TCPPingerTest, Ping) { net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; net::HostResolver::RequestInfo info("localhost", listen_port_); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(rv, net::OK); net::TCPPinger pinger(addr); @@ -78,13 +78,13 @@ TEST_F(TCPPingerTest, Ping) { TEST_F(TCPPingerTest, PingFail) { net::AddressList addr; - scoped_refptr<net::HostResolver> resolver(new net::HostResolver); + net::HostResolver resolver; // "Kill" "server" listen_sock_ = NULL; net::HostResolver::RequestInfo info("localhost", listen_port_); - int rv = resolver->Resolve(info, &addr, NULL, NULL); + int rv = resolver.Resolve(info, &addr, NULL, NULL); EXPECT_EQ(rv, net::OK); net::TCPPinger pinger(addr); diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 783c91d..68022f2 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -127,14 +127,14 @@ int main(int argc, char**argv) { // Do work here. MessageLoop loop; - scoped_refptr<net::HostResolver> host_resolver(new net::HostResolver); + net::HostResolver host_resolver; scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); net::HttpTransactionFactory* factory = NULL; if (use_cache) { - factory = new net::HttpCache(host_resolver, proxy_service.get(), 0); + factory = new net::HttpCache(&host_resolver, proxy_service.get(), 0); } else { factory = new net::HttpNetworkLayer( - net::ClientSocketFactory::GetDefaultFactory(), host_resolver, + net::ClientSocketFactory::GetDefaultFactory(), &host_resolver, proxy_service.get()); } diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index 486ade0..374af90 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -13,13 +13,13 @@ #include "base/ref_counted.h" #include "base/string_util.h" #include "net/base/cookie_policy.h" -#include "net/base/host_resolver.h" #include "net/ftp/ftp_auth_cache.h" namespace net { class CookieMonster; class ForceTLSState; class FtpTransactionFactory; +class HostResolver; class HttpTransactionFactory; class ProxyService; } @@ -113,7 +113,7 @@ class URLRequestContext : // The following members are expected to be initialized and owned by // subclasses. - scoped_refptr<net::HostResolver> host_resolver_; + net::HostResolver* host_resolver_; net::ProxyService* proxy_service_; net::HttpTransactionFactory* http_transaction_factory_; net::FtpTransactionFactory* ftp_transaction_factory_; diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 415fb1c..f5452be 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -59,6 +59,7 @@ class URLRequestHttpCacheContext : public URLRequestContext { delete cookie_store_; delete http_transaction_factory_; delete proxy_service_; + delete host_resolver_; } }; diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index dcc1757..a4ec2fe 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -51,7 +51,10 @@ class TestURLRequestContext : public URLRequestContext { } explicit TestURLRequestContext(const std::string& proxy) { - host_resolver_ = new net::HostResolver; + // TODO(eroman): we turn off host caching to see if synchronous + // host resolving interacts poorly with client socket pool. [experiment] + // http://crbug.com/13952 + host_resolver_ = new net::HostResolver(0, 0); net::ProxyConfig proxy_config; proxy_config.proxy_rules.ParseFromString(proxy); proxy_service_ = net::ProxyService::CreateFixed(proxy_config); @@ -63,6 +66,7 @@ class TestURLRequestContext : public URLRequestContext { virtual ~TestURLRequestContext() { delete http_transaction_factory_; delete proxy_service_; + delete host_resolver_; } }; |