diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 23:57:54 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 23:57:54 +0000 |
commit | 73c4532bd7f5b84bc822a4acca5c5b8affef4129 (patch) | |
tree | dc2a525aab1bda568b52ea78e72c8be79b9165dc | |
parent | 3209e71131849f3e0d513cd3fd8dca881f05d531 (diff) | |
download | chromium_src-73c4532bd7f5b84bc822a4acca5c5b8affef4129.zip chromium_src-73c4532bd7f5b84bc822a4acca5c5b8affef4129.tar.gz chromium_src-73c4532bd7f5b84bc822a4acca5c5b8affef4129.tar.bz2 |
Stop refcounting HostResolver.
BUG=46049
TEST=none
Review URL: http://codereview.chromium.org/3601002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61256 0039d316-1c4b-4281-b951-d872f2087c98
62 files changed, 339 insertions, 286 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 42a8a17..2b55f6e 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -169,9 +169,10 @@ void IOThread::Init() { network_change_observer_.reset( new LoggingNetworkChangeObserver(globals_->net_log.get())); - globals_->host_resolver = CreateGlobalHostResolver(globals_->net_log.get()); + globals_->host_resolver.reset( + CreateGlobalHostResolver(globals_->net_log.get())); globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( - globals_->host_resolver)); + globals_->host_resolver.get())); } void IOThread::CleanUp() { @@ -279,7 +280,7 @@ void IOThread::InitNetworkPredictorOnIOThread( chrome_browser_net::EnablePredictor(prefetching_enabled); predictor_ = new chrome_browser_net::Predictor( - globals_->host_resolver, + globals_->host_resolver.get(), max_dns_queue_delay, max_concurrent, preconnect_enabled); diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index f2f1310..a51d515 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -32,9 +32,7 @@ class IOThread : public BrowserProcessSubThread { public: struct Globals { scoped_ptr<ChromeNetLog> net_log; - // TODO(willchan): Stop reference counting HostResolver. It's owned by - // IOThread now. - scoped_refptr<net::HostResolver> host_resolver; + scoped_ptr<net::HostResolver> host_resolver; scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; scoped_ptr<net::URLSecurityManager> url_security_manager; ChromeNetworkDelegate network_delegate; diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index a9ed157..5819148 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -254,7 +254,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() { IOThread::Globals* io_thread_globals = io_thread()->globals(); // Global host resolver for the context. - context->set_host_resolver(io_thread_globals->host_resolver); + context->set_host_resolver(io_thread_globals->host_resolver.get()); context->set_http_auth_handler_factory( io_thread_globals->http_auth_handler_factory.get()); diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index 4f9d943..0ed9f94 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -12,6 +12,7 @@ #include "chrome/browser/importer/firefox_proxy_settings.h" #include "chrome/common/chrome_switches.h" #include "net/base/cookie_monster.h" +#include "net/base/host_resolver.h" #include "net/base/host_resolver_impl.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -71,6 +72,7 @@ class ExperimentURLRequestContext : public URLRequestContext { delete ftp_transaction_factory_; delete http_transaction_factory_; delete http_auth_handler_factory_; + delete host_resolver_; } private: @@ -79,10 +81,10 @@ class ExperimentURLRequestContext : public URLRequestContext { // error code. int CreateHostResolver( ConnectionTester::HostResolverExperiment experiment, - scoped_refptr<net::HostResolver>* host_resolver) { + net::HostResolver** host_resolver) { // Create a vanilla HostResolver that disables caching. const size_t kMaxJobs = 50u; - scoped_refptr<net::HostResolverImpl> impl = + net::HostResolverImpl* impl = new net::HostResolverImpl(NULL, NULL, kMaxJobs, NULL); *host_resolver = impl; diff --git a/chrome/browser/net/predictor.h b/chrome/browser/net/predictor.h index c840a00..e6363ad 100644 --- a/chrome/browser/net/predictor.h +++ b/chrome/browser/net/predictor.h @@ -270,8 +270,8 @@ class Predictor : public base::RefCountedThreadSafe<Predictor> { // reduction mode, and discard all queued (but not yet assigned) resolutions. const base::TimeDelta max_dns_queue_delay_; - // The host resovler we warm DNS entries for. - scoped_refptr<net::HostResolver> host_resolver_; + // The host resolver we warm DNS entries for. + net::HostResolver* const host_resolver_; // Are we currently using preconnection, rather than just DNS resolution, for // subresources and omni-box search URLs. diff --git a/chrome/browser/net/predictor_unittest.cc b/chrome/browser/net/predictor_unittest.cc index fd8bd9a..071c66f 100644 --- a/chrome/browser/net/predictor_unittest.cc +++ b/chrome/browser/net/predictor_unittest.cc @@ -99,7 +99,7 @@ class PredictorTest : public testing::Test { ChromeThread io_thread_; protected: - scoped_refptr<net::MockCachingHostResolver> host_resolver_; + scoped_ptr<net::MockCachingHostResolver> host_resolver_; // Shorthand to access TimeDelta of PredictorInit::kMaxQueueingDelayMs. // (It would be a static constant... except style rules preclude that :-/ ). @@ -109,10 +109,11 @@ class PredictorTest : public testing::Test { //------------------------------------------------------------------------------ TEST_F(PredictorTest, StartupShutdownTest) { - scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> testing_master = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); testing_master->Shutdown(); } @@ -122,10 +123,11 @@ TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { new net::WaitingHostResolverProc(NULL); host_resolver_->Reset(resolver_proc); - scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> testing_master = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); GURL localhost("http://localhost:80"); UrlList names; @@ -147,10 +149,11 @@ TEST_F(PredictorTest, ShutdownWhenResolutionIsPendingTest) { } TEST_F(PredictorTest, SingleLookupTest) { - scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> testing_master = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); GURL goog("http://www.google.com:80"); @@ -178,10 +181,11 @@ TEST_F(PredictorTest, SingleLookupTest) { TEST_F(PredictorTest, ConcurrentLookupTest) { host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<Predictor> testing_master = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> testing_master = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); GURL goog("http://www.google.com:80"), goog2("http://gmail.google.com.com:80"), @@ -228,11 +232,11 @@ TEST_F(PredictorTest, ConcurrentLookupTest) { TEST_F(PredictorTest, MassiveConcurrentLookupTest) { host_resolver_->rules()->AddSimulatedFailure("*.notfound"); - scoped_refptr<Predictor> testing_master = new Predictor( - host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> testing_master = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); UrlList names; for (int i = 0; i < 100; i++) @@ -348,10 +352,11 @@ static bool GetDataFromSerialization(const GURL& motivation, // Make sure nil referral lists really have no entries, and no latency listed. TEST_F(PredictorTest, ReferrerSerializationNilTest) { - scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> predictor = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); scoped_ptr<ListValue> referral_list(NewEmptySerializationList()); predictor->SerializeReferrers(referral_list.get()); EXPECT_EQ(1U, referral_list->GetSize()); @@ -366,10 +371,11 @@ TEST_F(PredictorTest, ReferrerSerializationNilTest) { // deserialized into the database, and can be extracted back out via // serialization without being changed. TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { - scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> predictor = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); const GURL motivation_url("http://www.google.com:91"); const GURL subresource_url("http://icons.google.com:90"); const double kUseRate = 23.4; @@ -393,10 +399,11 @@ TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) { // Make sure the Trim() functionality works as expected. TEST_F(PredictorTest, ReferrerSerializationTrimTest) { - scoped_refptr<Predictor> predictor = new Predictor(host_resolver_, - default_max_queueing_delay_, - PredictorInit::kMaxPrefetchConcurrentLookups, - false); + scoped_refptr<Predictor> predictor = + new Predictor(host_resolver_.get(), + default_max_queueing_delay_, + PredictorInit::kMaxPrefetchConcurrentLookups, + false); GURL motivation_url("http://www.google.com:110"); GURL icon_subresource_url("http://icons.google.com:111"); diff --git a/jingle/notifier/communicator/xmpp_connection_generator.cc b/jingle/notifier/communicator/xmpp_connection_generator.cc index 0a78fef..469f3d4 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator.cc +++ b/jingle/notifier/communicator/xmpp_connection_generator.cc @@ -37,7 +37,7 @@ namespace notifier { XmppConnectionGenerator::XmppConnectionGenerator( - const scoped_refptr<net::HostResolver>& host_resolver, + net::HostResolver* host_resolver, const ConnectionOptions* options, bool try_ssltcp_first, const ServerInformation* server_list, diff --git a/jingle/notifier/communicator/xmpp_connection_generator.h b/jingle/notifier/communicator/xmpp_connection_generator.h index 26b040d..0cb969c 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator.h +++ b/jingle/notifier/communicator/xmpp_connection_generator.h @@ -40,7 +40,7 @@ class XmppConnectionGenerator : public sigslot::has_slots<> { // server_list is the list of connections to attempt in priority order. // server_count is the number of items in the server list. XmppConnectionGenerator( - const scoped_refptr<net::HostResolver>& host_resolver, + net::HostResolver* host_resolver, const ConnectionOptions* options, bool try_ssltcp_first, const ServerInformation* server_list, diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc index aea38e7..a9f411f 100644 --- a/jingle/notifier/listener/mediator_thread_impl.cc +++ b/jingle/notifier/listener/mediator_thread_impl.cc @@ -126,9 +126,9 @@ void MediatorThreadImpl::DoLogin( // TODO(akalin): Use an existing HostResolver from somewhere (maybe // the IOThread one). - host_resolver_ = + host_resolver_.reset( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL)); notifier::ServerInformation server_list[2]; int server_list_count = 0; @@ -171,7 +171,7 @@ void MediatorThreadImpl::DoDisconnect() { DCHECK_EQ(MessageLoop::current(), worker_message_loop()); LOG(INFO) << "P2P: Thread logging out of talk network."; login_.reset(); - host_resolver_ = NULL; + host_resolver_.reset(); base_task_.reset(); } diff --git a/jingle/notifier/listener/mediator_thread_impl.h b/jingle/notifier/listener/mediator_thread_impl.h index 76d296d..1792ca4 100644 --- a/jingle/notifier/listener/mediator_thread_impl.h +++ b/jingle/notifier/listener/mediator_thread_impl.h @@ -24,7 +24,6 @@ #include <vector> #include "base/basictypes.h" -#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/thread.h" #include "jingle/notifier/base/notifier_options.h" @@ -115,7 +114,7 @@ class MediatorThreadImpl const NotifierOptions notifier_options_; base::Thread worker_thread_; - scoped_refptr<net::HostResolver> host_resolver_; + scoped_ptr<net::HostResolver> host_resolver_; scoped_ptr<notifier::Login> login_; diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 1c0982d..9ee345a 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -8,7 +8,7 @@ #include <string> -#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "googleurl/src/gurl.h" #include "net/base/address_family.h" #include "net/base/completion_callback.h" @@ -31,7 +31,7 @@ class NetLog; // request at a time is to create a SingleRequestHostResolver wrapper around // HostResolver (which will automatically cancel the single request when it // goes out of scope). -class HostResolver : public base::RefCounted<HostResolver> { +class HostResolver { public: // The parameters for doing a Resolve(). A hostname and port are required, // the rest are optional (and have reasonable defaults). @@ -124,6 +124,11 @@ class HostResolver : public base::RefCounted<HostResolver> { // concurrency. static const size_t kDefaultParallelism = 0; + // If any completion callbacks are pending when the resolver is destroyed, + // the host resolutions are cancelled, and the completion callbacks will not + // be called. + virtual ~HostResolver(); + // Resolves the given hostname (or IP address literal), filling out the // |addresses| object upon success. The |info.port| parameter will be set as // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if @@ -174,15 +179,8 @@ class HostResolver : public base::RefCounted<HostResolver> { virtual void Shutdown() {} protected: - friend class base::RefCounted<HostResolver>; - HostResolver(); - // If any completion callbacks are pending when the resolver is destroyed, - // the host resolutions are cancelled, and the completion callbacks will not - // be called. - virtual ~HostResolver(); - private: DISALLOW_COPY_AND_ASSIGN(HostResolver); }; @@ -192,6 +190,7 @@ class HostResolver : public base::RefCounted<HostResolver> { // single hostname at a time and cancels this request when going out of scope. class SingleRequestHostResolver { public: + // |resolver| must remain valid for the lifetime of |this|. explicit SingleRequestHostResolver(HostResolver* resolver); // If a completion callback is pending when the resolver is destroyed, the @@ -216,7 +215,7 @@ class SingleRequestHostResolver { void OnResolveCompletion(int result); // The actual host resolver that will handle the request. - scoped_refptr<HostResolver> resolver_; + HostResolver* const resolver_; // The current request (if any). HostResolver::RequestHandle cur_request_; diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index b1002ab..7f6f7e8d 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -82,6 +82,11 @@ class HostResolverImpl : public HostResolver, size_t max_jobs, NetLog* net_log); + // If any completion callbacks are pending when the resolver is destroyed, + // the host resolutions are cancelled, and the completion callbacks will not + // be called. + virtual ~HostResolverImpl(); + // HostResolver methods: virtual int Resolve(const RequestInfo& info, AddressList* addresses, @@ -132,11 +137,6 @@ class HostResolverImpl : public HostResolver, typedef std::map<Key, scoped_refptr<Job> > JobMap; typedef std::vector<HostResolver::Observer*> ObserversList; - // If any completion callbacks are pending when the resolver is destroyed, - // the host resolutions are cancelled, and the completion callbacks will not - // be called. - virtual ~HostResolverImpl(); - // Returns the HostResolverProc to use for this instance. HostResolverProc* effective_resolver_proc() const { return resolver_proc_ ? diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 4b28b8c..07e00bf 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -226,8 +226,6 @@ class ResolveRequest { int result_; AddressList addrlist_; - // We don't use a scoped_refptr, to simplify deleting shared resolver in - // DeleteWithinCallback test. HostResolver* resolver_; Delegate* delegate_; @@ -265,7 +263,7 @@ TEST_F(HostResolverImplTest, SynchronousLookup) { new RuleBasedHostResolverProc(NULL); resolver_proc->AddRule("just.testing", "192.168.1.42"); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); @@ -297,7 +295,7 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) { new RuleBasedHostResolverProc(NULL); resolver_proc->AddRule("just.testing", "192.168.1.42"); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); HostResolver::RequestInfo info(HostPortPair("just.testing", kPortnum)); @@ -336,7 +334,7 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { CapturingNetLog net_log(CapturingNetLog::kUnbounded); CapturingBoundNetLog log(CapturingNetLog::kUnbounded); { - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, @@ -396,7 +394,7 @@ TEST_F(HostResolverImplTest, NumericIPv4Address) { new RuleBasedHostResolverProc(NULL); resolver_proc->AllowDirectLookup("*"); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); AddressList addrlist; const int kPortnum = 5555; @@ -421,7 +419,7 @@ TEST_F(HostResolverImplTest, NumericIPv6Address) { // Resolve a plain IPv6 address. Don't worry about [brackets], because // the caller should have removed them. - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); AddressList addrlist; const int kPortnum = 5555; @@ -451,7 +449,7 @@ TEST_F(HostResolverImplTest, EmptyHost) { new RuleBasedHostResolverProc(NULL); resolver_proc->AllowDirectLookup("*"); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); AddressList addrlist; const int kPortnum = 5555; @@ -465,7 +463,7 @@ TEST_F(HostResolverImplTest, LongHost) { new RuleBasedHostResolverProc(NULL); resolver_proc->AllowDirectLookup("*"); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); AddressList addrlist; const int kPortnum = 5555; @@ -528,7 +526,7 @@ TEST_F(HostResolverImplTest, DeDupeRequests) { scoped_refptr<CapturingHostResolverProc> resolver_proc = new CapturingHostResolverProc(NULL); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); // The class will receive callbacks for when each resolve completes. It @@ -538,11 +536,11 @@ TEST_F(HostResolverImplTest, DeDupeRequests) { // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc 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.get(), "a", 80, &verifier); + ResolveRequest req2(host_resolver.get(), "b", 80, &verifier); + ResolveRequest req3(host_resolver.get(), "b", 81, &verifier); + ResolveRequest req4(host_resolver.get(), "a", 82, &verifier); + ResolveRequest req5(host_resolver.get(), "b", 83, &verifier); // Ready, Set, GO!!! resolver_proc->Signal(); @@ -579,7 +577,7 @@ TEST_F(HostResolverImplTest, CancelMultipleRequests) { scoped_refptr<CapturingHostResolverProc> resolver_proc = new CapturingHostResolverProc(NULL); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); // The class will receive callbacks for when each resolve completes. It @@ -589,11 +587,11 @@ TEST_F(HostResolverImplTest, CancelMultipleRequests) { // Start 5 requests, duplicating hosts "a" and "b". Since the resolver_proc 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.get(), "a", 80, &verifier); + ResolveRequest req2(host_resolver.get(), "b", 80, &verifier); + ResolveRequest req3(host_resolver.get(), "b", 81, &verifier); + ResolveRequest req4(host_resolver.get(), "a", 82, &verifier); + ResolveRequest req5(host_resolver.get(), "b", 83, &verifier); // Cancel everything except request 4. req1.Cancel(); @@ -666,7 +664,7 @@ TEST_F(HostResolverImplTest, CancelWithinCallback) { scoped_refptr<CapturingHostResolverProc> resolver_proc = new CapturingHostResolverProc(NULL); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(resolver_proc)); // The class will receive callbacks for when each resolve completes. It @@ -676,10 +674,10 @@ TEST_F(HostResolverImplTest, CancelWithinCallback) { // Start 4 requests, duplicating hosts "a". Since the resolver_proc 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.get(), "a", 80, &verifier); + ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); + ResolveRequest req3(host_resolver.get(), "a", 82, &verifier); + ResolveRequest req4(host_resolver.get(), "a", 83, &verifier); // Once "a:80" completes, it will cancel "a:81" and "a:82". verifier.SetRequestsToCancel(&req2, &req3); @@ -696,16 +694,15 @@ class DeleteWithinCallbackVerifier : public ResolveRequest::Delegate { public: // |host_resolver| is the resolver that the the resolve requests were started // with. - DeleteWithinCallbackVerifier(HostResolver* host_resolver) + explicit DeleteWithinCallbackVerifier(HostResolver* host_resolver) : host_resolver_(host_resolver) {} 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; + // Deletes the host resolver. + host_resolver_.reset(); // Quit after returning from OnCompleted (to give it a chance at // incorrectly running the cancelled tasks). @@ -713,7 +710,7 @@ class DeleteWithinCallbackVerifier : public ResolveRequest::Delegate { } private: - scoped_refptr<HostResolver> host_resolver_; + scoped_ptr<HostResolver> host_resolver_; DISALLOW_COPY_AND_ASSIGN(DeleteWithinCallbackVerifier); }; @@ -780,7 +777,7 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { new CapturingHostResolverProc(NULL); // Turn off caching for this host resolver. - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, NULL, kMaxJobs, NULL)); // The class will receive callbacks for when each resolve completes. It @@ -790,10 +787,10 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { // Start 4 requests, duplicating hosts "a". Since the resolver_proc 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.get(), "a", 80, &verifier); + ResolveRequest req2(host_resolver.get(), "a", 81, &verifier); + ResolveRequest req3(host_resolver.get(), "a", 82, &verifier); + ResolveRequest req4(host_resolver.get(), "a", 83, &verifier); // Ready, Set, GO!!! resolver_proc->Signal(); @@ -846,7 +843,7 @@ class BypassCacheVerifier : public ResolveRequest::Delegate { }; TEST_F(HostResolverImplTest, BypassCache) { - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(NULL)); // The class will receive callbacks for when each resolve completes. It @@ -854,7 +851,7 @@ TEST_F(HostResolverImplTest, BypassCache) { BypassCacheVerifier verifier; // Start a request. - ResolveRequest req1(host_resolver, "a", 80, &verifier); + ResolveRequest req1(host_resolver.get(), "a", 80, &verifier); // |verifier| will send quit message once all the requests have finished. MessageLoop::current()->Run(); @@ -931,7 +928,7 @@ class CapturingObserver : public HostResolver::Observer { // Does not test the cancellation notification since all resolves are // synchronous. TEST_F(HostResolverImplTest, Observers) { - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(NULL)); CapturingObserver observer; @@ -1009,7 +1006,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { CapturingObserver observer; { // Create a host resolver and attach an observer. - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( CreateHostResolverImpl(NULL)); host_resolver->AddObserver(&observer); @@ -1077,7 +1074,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { // Test that IP address changes flush the cache. TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs, NULL)); AddressList addrlist; @@ -1111,7 +1108,7 @@ TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { scoped_refptr<WaitingHostResolverProc> resolver_proc = new WaitingHostResolverProc(NULL); HostCache* cache = CreateDefaultCache(); - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, cache, kMaxJobs, NULL)); // Resolve "host1". @@ -1135,7 +1132,7 @@ TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { scoped_refptr<WaitingHostResolverProc> resolver_proc = new WaitingHostResolverProc(NULL); - scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver()); + scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); host_resolver->Reset(resolver_proc); const size_t kMaxOutstandingJobs = 1u; @@ -1171,11 +1168,11 @@ TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { public: ResolveWithinCallback( - const scoped_refptr<MockHostResolver>& host_resolver, + MockHostResolver* host_resolver, const HostResolver::RequestInfo& info) : host_resolver_(host_resolver), info_(info) { - DCHECK(host_resolver.get()); + DCHECK(host_resolver); } virtual void RunWithParams(const Tuple1<int>& params) { @@ -1197,7 +1194,7 @@ class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { } private: - const scoped_refptr<MockHostResolver> host_resolver_; + MockHostResolver* const host_resolver_; const HostResolver::RequestInfo info_; AddressList addrlist_; TestCompletionCallback callback_; @@ -1207,12 +1204,12 @@ class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > { TEST_F(HostResolverImplTest, OnlyAbortExistingRequestsOnIPAddressChange) { scoped_refptr<WaitingHostResolverProc> resolver_proc = new WaitingHostResolverProc(NULL); - scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver()); + scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver()); host_resolver->Reset(resolver_proc); // Resolve "host1". HostResolver::RequestInfo info(HostPortPair("host1", 70)); - ResolveWithinCallback callback(host_resolver, info); + ResolveWithinCallback callback(host_resolver.get(), info); AddressList addrlist; int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL, BoundNetLog()); @@ -1235,7 +1232,7 @@ TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. size_t kMaxJobs = 1u; - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, NULL)); @@ -1320,7 +1317,7 @@ TEST_F(HostResolverImplTest, CancelPendingRequest) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxJobs = 1u; - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs, NULL)); @@ -1383,7 +1380,7 @@ TEST_F(HostResolverImplTest, QueueOverflow) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); // Only allow up to 3 requests to be enqueued at a time. @@ -1461,7 +1458,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); @@ -1529,7 +1526,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); @@ -1595,7 +1592,7 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { new CapturingHostResolverProc(new EchoingHostResolverProc); const size_t kMaxOutstandingJobs = 10u; - scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + scoped_ptr<HostResolverImpl> host_resolver(new HostResolverImpl( resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs, NULL)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); diff --git a/net/base/mapped_host_resolver.cc b/net/base/mapped_host_resolver.cc index d81efc6..0e596f7 100644 --- a/net/base/mapped_host_resolver.cc +++ b/net/base/mapped_host_resolver.cc @@ -15,6 +15,9 @@ MappedHostResolver::MappedHostResolver(HostResolver* impl) : impl_(impl) { } +MappedHostResolver::~MappedHostResolver() { +} + int MappedHostResolver::Resolve(const RequestInfo& info, AddressList* addresses, CompletionCallback* callback, @@ -44,7 +47,4 @@ HostResolverImpl* MappedHostResolver::GetAsHostResolverImpl() { return impl_->GetAsHostResolverImpl(); } -MappedHostResolver::~MappedHostResolver() { -} - } // namespace net diff --git a/net/base/mapped_host_resolver.h b/net/base/mapped_host_resolver.h index 1f1bf1c..4a94fba 100644 --- a/net/base/mapped_host_resolver.h +++ b/net/base/mapped_host_resolver.h @@ -8,7 +8,7 @@ #include <string> -#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "net/base/host_mapping_rules.h" #include "net/base/host_resolver.h" @@ -21,8 +21,9 @@ namespace net { class MappedHostResolver : public HostResolver { public: // Creates a MappedHostResolver that forwards all of its requests through - // |impl|. + // |impl|. It takes ownership of |impl|. explicit MappedHostResolver(HostResolver* impl); + virtual ~MappedHostResolver(); // HostResolver methods: virtual int Resolve(const RequestInfo& info, @@ -53,9 +54,7 @@ class MappedHostResolver : public HostResolver { } private: - virtual ~MappedHostResolver(); - - scoped_refptr<HostResolver> impl_; + scoped_ptr<HostResolver> impl_; HostMappingRules rules_; }; diff --git a/net/base/mapped_host_resolver_unittest.cc b/net/base/mapped_host_resolver_unittest.cc index 06beeb7..3531003 100644 --- a/net/base/mapped_host_resolver_unittest.cc +++ b/net/base/mapped_host_resolver_unittest.cc @@ -16,15 +16,15 @@ namespace { TEST(MappedHostResolverTest, Inclusion) { // Create a mock host resolver, with specific hostname to IP mappings. - scoped_refptr<MockHostResolver> resolver_impl = new MockHostResolver(); + MockHostResolver* resolver_impl(new MockHostResolver()); resolver_impl->rules()->AddSimulatedFailure("*google.com"); resolver_impl->rules()->AddRule("baz.com", "192.168.1.5"); resolver_impl->rules()->AddRule("foo.com", "192.168.1.8"); resolver_impl->rules()->AddRule("proxy", "192.168.1.11"); // Create a remapped resolver that uses |resolver_impl|. - scoped_refptr<MappedHostResolver> resolver = - new MappedHostResolver(resolver_impl); + scoped_ptr<MappedHostResolver> resolver( + new MappedHostResolver(resolver_impl)); int rv; AddressList address_list; @@ -70,13 +70,13 @@ TEST(MappedHostResolverTest, Inclusion) { // Tests that exclusions are respected. TEST(MappedHostResolverTest, Exclusion) { // Create a mock host resolver, with specific hostname to IP mappings. - scoped_refptr<MockHostResolver> resolver_impl = new MockHostResolver(); + MockHostResolver* resolver_impl(new MockHostResolver()); resolver_impl->rules()->AddRule("baz", "192.168.1.5"); resolver_impl->rules()->AddRule("www.google.com", "192.168.1.3"); // Create a remapped resolver that uses |resolver_impl|. - scoped_refptr<MappedHostResolver> resolver = - new MappedHostResolver(resolver_impl); + scoped_ptr<MappedHostResolver> resolver( + new MappedHostResolver(resolver_impl)); int rv; AddressList address_list; @@ -106,13 +106,13 @@ TEST(MappedHostResolverTest, Exclusion) { TEST(MappedHostResolverTest, SetRulesFromString) { // Create a mock host resolver, with specific hostname to IP mappings. - scoped_refptr<MockHostResolver> resolver_impl = new MockHostResolver(); + MockHostResolver* resolver_impl(new MockHostResolver()); resolver_impl->rules()->AddRule("baz", "192.168.1.7"); resolver_impl->rules()->AddRule("bar", "192.168.1.9"); // Create a remapped resolver that uses |resolver_impl|. - scoped_refptr<MappedHostResolver> resolver = - new MappedHostResolver(resolver_impl); + scoped_ptr<MappedHostResolver> resolver( + new MappedHostResolver(resolver_impl)); int rv; AddressList address_list; @@ -139,7 +139,7 @@ TEST(MappedHostResolverTest, SetRulesFromString) { // Parsing bad rules should silently discard the rule (and never crash). TEST(MappedHostResolverTest, ParseInvalidRules) { - scoped_refptr<MappedHostResolver> resolver = new MappedHostResolver(NULL); + scoped_ptr<MappedHostResolver> resolver(new MappedHostResolver(NULL)); EXPECT_FALSE(resolver->AddRuleFromString("xyz")); EXPECT_FALSE(resolver->AddRuleFromString("")); diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index f8c53a6..a70c6aa 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -102,7 +102,7 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { base::TimeDelta::FromSeconds(0)); } - impl_ = new HostResolverImpl(proc, cache, 50u, NULL); + impl_.reset(new HostResolverImpl(proc, cache, 50u, NULL)); } //----------------------------------------------------------------------------- diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h index 4b185b2..f158b9f 100644 --- a/net/base/mock_host_resolver.h +++ b/net/base/mock_host_resolver.h @@ -39,6 +39,8 @@ class RuleBasedHostResolverProc; // Base class shared by MockHostResolver and MockCachingHostResolver. class MockHostResolverBase : public HostResolver { public: + virtual ~MockHostResolverBase() {} + // HostResolver methods: virtual int Resolve(const RequestInfo& info, AddressList* addresses, @@ -68,19 +70,19 @@ class MockHostResolverBase : public HostResolver { protected: MockHostResolverBase(bool use_caching); - virtual ~MockHostResolverBase() {} - scoped_refptr<HostResolverImpl> impl_; + scoped_ptr<HostResolverImpl> impl_; scoped_refptr<RuleBasedHostResolverProc> rules_; bool synchronous_mode_; bool use_caching_; + + private: + DISALLOW_COPY_AND_ASSIGN(MockHostResolverBase); }; class MockHostResolver : public MockHostResolverBase { public: MockHostResolver() : MockHostResolverBase(false /*use_caching*/) {} - - private: virtual ~MockHostResolver() {} }; @@ -92,8 +94,6 @@ class MockHostResolver : public MockHostResolverBase { class MockCachingHostResolver : public MockHostResolverBase { public: MockCachingHostResolver() : MockHostResolverBase(true /*use_caching*/) {} - - private: ~MockCachingHostResolver() {} }; diff --git a/net/ftp/ftp_network_session.h b/net/ftp/ftp_network_session.h index 775bd01..3eab4ff 100644 --- a/net/ftp/ftp_network_session.h +++ b/net/ftp/ftp_network_session.h @@ -27,7 +27,7 @@ class FtpNetworkSession : public base::RefCounted<FtpNetworkSession> { ~FtpNetworkSession() {} - scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; FtpAuthCache auth_cache_; }; diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 8b877a9..01eff90 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -634,7 +634,7 @@ class FtpNetworkTransactionTest : public PlatformTest { public: FtpNetworkTransactionTest() : host_resolver_(new MockHostResolver), - session_(new FtpNetworkSession(host_resolver_)), + session_(new FtpNetworkSession(host_resolver_.get())), transaction_(session_.get(), &mock_socket_factory_) { } @@ -696,7 +696,7 @@ class FtpNetworkTransactionTest : public PlatformTest { ExecuteTransaction(ctrl_socket, request, expected_result); } - scoped_refptr<MockHostResolver> host_resolver_; + scoped_ptr<MockHostResolver> host_resolver_; scoped_refptr<FtpNetworkSession> session_; MockClientSocketFactory mock_socket_factory_; FtpNetworkTransaction transaction_; diff --git a/net/http/http_auth_handler_factory.h b/net/http/http_auth_handler_factory.h index 06d0f83..da6bad8 100644 --- a/net/http/http_auth_handler_factory.h +++ b/net/http/http_auth_handler_factory.h @@ -107,9 +107,11 @@ class HttpAuthHandlerFactory { // responsible for deleting the factory. // The default factory supports Basic, Digest, NTLM, and Negotiate schemes. // - // |host_resolver| is used by the Negotiate authentication handler to perform + // |resolver| is used by the Negotiate authentication handler to perform // CNAME lookups to generate a Kerberos SPN for the server. It must be - // non-NULL. + // non-NULL. |resolver| must remain valid for the lifetime of the + // HttpAuthHandlerRegistryFactory and any HttpAuthHandlers created by said + // factory. static HttpAuthHandlerRegistryFactory* CreateDefault(HostResolver* resolver); private: diff --git a/net/http/http_auth_handler_factory_unittest.cc b/net/http/http_auth_handler_factory_unittest.cc index 173e951..0b90f19 100644 --- a/net/http/http_auth_handler_factory_unittest.cc +++ b/net/http/http_auth_handler_factory_unittest.cc @@ -96,10 +96,10 @@ TEST(HttpAuthHandlerFactoryTest, RegistryFactory) { } TEST(HttpAuthHandlerFactoryTest, DefaultFactory) { - scoped_refptr<HostResolver> host_resolver(new MockHostResolver()); + scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); URLSecurityManagerAllow url_security_manager; scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)); + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); http_auth_handler_factory->SetURLSecurityManager( "negotiate", &url_security_manager); GURL server_origin("http://www.example.com"); diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h index 2ff4a9b..5f46ab1 100644 --- a/net/http/http_auth_handler_negotiate.h +++ b/net/http/http_auth_handler_negotiate.h @@ -85,7 +85,7 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { private: bool disable_cname_lookup_; bool use_port_; - scoped_refptr<HostResolver> resolver_; + HostResolver* resolver_; #if defined(OS_WIN) ULONG max_token_length_; bool first_creation_; @@ -148,7 +148,7 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { bool disable_cname_lookup_; bool use_port_; CompletionCallbackImpl<HttpAuthHandlerNegotiate> io_callback_; - scoped_refptr<HostResolver> resolver_; + HostResolver* const resolver_; // Members which are needed for DNS lookup + SPN. AddressList address_list_; diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc index 5c90b4f..9f87f78 100644 --- a/net/http/http_auth_handler_negotiate_unittest.cc +++ b/net/http/http_auth_handler_negotiate_unittest.cc @@ -32,7 +32,7 @@ class HttpAuthHandlerNegotiateTest : public PlatformTest { public: virtual void SetUp() { auth_library_.reset(new MockAuthLibrary()); - resolver_ = new MockHostResolver(); + resolver_.reset(new MockHostResolver()); resolver_->rules()->AddIPLiteralRule("alias", "10.0.0.2", "canonical.example.com"); @@ -40,7 +40,7 @@ class HttpAuthHandlerNegotiateTest : public PlatformTest { factory_.reset(new HttpAuthHandlerNegotiate::Factory()); factory_->set_url_security_manager(url_security_manager_.get()); factory_->set_library(auth_library_.get()); - factory_->set_host_resolver(resolver_); + factory_->set_host_resolver(resolver_.get()); } void SetupMocks(MockAuthLibrary* mock_library) { @@ -212,7 +212,7 @@ class HttpAuthHandlerNegotiateTest : public PlatformTest { scoped_ptr<SecPkgInfoW> security_package_; #endif scoped_ptr<MockAuthLibrary> auth_library_; - scoped_refptr<MockHostResolver> resolver_; + scoped_ptr<MockHostResolver> resolver_; scoped_ptr<URLSecurityManager> url_security_manager_; scoped_ptr<HttpAuthHandlerNegotiate::Factory> factory_; }; diff --git a/net/http/http_auth_unittest.cc b/net/http/http_auth_unittest.cc index 913e1cc..85bed8c 100644 --- a/net/http/http_auth_unittest.cc +++ b/net/http/http_auth_unittest.cc @@ -98,9 +98,9 @@ TEST(HttpAuthTest, ChooseBestChallenge) { GURL origin("http://www.example.com"); std::set<std::string> disabled_schemes; URLSecurityManagerAllow url_security_manager; - scoped_refptr<HostResolver> host_resolver(new MockHostResolver()); + scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)); + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); http_auth_handler_factory->SetURLSecurityManager( "negotiate", &url_security_manager); diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index 9d8b838..dc98c35 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -90,7 +90,7 @@ class HttpNetworkLayer : public HttpTransactionFactory, public NonThreadSafe { // The host resolver and proxy service that will be used when lazily // creating |session_|. - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; scoped_refptr<ProxyService> proxy_service_; // The SSL config service being used for the session. diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 27822ed..90a9adc 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -12,13 +12,23 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +namespace net { + +namespace { + class HttpNetworkLayerTest : public PlatformTest { }; TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { - net::HttpNetworkLayer factory(NULL, new net::MockHostResolver, - net::ProxyService::CreateDirect(), new net::SSLConfigServiceDefaults, - NULL, NULL, NULL); + MockHostResolver host_resolver; + net::HttpNetworkLayer factory( + NULL, + &host_resolver, + net::ProxyService::CreateDirect(), + new net::SSLConfigServiceDefaults, + NULL, + NULL, + NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -27,9 +37,15 @@ TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { } TEST_F(HttpNetworkLayerTest, Suspend) { - net::HttpNetworkLayer factory(NULL, new net::MockHostResolver, - net::ProxyService::CreateDirect(), new net::SSLConfigServiceDefaults, - NULL, NULL, NULL); + MockHostResolver host_resolver; + net::HttpNetworkLayer factory( + NULL, + &host_resolver, + net::ProxyService::CreateDirect(), + new net::SSLConfigServiceDefaults, + NULL, + NULL, + NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -67,9 +83,15 @@ TEST_F(HttpNetworkLayerTest, GET) { data_writes, arraysize(data_reads)); mock_socket_factory.AddSocketDataProvider(&data); - net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, - net::ProxyService::CreateDirect(), new net::SSLConfigServiceDefaults, - NULL, NULL, NULL); + MockHostResolver host_resolver; + net::HttpNetworkLayer factory( + &mock_socket_factory, + &host_resolver, + net::ProxyService::CreateDirect(), + new net::SSLConfigServiceDefaults, + NULL, + NULL, + NULL); TestCompletionCallback callback; @@ -94,3 +116,7 @@ TEST_F(HttpNetworkLayerTest, GET) { EXPECT_EQ(net::OK, rv); EXPECT_EQ("hello world", contents); } + +} // namespace + +} // namespace net diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 1ee0bc5..c0d1ca9 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -137,7 +137,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>, HttpAuthCache auth_cache_; SSLClientAuthCache ssl_client_auth_cache_; HttpAlternateProtocols alternate_protocols_; - scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; scoped_refptr<ProxyService> proxy_service_; scoped_refptr<SSLConfigService> ssl_config_service_; ClientSocketPoolManager socket_pool_manager_; diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index d8b6ffc..ad41eac 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -76,7 +76,7 @@ struct SessionDependencies { proxy_service(ProxyService::CreateDirect()), ssl_config_service(new SSLConfigServiceDefaults), http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)), + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), net_log(NULL) {} // Custom proxy service dependency. @@ -85,10 +85,10 @@ struct SessionDependencies { proxy_service(proxy_service), ssl_config_service(new SSLConfigServiceDefaults), http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)), + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), net_log(NULL) {} - scoped_refptr<MockHostResolverBase> host_resolver; + scoped_ptr<MockHostResolverBase> host_resolver; scoped_refptr<ProxyService> proxy_service; scoped_refptr<SSLConfigService> ssl_config_service; MockClientSocketFactory socket_factory; @@ -103,7 +103,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.get(), session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, @@ -5046,7 +5046,7 @@ void BypassHostCacheOnRefreshHelper(int load_flags) { SessionDependencies session_deps; // Select a host resolver that does caching. - session_deps.host_resolver = new MockCachingHostResolver; + session_deps.host_resolver.reset(new MockCachingHostResolver); scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( CreateSession(&session_deps))); diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc index fa49944..0f55e14 100644 --- a/net/http/http_proxy_client_socket_pool.cc +++ b/net/http/http_proxy_client_socket_pool.cc @@ -62,7 +62,7 @@ HttpProxyConnectJob::HttpProxyConnectJob( const base::TimeDelta& timeout_duration, TCPClientSocketPool* tcp_pool, SSLClientSocketPool* ssl_pool, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log) : ConnectJob(group_name, timeout_duration, delegate, @@ -271,7 +271,7 @@ HttpProxyClientSocketPool::HttpProxyClientSocketPool( int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, TCPClientSocketPool* tcp_pool, SSLClientSocketPool* ssl_pool, NetLog* net_log) diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h index ea3c51f..3ee215a 100644 --- a/net/http/http_proxy_client_socket_pool.h +++ b/net/http/http_proxy_client_socket_pool.h @@ -84,7 +84,7 @@ class HttpProxyConnectJob : public ConnectJob { const base::TimeDelta& timeout_duration, TCPClientSocketPool* tcp_pool, SSLClientSocketPool* ssl_pool, - const scoped_refptr<HostResolver> &host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log); virtual ~HttpProxyConnectJob(); @@ -130,7 +130,7 @@ class HttpProxyConnectJob : public ConnectJob { scoped_refptr<HttpProxySocketParams> params_; TCPClientSocketPool* const tcp_pool_; SSLClientSocketPool* const ssl_pool_; - const scoped_refptr<HostResolver> resolver_; + HostResolver* const resolver_; State next_state_; CompletionCallbackImpl<HttpProxyConnectJob> callback_; @@ -147,7 +147,7 @@ class HttpProxyClientSocketPool : public ClientSocketPool { int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, TCPClientSocketPool* tcp_pool, SSLClientSocketPool* ssl_pool, NetLog* net_log); @@ -215,7 +215,7 @@ class HttpProxyClientSocketPool : public ClientSocketPool { private: TCPClientSocketPool* const tcp_pool_; SSLClientSocketPool* const ssl_pool_; - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; NetLog* net_log_; base::TimeDelta timeout_; diff --git a/net/http/http_proxy_client_socket_pool_unittest.cc b/net/http/http_proxy_client_socket_pool_unittest.cc index 4a68d9b..e823596 100644 --- a/net/http/http_proxy_client_socket_pool_unittest.cc +++ b/net/http/http_proxy_client_socket_pool_unittest.cc @@ -57,8 +57,8 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam { &tcp_socket_pool_), host_resolver_(new MockHostResolver), http_auth_handler_factory_( - HttpAuthHandlerFactory::CreateDefault(host_resolver_)), - session_(new HttpNetworkSession(host_resolver_, + HttpAuthHandlerFactory::CreateDefault(host_resolver_.get())), + session_(new HttpNetworkSession(host_resolver_.get(), ProxyService::CreateDirect(), &socket_factory_, new SSLConfigServiceDefaults, @@ -131,7 +131,7 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam { MockSSLClientSocketPool ssl_socket_pool_; MockClientSocketFactory socket_factory_; - scoped_refptr<HostResolver> host_resolver_; + scoped_ptr<HostResolver> host_resolver_; scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_; scoped_refptr<HttpNetworkSession> session_; ClientSocketPoolHistograms http_proxy_histograms_; diff --git a/net/proxy/proxy_resolver_js_bindings.cc b/net/proxy/proxy_resolver_js_bindings.cc index 5f9307e..3888663 100644 --- a/net/proxy/proxy_resolver_js_bindings.cc +++ b/net/proxy/proxy_resolver_js_bindings.cc @@ -285,7 +285,7 @@ class DefaultJSBindings : public ProxyResolverJSBindings { } } - scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; NetLog* net_log_; }; diff --git a/net/proxy/proxy_resolver_js_bindings_unittest.cc b/net/proxy/proxy_resolver_js_bindings_unittest.cc index 3b10631..6b33a34 100644 --- a/net/proxy/proxy_resolver_js_bindings_unittest.cc +++ b/net/proxy/proxy_resolver_js_bindings_unittest.cc @@ -111,11 +111,11 @@ class MockFailingHostResolver : public HostResolver { }; TEST(ProxyResolverJSBindingsTest, DnsResolve) { - scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver); + scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), NULL)); std::string ip_address; @@ -138,9 +138,11 @@ TEST(ProxyResolverJSBindingsTest, DnsResolve) { } TEST(ProxyResolverJSBindingsTest, MyIpAddress) { + scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver); + // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(new MockHostResolver, NULL)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), NULL)); // Our IP address is always going to be 127.0.0.1, since we are using a // mock host resolver. @@ -163,11 +165,11 @@ TEST(ProxyResolverJSBindingsTest, MyIpAddress) { // myIpAddressEx() // dnsResolveEx() TEST(ProxyResolverJSBindingsTest, RestrictAddressFamily) { - scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver); + scoped_ptr<MockHostResolver> host_resolver(new MockHostResolver); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), NULL)); // Make it so requests resolve to particular address patterns based on family: // IPV4_ONLY --> 192.168.1.* @@ -219,12 +221,12 @@ TEST(ProxyResolverJSBindingsTest, RestrictAddressFamily) { // separated list of addresses (as opposed to the non-Ex versions which // just return the first result). TEST(ProxyResolverJSBindingsTest, ExFunctionsReturnList) { - scoped_refptr<HostResolver> host_resolver( + scoped_ptr<HostResolver> host_resolver( new MockHostResolverWithMultipleResults); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), NULL)); std::string ip_addresses; @@ -236,12 +238,12 @@ TEST(ProxyResolverJSBindingsTest, ExFunctionsReturnList) { } TEST(ProxyResolverJSBindingsTest, PerRequestDNSCache) { - scoped_refptr<MockFailingHostResolver> host_resolver( + scoped_ptr<MockFailingHostResolver> host_resolver( new MockFailingHostResolver); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), NULL)); std::string ip_address; @@ -286,14 +288,14 @@ TEST(ProxyResolverJSBindingsTest, PerRequestDNSCache) { // Test that when a binding is called, it logs to the per-request NetLog. TEST(ProxyResolverJSBindingsTest, NetLog) { - scoped_refptr<MockFailingHostResolver> host_resolver( + scoped_ptr<MockFailingHostResolver> host_resolver( new MockFailingHostResolver); CapturingNetLog global_log(CapturingNetLog::kUnbounded); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). scoped_ptr<ProxyResolverJSBindings> bindings( - ProxyResolverJSBindings::CreateDefault(host_resolver, &global_log)); + ProxyResolverJSBindings::CreateDefault(host_resolver.get(), &global_log)); // Attach a capturing NetLog as the current request's log stream. CapturingNetLog log(CapturingNetLog::kUnbounded); diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index 8980c0e..64754a4 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -49,6 +49,7 @@ class RequestContext : public URLRequestContext { private: ~RequestContext() { delete http_transaction_factory_; + delete host_resolver_; } }; diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index dfdacde..80a849a 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -185,7 +185,7 @@ class ProxyResolverFactoryForV8 : public ProxyResolverFactory { } private: - scoped_refptr<HostResolver> async_host_resolver_; + HostResolver* const async_host_resolver_; MessageLoop* io_loop_; // Thread-safe wrapper around a non-threadsafe NetLog implementation. This diff --git a/net/proxy/sync_host_resolver_bridge.cc b/net/proxy/sync_host_resolver_bridge.cc index 6c62c7d..bcb05d6 100644 --- a/net/proxy/sync_host_resolver_bridge.cc +++ b/net/proxy/sync_host_resolver_bridge.cc @@ -50,7 +50,7 @@ class SyncHostResolverBridge::Core // Not called on |host_resolver_loop_|. int WaitForResolveCompletion(); - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; MessageLoop* const host_resolver_loop_; net::CompletionCallbackImpl<Core> callback_; // The result from the current request (set on |host_resolver_loop_|). diff --git a/net/proxy/sync_host_resolver_bridge_unittest.cc b/net/proxy/sync_host_resolver_bridge_unittest.cc index c10c3e6..cd4264e 100644 --- a/net/proxy/sync_host_resolver_bridge_unittest.cc +++ b/net/proxy/sync_host_resolver_bridge_unittest.cc @@ -116,22 +116,23 @@ class SyncProxyResolver : public ProxyResolver { } private: - scoped_refptr<SyncHostResolverBridge> host_resolver_; + SyncHostResolverBridge* const host_resolver_; }; class SyncProxyResolverFactory : public ProxyResolverFactory { public: + // Takes ownership of |sync_host_resolver|. explicit SyncProxyResolverFactory(SyncHostResolverBridge* sync_host_resolver) : ProxyResolverFactory(false), sync_host_resolver_(sync_host_resolver) { } virtual ProxyResolver* CreateProxyResolver() { - return new SyncProxyResolver(sync_host_resolver_); + return new SyncProxyResolver(sync_host_resolver_.get()); } private: - scoped_refptr<SyncHostResolverBridge> sync_host_resolver_; + const scoped_ptr<SyncHostResolverBridge> sync_host_resolver_; }; // This helper thread is used to create the circumstances for the deadlock. @@ -145,18 +146,18 @@ class IOThread : public base::Thread { Stop(); } - const scoped_refptr<BlockableHostResolver>& async_resolver() { - return async_resolver_; + BlockableHostResolver* async_resolver() { + return async_resolver_.get(); } protected: virtual void Init() { - async_resolver_ = new BlockableHostResolver(); + async_resolver_.reset(new BlockableHostResolver()); // Create a synchronous host resolver that operates the async host // resolver on THIS thread. - scoped_refptr<SyncHostResolverBridge> sync_resolver = - new SyncHostResolverBridge(async_resolver_, message_loop()); + SyncHostResolverBridge* sync_resolver = + new SyncHostResolverBridge(async_resolver_.get(), message_loop()); proxy_resolver_.reset( new MultiThreadedProxyResolver( @@ -190,14 +191,12 @@ class IOThread : public base::Thread { // During the teardown sequence of the single threaded proxy resolver, // the outstanding host resolve should have been cancelled. EXPECT_TRUE(async_resolver_->was_request_cancelled()); - - async_resolver_ = NULL; } private: // This (async) host resolver will outlive the thread that is operating it // synchronously. - scoped_refptr<BlockableHostResolver> async_resolver_; + scoped_ptr<BlockableHostResolver> async_resolver_; scoped_ptr<ProxyResolver> proxy_resolver_; diff --git a/net/socket/client_socket_pool_manager.h b/net/socket/client_socket_pool_manager.h index 40f831f..02a73a9 100644 --- a/net/socket/client_socket_pool_manager.h +++ b/net/socket/client_socket_pool_manager.h @@ -99,7 +99,7 @@ class ClientSocketPoolManager : public NonThreadSafe { NetLog* const net_log_; ClientSocketFactory* const socket_factory_; - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; const scoped_refptr<ProxyService> proxy_service_; const scoped_refptr<SSLConfigService> ssl_config_service_; diff --git a/net/socket/socks5_client_socket_unittest.cc b/net/socket/socks5_client_socket_unittest.cc index 9ceffd0..43a441d 100644 --- a/net/socket/socks5_client_socket_unittest.cc +++ b/net/socket/socks5_client_socket_unittest.cc @@ -48,7 +48,7 @@ class SOCKS5ClientSocketTest : public PlatformTest { AddressList address_list_; ClientSocket* tcp_sock_; TestCompletionCallback callback_; - scoped_refptr<MockHostResolver> host_resolver_; + scoped_ptr<MockHostResolver> host_resolver_; scoped_ptr<SocketDataProvider> data_; private: diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index 129c075..cae333a 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -44,7 +44,7 @@ SOCKSConnectJob::SOCKSConnectJob( const scoped_refptr<SOCKSSocketParams>& socks_params, const base::TimeDelta& timeout_duration, TCPClientSocketPool* tcp_pool, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log) : ConnectJob(group_name, timeout_duration, delegate, @@ -181,7 +181,7 @@ SOCKSClientSocketPool::SOCKSClientSocketPool( int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, TCPClientSocketPool* tcp_pool, NetLog* net_log) : tcp_pool_(tcp_pool), diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index 383de63..a257d0f 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -58,7 +58,7 @@ class SOCKSConnectJob : public ConnectJob { const scoped_refptr<SOCKSSocketParams>& params, const base::TimeDelta& timeout_duration, TCPClientSocketPool* tcp_pool, - const scoped_refptr<HostResolver> &host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log); virtual ~SOCKSConnectJob(); @@ -92,7 +92,7 @@ class SOCKSConnectJob : public ConnectJob { scoped_refptr<SOCKSSocketParams> socks_params_; TCPClientSocketPool* const tcp_pool_; - const scoped_refptr<HostResolver> resolver_; + HostResolver* const resolver_; State next_state_; CompletionCallbackImpl<SOCKSConnectJob> callback_; @@ -108,7 +108,7 @@ class SOCKSClientSocketPool : public ClientSocketPool { int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, TCPClientSocketPool* tcp_pool, NetLog* net_log); @@ -178,7 +178,7 @@ class SOCKSClientSocketPool : public ClientSocketPool { private: TCPClientSocketPool* const tcp_pool_; - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; NetLog* net_log_; DISALLOW_COPY_AND_ASSIGN(SOCKSConnectJobFactory); diff --git a/net/socket/socks_client_socket_unittest.cc b/net/socket/socks_client_socket_unittest.cc index 8ed82b9..086b21d9 100644 --- a/net/socket/socks_client_socket_unittest.cc +++ b/net/socket/socks_client_socket_unittest.cc @@ -41,11 +41,8 @@ class SOCKSClientSocketTest : public PlatformTest { AddressList address_list_; ClientSocket* tcp_sock_; TestCompletionCallback callback_; - scoped_refptr<MockHostResolver> host_resolver_; + scoped_ptr<MockHostResolver> host_resolver_; scoped_ptr<SocketDataProvider> data_; - - private: - DISALLOW_COPY_AND_ASSIGN(SOCKSClientSocketTest); }; SOCKSClientSocketTest::SOCKSClientSocketTest() @@ -135,7 +132,9 @@ TEST_F(SOCKSClientSocketTest, CompleteHandshake) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, "localhost", 80, &log)); + host_resolver_.get(), + "localhost", 80, + &log)); // At this state the TCP connection is completed but not the SOCKS handshake. EXPECT_TRUE(tcp_sock_->IsConnected()); @@ -203,7 +202,9 @@ TEST_F(SOCKSClientSocketTest, HandshakeFailures) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, "localhost", 80, &log)); + host_resolver_.get(), + "localhost", 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -233,7 +234,9 @@ TEST_F(SOCKSClientSocketTest, PartialServerReads) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, "localhost", 80, &log)); + host_resolver_.get(), + "localhost", 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -265,7 +268,9 @@ TEST_F(SOCKSClientSocketTest, PartialClientWrites) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, "localhost", 80, &log)); + host_resolver_.get(), + "localhost", 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -291,7 +296,9 @@ TEST_F(SOCKSClientSocketTest, FailedSocketRead) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, "localhost", 80, &log)); + host_resolver_.get(), + "localhost", 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -322,7 +329,9 @@ TEST_F(SOCKSClientSocketTest, SOCKS4AFailedDNS) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, hostname, 80, &log)); + host_resolver_.get(), + hostname, 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -356,7 +365,9 @@ TEST_F(SOCKSClientSocketTest, SOCKS4AIfDomainInIPv6) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - host_resolver_, hostname, 80, &log)); + host_resolver_.get(), + hostname, 80, + &log)); int rv = user_sock_->Connect(&callback_); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -373,8 +384,7 @@ TEST_F(SOCKSClientSocketTest, SOCKS4AIfDomainInIPv6) { // Calls Disconnect() while a host resolve is in progress. The outstanding host // resolve should be cancelled. TEST_F(SOCKSClientSocketTest, DisconnectWhileHostResolveInProgress) { - scoped_refptr<HangingHostResolver> hanging_resolver = - new HangingHostResolver(); + scoped_ptr<HangingHostResolver> hanging_resolver(new HangingHostResolver()); // Doesn't matter what the socket data is, we will never use it -- garbage. MockWrite data_writes[] = { MockWrite(false, "", 0) }; @@ -382,7 +392,9 @@ TEST_F(SOCKSClientSocketTest, DisconnectWhileHostResolveInProgress) { user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes), - hanging_resolver, "foo", 80, NULL)); + hanging_resolver.get(), + "foo", 80, + NULL)); // Start connecting (will get stuck waiting for the host to resolve). int rv = user_sock_->Connect(&callback_); diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc index 6069f4d..ceea81b 100644 --- a/net/socket/ssl_client_socket_pool.cc +++ b/net/socket/ssl_client_socket_pool.cc @@ -74,7 +74,7 @@ SSLConnectJob::SSLConnectJob( SOCKSClientSocketPool* socks_pool, HttpProxyClientSocketPool* http_proxy_pool, ClientSocketFactory* client_socket_factory, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log) : ConnectJob(group_name, timeout_duration, delegate, @@ -377,7 +377,7 @@ SSLClientSocketPool::SSLClientSocketPool( int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, TCPClientSocketPool* tcp_pool, SOCKSClientSocketPool* socks_pool, diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h index c9a93ac..6aff091 100644 --- a/net/socket/ssl_client_socket_pool.h +++ b/net/socket/ssl_client_socket_pool.h @@ -90,7 +90,7 @@ class SSLConnectJob : public ConnectJob { SOCKSClientSocketPool* socks_pool, HttpProxyClientSocketPool* http_proxy_pool, ClientSocketFactory* client_socket_factory, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, Delegate* delegate, NetLog* net_log); virtual ~SSLConnectJob(); @@ -137,7 +137,7 @@ class SSLConnectJob : public ConnectJob { SOCKSClientSocketPool* const socks_pool_; HttpProxyClientSocketPool* const http_proxy_pool_; ClientSocketFactory* const client_socket_factory_; - const scoped_refptr<HostResolver> resolver_; + HostResolver* const resolver_; State next_state_; CompletionCallbackImpl<SSLConnectJob> callback_; @@ -161,7 +161,7 @@ class SSLClientSocketPool : public ClientSocketPool, int max_sockets, int max_sockets_per_group, ClientSocketPoolHistograms* histograms, - const scoped_refptr<HostResolver>& host_resolver, + HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, TCPClientSocketPool* tcp_pool, SOCKSClientSocketPool* socks_pool, @@ -245,7 +245,7 @@ class SSLClientSocketPool : public ClientSocketPool, SOCKSClientSocketPool* const socks_pool_; HttpProxyClientSocketPool* const http_proxy_pool_; ClientSocketFactory* const client_socket_factory_; - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; base::TimeDelta timeout_; NetLog* net_log_; diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc index feac473..91290bb 100644 --- a/net/socket/ssl_client_socket_pool_unittest.cc +++ b/net/socket/ssl_client_socket_pool_unittest.cc @@ -37,8 +37,8 @@ class SSLClientSocketPoolTest : public testing::Test { SSLClientSocketPoolTest() : host_resolver_(new MockHostResolver), http_auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault( - host_resolver_)), - session_(new HttpNetworkSession(host_resolver_, + host_resolver_.get())), + session_(new HttpNetworkSession(host_resolver_.get(), ProxyService::CreateDirect(), &socket_factory_, new SSLConfigServiceDefaults, @@ -76,7 +76,7 @@ class SSLClientSocketPoolTest : public testing::Test { kMaxSockets, kMaxSocketsPerGroup, &http_proxy_histograms_, - new MockHostResolver, + host_resolver_.get(), &tcp_socket_pool_, NULL, NULL) { @@ -122,7 +122,7 @@ class SSLClientSocketPoolTest : public testing::Test { } MockClientSocketFactory socket_factory_; - scoped_refptr<HostResolver> host_resolver_; + scoped_ptr<HostResolver> host_resolver_; scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_; scoped_refptr<HttpNetworkSession> session_; diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 70540f9..e545388 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -26,14 +26,10 @@ const net::SSLConfig kDefaultSSLConfig; class SSLClientSocketTest : public PlatformTest { public: SSLClientSocketTest() - : resolver_(net::CreateSystemHostResolver( - net::HostResolver::kDefaultParallelism, - NULL)), - socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { + : socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { } protected: - scoped_refptr<net::HostResolver> resolver_; net::ClientSocketFactory* socket_factory_; }; @@ -292,9 +288,10 @@ TEST_F(SSLClientSocketTest, Read) { EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( - socket_factory_->CreateSSLClientSocket(transport, - test_server.host_port_pair().host(), - kDefaultSSLConfig)); + socket_factory_->CreateSSLClientSocket( + transport, + test_server.host_port_pair().host(), + kDefaultSSLConfig)); rv = sock->Connect(&callback); if (rv != net::OK) { @@ -351,9 +348,10 @@ TEST_F(SSLClientSocketTest, Read_FullDuplex) { EXPECT_EQ(net::OK, rv); scoped_ptr<net::SSLClientSocket> sock( - socket_factory_->CreateSSLClientSocket(transport, - test_server.host_port_pair().host(), - kDefaultSSLConfig)); + socket_factory_->CreateSSLClientSocket( + transport, + test_server.host_port_pair().host(), + kDefaultSSLConfig)); rv = sock->Connect(&callback); if (rv != net::OK) { diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 1de3870..4837468 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -191,7 +191,7 @@ class TCPClientSocketPool : public ClientSocketPool { private: ClientSocketFactory* const client_socket_factory_; - const scoped_refptr<HostResolver> host_resolver_; + HostResolver* const host_resolver_; NetLog* net_log_; DISALLOW_COPY_AND_ASSIGN(TCPConnectJobFactory); diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index 1e701aa..c550232 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -285,7 +285,7 @@ class TCPClientSocketPoolTest : public testing::Test { pool_(kMaxSockets, kMaxSocketsPerGroup, histograms_.get(), - host_resolver_, + host_resolver_.get(), &client_socket_factory_, NULL) { } @@ -315,7 +315,7 @@ class TCPClientSocketPoolTest : public testing::Test { scoped_refptr<TCPSocketParams> params_; scoped_refptr<TCPSocketParams> low_params_; scoped_ptr<ClientSocketPoolHistograms> histograms_; - scoped_refptr<MockHostResolver> host_resolver_; + scoped_ptr<MockHostResolver> host_resolver_; MockClientSocketFactory client_socket_factory_; TCPClientSocketPool pool_; ClientSocketPoolTest test_base_; diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index 17ec51c..fdd966c 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -91,7 +91,7 @@ void TCPClientSocketTest::SetUp() { listen_port_ = port; AddressList addr; - scoped_refptr<HostResolver> resolver( + scoped_ptr<HostResolver> resolver( CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL)); HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 7abf2be..95f30ab 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -519,8 +519,8 @@ int SocketStream::DoResolveHost() { HostResolver::RequestInfo resolve_info(host_port_pair); - DCHECK(host_resolver_.get()); - resolver_.reset(new SingleRequestHostResolver(host_resolver_.get())); + DCHECK(host_resolver_); + resolver_.reset(new SingleRequestHostResolver(host_resolver_)); return resolver_->Resolve(resolve_info, &addresses_, &io_callback_, net_log_); } @@ -771,7 +771,7 @@ int SocketStream::DoSOCKSConnect() { if (proxy_info_.proxy_server().scheme() == ProxyServer::SCHEME_SOCKS5) s = new SOCKS5ClientSocket(s, req_info); else - s = new SOCKSClientSocket(s, req_info, host_resolver_.get()); + s = new SOCKSClientSocket(s, req_info, host_resolver_); socket_.reset(s); metrics_->OnSOCKSProxy(); return socket_->Connect(&io_callback_); diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index aaf48de..e1f2584 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -273,7 +273,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { UserDataMap user_data_; State next_state_; - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; HttpAuthHandlerFactory* http_auth_handler_factory_; ClientSocketFactory* factory_; diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index d8e2093..497020d 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -238,11 +238,13 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { delegate->SetOnReceivedData(NewCallback( test, &SocketStreamTest::DoCloseFlushPendingWriteTest)); + MockHostResolver host_resolver; + scoped_refptr<SocketStream> socket_stream = new SocketStream(GURL("ws://example.com/demo"), delegate.get()); socket_stream->set_context(new TestURLRequestContext()); - socket_stream->SetHostResolver(new MockHostResolver()); + socket_stream->SetHostResolver(&host_resolver); MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), @@ -333,7 +335,8 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { new SocketStream(GURL("ws://example.com/demo"), delegate.get()); socket_stream->set_context(new TestURLRequestContext("myproxy:70")); - socket_stream->SetHostResolver(new MockHostResolver()); + MockHostResolver host_resolver; + socket_stream->SetHostResolver(&host_resolver); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); diff --git a/net/spdy/spdy_test_util.h b/net/spdy/spdy_test_util.h index 13b3a2f..0da4d98 100644 --- a/net/spdy/spdy_test_util.h +++ b/net/spdy/spdy_test_util.h @@ -304,7 +304,7 @@ class SpdySessionDependencies { socket_factory(new MockClientSocketFactory), deterministic_socket_factory(new DeterministicMockClientSocketFactory), http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)) { + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) { // Note: The CancelledTransaction test does cleanup by running all // tasks in the message loop (RunAllPending). Unfortunately, that // doesn't clean up tasks on the host resolver thread; and @@ -322,10 +322,10 @@ class SpdySessionDependencies { socket_factory(new MockClientSocketFactory), deterministic_socket_factory(new DeterministicMockClientSocketFactory), http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver)) {} + HttpAuthHandlerFactory::CreateDefault(host_resolver.get())) {} // NOTE: host_resolver must be ordered before http_auth_handler_factory. - scoped_refptr<MockHostResolverBase> host_resolver; + scoped_ptr<MockHostResolverBase> host_resolver; scoped_refptr<ProxyService> proxy_service; scoped_refptr<SSLConfigService> ssl_config_service; scoped_ptr<MockClientSocketFactory> socket_factory; @@ -334,7 +334,7 @@ class SpdySessionDependencies { static HttpNetworkSession* SpdyCreateSession( SpdySessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, + return new HttpNetworkSession(session_deps->host_resolver.get(), session_deps->proxy_service, session_deps->socket_factory.get(), session_deps->ssl_config_service, @@ -345,7 +345,7 @@ class SpdySessionDependencies { } static HttpNetworkSession* SpdyCreateSessionDeterministic( SpdySessionDependencies* session_deps) { - return new HttpNetworkSession(session_deps->host_resolver, + return new HttpNetworkSession(session_deps->host_resolver.get(), session_deps->proxy_service, session_deps-> deterministic_socket_factory.get(), @@ -360,7 +360,7 @@ class SpdySessionDependencies { class SpdyURLRequestContext : public URLRequestContext { public: SpdyURLRequestContext() { - host_resolver_ = new MockHostResolver; + host_resolver_ = new MockHostResolver(); proxy_service_ = ProxyService::CreateDirect(); ssl_config_service_ = new SSLConfigServiceDefaults; http_auth_handler_factory_ = HttpAuthHandlerFactory::CreateDefault( @@ -383,6 +383,7 @@ class SpdyURLRequestContext : public URLRequestContext { virtual ~SpdyURLRequestContext() { delete http_transaction_factory_; delete http_auth_handler_factory_; + delete host_resolver_; } private: diff --git a/net/test/test_server.cc b/net/test/test_server.cc index f4eb64f..a1e1f13 100644 --- a/net/test/test_server.cc +++ b/net/test/test_server.cc @@ -204,7 +204,7 @@ std::string TestServer::GetScheme() const { bool TestServer::GetAddressList(AddressList* address_list) const { DCHECK(address_list); - scoped_refptr<HostResolver> resolver( + scoped_ptr<HostResolver> resolver( CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL)); HostResolver::RequestInfo info(host_port_pair_); int rv = resolver->Resolve(info, address_list, NULL, NULL, BoundNetLog()); diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 435dc93..9089462 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -135,7 +135,7 @@ int main(int argc, char**argv) { // Do work here. MessageLoop loop(MessageLoop::TYPE_IO); - scoped_refptr<net::HostResolver> host_resolver( + scoped_ptr<net::HostResolver> host_resolver( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, NULL)); @@ -145,16 +145,20 @@ int main(int argc, char**argv) { net::SSLConfigService::CreateSystemSSLConfigService()); net::HttpTransactionFactory* factory = NULL; scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory( - net::HttpAuthHandlerFactory::CreateDefault(host_resolver)); + net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); if (use_cache) { - factory = new net::HttpCache(host_resolver, proxy_service, + factory = new net::HttpCache(host_resolver.get(), proxy_service, ssl_config_service, http_auth_handler_factory.get(), NULL, NULL, net::HttpCache::DefaultBackend::InMemory(0)); } else { factory = new net::HttpNetworkLayer( - net::ClientSocketFactory::GetDefaultFactory(), host_resolver, - proxy_service, ssl_config_service, http_auth_handler_factory.get(), - NULL, NULL); + net::ClientSocketFactory::GetDefaultFactory(), + host_resolver.get(), + proxy_service, + ssl_config_service, + http_auth_handler_factory.get(), + NULL, + NULL); } { diff --git a/net/tools/hresolv/hresolv.cc b/net/tools/hresolv/hresolv.cc index 250a6b2..c5c1976 100644 --- a/net/tools/hresolv/hresolv.cc +++ b/net/tools/hresolv/hresolv.cc @@ -215,7 +215,7 @@ class DelayedResolve : public base::RefCounted<DelayedResolve> { std::string host_; net::AddressList address_list_; bool is_async_; - scoped_refptr<net::HostResolver> resolver_; + net::HostResolver* const resolver_; ResolverInvoker* invoker_; net::CompletionCallbackImpl<DelayedResolve> io_callback_; }; @@ -289,7 +289,7 @@ class ResolverInvoker { } MessageLoop message_loop_; - scoped_refptr<net::HostResolver> resolver_; + net::HostResolver* const resolver_; int remaining_requests_; }; @@ -451,9 +451,8 @@ int main(int argc, char** argv) { base::TimeDelta::FromMilliseconds(options.cache_ttl), base::TimeDelta::FromSeconds(0)); - scoped_refptr<net::HostResolver> host_resolver( - new net::HostResolverImpl(NULL, cache, 100u, NULL)); - ResolverInvoker invoker(host_resolver.get()); + net::HostResolverImpl host_resolver(NULL, cache, 100u, NULL); + ResolverInvoker invoker(&host_resolver); invoker.ResolveAll(hosts_and_times, options.async); CommandLine::Reset(); diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index 6ddc940..5198fa3 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -112,7 +112,7 @@ class URLRequestContext // The following members are expected to be initialized and owned by // subclasses. net::NetLog* net_log_; - scoped_refptr<net::HostResolver> host_resolver_; + net::HostResolver* host_resolver_; scoped_refptr<net::ProxyService> proxy_service_; scoped_refptr<net::SSLConfigService> ssl_config_service_; net::HttpTransactionFactory* http_transaction_factory_; diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 5900d61..706aff9 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -132,7 +132,7 @@ class TestURLRequestContext : public URLRequestContext { } explicit TestURLRequestContext(const std::string& proxy) { - host_resolver_ = + host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, NULL); net::ProxyConfig proxy_config; @@ -150,6 +150,7 @@ class TestURLRequestContext : public URLRequestContext { delete ftp_transaction_factory_; delete http_transaction_factory_; delete http_auth_handler_factory_; + delete host_resolver_; } private: diff --git a/net/websockets/websocket.h b/net/websockets/websocket.h index 19720ae..c729afc 100644 --- a/net/websockets/websocket.h +++ b/net/websockets/websocket.h @@ -115,7 +115,7 @@ class WebSocket : public base::RefCountedThreadSafe<WebSocket>, ProtocolVersion version_; scoped_refptr<URLRequestContext> context_; - scoped_refptr<HostResolver> host_resolver_; + HostResolver* host_resolver_; ClientSocketFactory* client_socket_factory_; DISALLOW_COPY_AND_ASSIGN(Request); diff --git a/net/websockets/websocket_unittest.cc b/net/websockets/websocket_unittest.cc index 4b65ae9..e711266 100644 --- a/net/websockets/websocket_unittest.cc +++ b/net/websockets/websocket_unittest.cc @@ -165,6 +165,7 @@ TEST_F(WebSocketTest, Connect) { StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); mock_socket_factory.AddSocketDataProvider(&data); + MockHostResolver host_resolver; WebSocket::Request* request( new WebSocket::Request(GURL("ws://example.com/demo"), @@ -173,7 +174,7 @@ TEST_F(WebSocketTest, Connect) { "ws://example.com/demo", WebSocket::DRAFT75, new TestURLRequestContext())); - request->SetHostResolver(new MockHostResolver()); + request->SetHostResolver(&host_resolver); request->SetClientSocketFactory(&mock_socket_factory); TestCompletionCallback callback; @@ -227,6 +228,7 @@ TEST_F(WebSocketTest, ServerSentData) { StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, arraysize(data_writes)); mock_socket_factory.AddSocketDataProvider(&data); + MockHostResolver host_resolver; WebSocket::Request* request( new WebSocket::Request(GURL("ws://example.com/demo"), @@ -235,7 +237,7 @@ TEST_F(WebSocketTest, ServerSentData) { "ws://example.com/demo", WebSocket::DRAFT75, new TestURLRequestContext())); - request->SetHostResolver(new MockHostResolver()); + request->SetHostResolver(&host_resolver); request->SetClientSocketFactory(&mock_socket_factory); TestCompletionCallback callback; diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index b6e7b59..0cb19ed 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -90,6 +90,7 @@ TestShellRequestContext::~TestShellRequestContext() { delete http_transaction_factory_; delete http_auth_handler_factory_; delete static_cast<net::StaticCookiePolicy*>(cookie_policy_); + delete host_resolver_; } const std::string& TestShellRequestContext::GetUserAgent( |