diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/dns/host_resolver.cc | 30 | ||||
-rw-r--r-- | net/dns/host_resolver.h | 11 | ||||
-rw-r--r-- | net/dns/host_resolver_impl.cc | 62 | ||||
-rw-r--r-- | net/dns/host_resolver_impl.h | 27 | ||||
-rw-r--r-- | net/dns/host_resolver_impl_unittest.cc | 75 | ||||
-rw-r--r-- | net/tools/gdig/gdig.cc | 9 |
6 files changed, 96 insertions, 118 deletions
diff --git a/net/dns/host_resolver.cc b/net/dns/host_resolver.cc index 0435091..147a5a6e 100644 --- a/net/dns/host_resolver.cc +++ b/net/dns/host_resolver.cc @@ -24,10 +24,11 @@ namespace { // that limit this to 6, so we're temporarily holding it at that level. const size_t kDefaultMaxProcTasks = 6u; -PrioritizedDispatcher::Limits GetDispatcherLimits( - const HostResolver::Options& options) { - PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, - options.max_concurrent_resolves); +} // namespace + +PrioritizedDispatcher::Limits HostResolver::Options::GetDispatcherLimits() + const { + PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves); // If not using default, do not use the field trial. if (limits.total_jobs != HostResolver::kDefaultParallelism) @@ -82,8 +83,6 @@ PrioritizedDispatcher::Limits GetDispatcherLimits( return limits; } -} // namespace - HostResolver::Options::Options() : max_concurrent_resolves(kDefaultParallelism), max_retry_attempts(kDefaultRetryAttempts), @@ -116,22 +115,15 @@ base::Value* HostResolver::GetDnsConfigAsValue() const { } // static -scoped_ptr<HostResolver> -HostResolver::CreateSystemResolver(const Options& options, NetLog* net_log) { - scoped_ptr<HostCache> cache; - if (options.enable_caching) - cache = HostCache::CreateDefaultCache(); - return scoped_ptr<HostResolver>(new HostResolverImpl( - cache.Pass(), - GetDispatcherLimits(options), - HostResolverImpl::ProcTaskParams(NULL, options.max_retry_attempts), - net_log)); +scoped_ptr<HostResolver> HostResolver::CreateSystemResolver( + const Options& options, + NetLog* net_log) { + return scoped_ptr<HostResolver>(new HostResolverImpl(options, net_log)); } // static -scoped_ptr<HostResolver> -HostResolver::CreateDefaultResolver(NetLog* net_log) { - return CreateSystemResolver(Options(), net_log); +scoped_ptr<HostResolver> HostResolver::CreateDefaultResolver(NetLog* net_log) { + return scoped_ptr<HostResolver>(new HostResolverImpl(Options(), net_log)); } HostResolver::HostResolver() { diff --git a/net/dns/host_resolver.h b/net/dns/host_resolver.h index 2964fe6..5216329 100644 --- a/net/dns/host_resolver.h +++ b/net/dns/host_resolver.h @@ -13,6 +13,7 @@ #include "net/base/host_port_pair.h" #include "net/base/net_export.h" #include "net/base/net_util.h" +#include "net/base/prioritized_dispatcher.h" #include "net/base/request_priority.h" namespace base { @@ -48,6 +49,8 @@ class NET_EXPORT HostResolver { struct NET_EXPORT Options { Options(); + PrioritizedDispatcher::Limits GetDispatcherLimits() const; + size_t max_concurrent_resolves; size_t max_retry_attempts; bool enable_caching; @@ -105,13 +108,11 @@ class NET_EXPORT HostResolver { // Opaque type used to cancel a request. typedef void* RequestHandle; - // This value can be passed into CreateSystemResolver as the - // |max_concurrent_resolves| parameter. It will select a default level of - // concurrency. + // Set Options.max_concurrent_resolves to this to select a default level + // of concurrency. static const size_t kDefaultParallelism = 0; - // This value can be passed into CreateSystemResolver as the - // |max_retry_attempts| parameter. + // Set Options.max_retry_attempts to this to select a default retry value. static const size_t kDefaultRetryAttempts = -1; // If any completion callbacks are pending when the resolver is destroyed, diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc index dd11336..d5602a4 100644 --- a/net/dns/host_resolver_impl.cc +++ b/net/dns/host_resolver_impl.cc @@ -1258,9 +1258,9 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job, DCHECK(!is_queued()); PrioritizedDispatcher::Handle handle; if (!at_head) { - handle = resolver_->dispatcher_.Add(this, priority()); + handle = resolver_->dispatcher_->Add(this, priority()); } else { - handle = resolver_->dispatcher_.AddAtHead(this, priority()); + handle = resolver_->dispatcher_->AddAtHead(this, priority()); } // The dispatcher could have started |this| in the above call to Add, which // could have called Schedule again. In that case |handle| will be null, @@ -1399,10 +1399,10 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job, void ReduceToOneJobSlot() { DCHECK_GE(num_occupied_job_slots_, 1u); if (is_queued()) { - resolver_->dispatcher_.Cancel(handle_); + resolver_->dispatcher_->Cancel(handle_); handle_.Reset(); } else if (num_occupied_job_slots_ > 1) { - resolver_->dispatcher_.OnJobFinished(); + resolver_->dispatcher_->OnJobFinished(); --num_occupied_job_slots_; } DCHECK_EQ(1u, num_occupied_job_slots_); @@ -1412,7 +1412,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job, if (is_queued()) { if (priority() != static_cast<RequestPriority>(handle_.priority())) priority_change_time_ = base::TimeTicks::Now(); - handle_ = resolver_->dispatcher_.ChangePriority(handle_, priority()); + handle_ = resolver_->dispatcher_->ChangePriority(handle_, priority()); } } @@ -1659,9 +1659,9 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job, KillDnsTask(); // Signal dispatcher that a slot has opened. - resolver_->dispatcher_.OnJobFinished(); + resolver_->dispatcher_->OnJobFinished(); } else if (is_queued()) { - resolver_->dispatcher_.Cancel(handle_); + resolver_->dispatcher_->Cancel(handle_); handle_.Reset(); } @@ -1783,19 +1783,17 @@ HostResolverImpl::ProcTaskParams::ProcTaskParams( max_retry_attempts(max_retry_attempts), unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), retry_factor(2) { + // Maximum of 4 retry attempts for host resolution. + static const size_t kDefaultMaxRetryAttempts = 4u; + if (max_retry_attempts == HostResolver::kDefaultRetryAttempts) + max_retry_attempts = kDefaultMaxRetryAttempts; } HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} -HostResolverImpl::HostResolverImpl( - scoped_ptr<HostCache> cache, - const PrioritizedDispatcher::Limits& job_limits, - const ProcTaskParams& proc_params, - NetLog* net_log) - : cache_(cache.Pass()), - dispatcher_(job_limits), - max_queued_jobs_(job_limits.total_jobs * 100u), - proc_params_(proc_params), +HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) + : max_queued_jobs_(0), + proc_params_(NULL, options.max_retry_attempts), net_log_(net_log), default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), received_dns_config_(false), @@ -1807,14 +1805,14 @@ HostResolverImpl::HostResolverImpl( fallback_to_proctask_(true), weak_ptr_factory_(this), probe_weak_ptr_factory_(this) { + if (options.enable_caching) + cache_ = HostCache::CreateDefaultCache(); - DCHECK_GE(dispatcher_.num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); - - // Maximum of 4 retry attempts for host resolution. - static const size_t kDefaultMaxRetryAttempts = 4u; + PrioritizedDispatcher::Limits job_limits = options.GetDispatcherLimits(); + dispatcher_.reset(new PrioritizedDispatcher(job_limits)); + max_queued_jobs_ = job_limits.total_jobs * 100u; - if (proc_params_.max_retry_attempts == HostResolver::kDefaultRetryAttempts) - proc_params_.max_retry_attempts = kDefaultMaxRetryAttempts; + DCHECK_GE(dispatcher_->num_priorities(), static_cast<size_t>(NUM_PRIORITIES)); #if defined(OS_WIN) EnsureWinsockInit(); @@ -1842,7 +1840,7 @@ HostResolverImpl::HostResolverImpl( HostResolverImpl::~HostResolverImpl() { // Prevent the dispatcher from starting new jobs. - dispatcher_.SetLimitsToZero(); + dispatcher_->SetLimitsToZero(); // It's now safe for Jobs to call KillDsnTask on destruction, because // OnJobComplete will not start any new jobs. STLDeleteValues(&jobs_); @@ -1852,7 +1850,7 @@ HostResolverImpl::~HostResolverImpl() { } void HostResolverImpl::SetMaxQueuedJobs(size_t value) { - DCHECK_EQ(0u, dispatcher_.num_queued_jobs()); + DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); DCHECK_GT(value, 0u); max_queued_jobs_ = value; } @@ -1900,8 +1898,8 @@ int HostResolverImpl::Resolve(const RequestInfo& info, job->Schedule(false); // Check for queue overflow. - if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { - Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); + if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { + Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); DCHECK(evicted); evicted->OnEvicted(); // Deletes |evicted|. if (evicted == job) { @@ -2203,8 +2201,8 @@ void HostResolverImpl::AbortAllInProgressJobs() { // aborting the old ones. This is needed so that it won't start the second // DnsTransaction for a job in |jobs_to_abort| if the DnsConfig just became // invalid. - PrioritizedDispatcher::Limits limits = dispatcher_.GetLimits(); - dispatcher_.SetLimits( + PrioritizedDispatcher::Limits limits = dispatcher_->GetLimits(); + dispatcher_->SetLimits( PrioritizedDispatcher::Limits(limits.reserved_slots.size(), 0)); // Life check to bail once |this| is deleted. @@ -2217,20 +2215,20 @@ void HostResolverImpl::AbortAllInProgressJobs() { } if (self) - dispatcher_.SetLimits(limits); + dispatcher_->SetLimits(limits); } void HostResolverImpl::AbortDnsTasks() { // Pause the dispatcher so it won't start any new dispatcher jobs while // aborting the old ones. This is needed so that it won't start the second // DnsTransaction for a job if the DnsConfig just changed. - PrioritizedDispatcher::Limits limits = dispatcher_.GetLimits(); - dispatcher_.SetLimits( + PrioritizedDispatcher::Limits limits = dispatcher_->GetLimits(); + dispatcher_->SetLimits( PrioritizedDispatcher::Limits(limits.reserved_slots.size(), 0)); for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) it->second->AbortDnsTask(); - dispatcher_.SetLimits(limits); + dispatcher_->SetLimits(limits); } void HostResolverImpl::TryServingAllJobsFromHosts() { diff --git a/net/dns/host_resolver_impl.h b/net/dns/host_resolver_impl.h index 7bcc800..7a0fb57 100644 --- a/net/dns/host_resolver_impl.h +++ b/net/dns/host_resolver_impl.h @@ -16,7 +16,6 @@ #include "base/time/time.h" #include "net/base/net_export.h" #include "net/base/network_change_notifier.h" -#include "net/base/prioritized_dispatcher.h" #include "net/dns/host_cache.h" #include "net/dns/host_resolver.h" #include "net/dns/host_resolver_proc.h" @@ -97,21 +96,17 @@ class NET_EXPORT HostResolverImpl uint32 retry_factor; }; - // Creates a HostResolver that first uses the local cache |cache|, and then - // falls back to |proc_params.resolver_proc|. + // Creates a HostResolver as specified by |options|. // - // If |cache| is NULL, then no caching is used. Otherwise we take - // ownership of the |cache| pointer, and will free it during destruction. + // If Options.enable_caching is true, a cache is created using + // HostCache::CreateDefaultCache(). Otherwise no cache is used. // - // |job_limits| specifies the maximum number of jobs that the resolver will - // run at once. This upper-bounds the total number of outstanding - // DNS transactions (not counting retransmissions and retries). + // Options.GetDispatcherLimits() determines the maximum number of jobs that + // the resolver will run at once. This upper-bounds the total number of + // outstanding DNS transactions (not counting retransmissions and retries). // // |net_log| must remain valid for the life of the HostResolverImpl. - HostResolverImpl(scoped_ptr<HostCache> cache, - const PrioritizedDispatcher::Limits& job_limits, - const ProcTaskParams& proc_params, - NetLog* net_log); + HostResolverImpl(const Options& options, 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 @@ -145,6 +140,10 @@ class NET_EXPORT HostResolverImpl virtual HostCache* GetHostCache() OVERRIDE; virtual base::Value* GetDnsConfigAsValue() const OVERRIDE; + void set_proc_params_for_test(const ProcTaskParams& proc_params) { + proc_params_ = proc_params; + } + private: friend class HostResolverImplTest; class Job; @@ -237,7 +236,7 @@ class NET_EXPORT HostResolverImpl // HostResolverImpl::Job could occupy multiple PrioritizedDispatcher job // slots. size_t num_running_dispatcher_jobs_for_tests() const { - return dispatcher_.num_running_jobs(); + return dispatcher_->num_running_jobs(); } // Cache of host resolution results. @@ -247,7 +246,7 @@ class NET_EXPORT HostResolverImpl JobMap jobs_; // Starts Jobs according to their priority and the configured limits. - PrioritizedDispatcher dispatcher_; + scoped_ptr<PrioritizedDispatcher> dispatcher_; // Limit on the maximum number of jobs queued in |dispatcher_|. size_t max_queued_jobs_; diff --git a/net/dns/host_resolver_impl_unittest.cc b/net/dns/host_resolver_impl_unittest.cc index efb63e8..4ab8fdf 100644 --- a/net/dns/host_resolver_impl_unittest.cc +++ b/net/dns/host_resolver_impl_unittest.cc @@ -24,7 +24,6 @@ #include "net/base/net_util.h" #include "net/dns/dns_client.h" #include "net/dns/dns_test_util.h" -#include "net/dns/host_cache.h" #include "net/dns/mock_host_resolver.h" #include "testing/gtest/include/gtest/gtest.h" @@ -35,9 +34,12 @@ namespace { const size_t kMaxJobs = 10u; const size_t kMaxRetryAttempts = 4u; -PrioritizedDispatcher::Limits DefaultLimits() { - PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, kMaxJobs); - return limits; +HostResolver::Options DefaultOptions() { + HostResolver::Options options; + options.max_concurrent_resolves = kMaxJobs; + options.max_retry_attempts = kMaxRetryAttempts; + options.enable_caching = true; + return options; } HostResolverImpl::ProcTaskParams DefaultParams( @@ -422,7 +424,7 @@ class HostResolverImplTest : public testing::Test { HostResolverImplTest() : proc_(new MockHostResolverProc()) {} void CreateResolver() { - CreateResolverWithLimitsAndParams(DefaultLimits(), + CreateResolverWithLimitsAndParams(kMaxJobs, DefaultParams(proc_.get())); } @@ -431,8 +433,7 @@ class HostResolverImplTest : public testing::Test { void CreateSerialResolver() { HostResolverImpl::ProcTaskParams params = DefaultParams(proc_.get()); params.max_retry_attempts = 0u; - PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, 1); - CreateResolverWithLimitsAndParams(limits, params); + CreateResolverWithLimitsAndParams(1u, params); } protected: @@ -470,10 +471,12 @@ class HostResolverImplTest : public testing::Test { } virtual void CreateResolverWithLimitsAndParams( - const PrioritizedDispatcher::Limits& limits, + size_t max_concurrent_resolves, const HostResolverImpl::ProcTaskParams& params) { - resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), - limits, params, NULL)); + HostResolverImpl::Options options = DefaultOptions(); + options.max_concurrent_resolves = max_concurrent_resolves; + resolver_.reset(new HostResolverImpl(options, NULL)); + resolver_->set_proc_params_for_test(params); } // The Request will not be made until a call to |Resolve()|, and the Job will @@ -835,10 +838,10 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { set_handler(new MyHandler()); // Turn off caching for this host resolver. - resolver_.reset(new HostResolverImpl(scoped_ptr<HostCache>(), - DefaultLimits(), - DefaultParams(proc_.get()), - NULL)); + HostResolver::Options options = DefaultOptions(); + options.enable_caching = false; + resolver_.reset(new HostResolverImpl(options, NULL)); + resolver_->set_proc_params_for_test(DefaultParams(proc_.get())); for (size_t i = 0; i < 4; ++i) { EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80 + i)->Resolve()) << i; @@ -1272,11 +1275,8 @@ TEST_F(HostResolverImplTest, MultipleAttempts) { // (500ms * 3). params.unresponsive_delay = base::TimeDelta::FromMilliseconds(500); - resolver_.reset( - new HostResolverImpl(HostCache::CreateDefaultCache(), - DefaultLimits(), - params, - NULL)); + resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); + resolver_->set_proc_params_for_test(params); // Resolve "host1". HostResolver::RequestInfo info(HostPortPair("host1", 70)); @@ -1353,12 +1353,12 @@ class HostResolverImplDnsTest : public HostResolverImplTest { // HostResolverImplTest implementation: virtual void CreateResolverWithLimitsAndParams( - const PrioritizedDispatcher::Limits& limits, + size_t max_concurrent_resolves, const HostResolverImpl::ProcTaskParams& params) OVERRIDE { - resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), - limits, - params, - NULL)); + HostResolverImpl::Options options = DefaultOptions(); + options.max_concurrent_resolves = max_concurrent_resolves; + resolver_.reset(new HostResolverImpl(options, NULL)); + resolver_->set_proc_params_for_test(params); // Disable IPv6 support probing. resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); @@ -1688,10 +1688,9 @@ TEST_F(HostResolverImplDnsTest, DontDisableDnsClientOnSporadicFailure) { TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) { // Use regular SystemHostResolverCall! scoped_refptr<HostResolverProc> proc(new SystemHostResolverProc()); - resolver_.reset(new HostResolverImpl(HostCache::CreateDefaultCache(), - DefaultLimits(), - DefaultParams(proc.get()), - NULL)); + resolver_.reset(new HostResolverImpl(DefaultOptions(), NULL)); + resolver_->set_proc_params_for_test(DefaultParams(proc.get())); + resolver_->SetDnsClient( scoped_ptr<DnsClient>(new MockDnsClient(DnsConfig(), dns_rules_))); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); @@ -1786,9 +1785,7 @@ TEST_F(HostResolverImplDnsTest, CancelWithTwoTransactionsActive) { // Delete a resolver with some active requests and some queued requests. TEST_F(HostResolverImplDnsTest, DeleteWithActiveTransactions) { // At most 10 Jobs active at once. - CreateResolverWithLimitsAndParams( - PrioritizedDispatcher::Limits(NUM_PRIORITIES, 10u), - DefaultParams(proc_.get())); + CreateResolverWithLimitsAndParams(10u, DefaultParams(proc_.get())); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); ChangeDnsConfig(CreateValidDnsConfig()); @@ -1899,9 +1896,7 @@ TEST_F(HostResolverImplDnsTest, SerialResolver) { // Test the case where the AAAA query is started when another transaction // completes. TEST_F(HostResolverImplDnsTest, AAAAStartsAfterOtherJobFinishes) { - CreateResolverWithLimitsAndParams( - PrioritizedDispatcher::Limits(NUM_PRIORITIES, 2), - DefaultParams(proc_.get())); + CreateResolverWithLimitsAndParams(2u, DefaultParams(proc_.get())); set_fallback_to_proctask(false); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); ChangeDnsConfig(CreateValidDnsConfig()); @@ -1960,9 +1955,7 @@ TEST_F(HostResolverImplDnsTest, InvalidDnsConfigWithPendingRequests) { // make sure that aborting the first HostResolverImpl::Job does not trigger // another DnsTransaction on the second Job when it releases its second // prioritized dispatcher slot. - CreateResolverWithLimitsAndParams( - PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), - DefaultParams(proc_.get())); + CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); ChangeDnsConfig(CreateValidDnsConfig()); @@ -2003,9 +1996,7 @@ TEST_F(HostResolverImplDnsTest, // occupying two slots has its DnsTask aborted is the case most likely to run // into problems. for (size_t limit = 1u; limit < 6u; ++limit) { - CreateResolverWithLimitsAndParams( - PrioritizedDispatcher::Limits(NUM_PRIORITIES, limit), - DefaultParams(proc_.get())); + CreateResolverWithLimitsAndParams(limit, DefaultParams(proc_.get())); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); ChangeDnsConfig(CreateValidDnsConfig()); @@ -2052,9 +2043,7 @@ TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) { // make sure that aborting the first HostResolverImpl::Job does not trigger // another DnsTransaction on the second Job when it releases its second // prioritized dispatcher slot. - CreateResolverWithLimitsAndParams( - PrioritizedDispatcher::Limits(NUM_PRIORITIES, 3u), - DefaultParams(proc_.get())); + CreateResolverWithLimitsAndParams(3u, DefaultParams(proc_.get())); resolver_->SetDefaultAddressFamily(ADDRESS_FAMILY_UNSPECIFIED); ChangeDnsConfig(CreateValidDnsConfig()); diff --git a/net/tools/gdig/gdig.cc b/net/tools/gdig/gdig.cc index a55dbde..fbee886 100644 --- a/net/tools/gdig/gdig.cc +++ b/net/tools/gdig/gdig.cc @@ -421,12 +421,11 @@ void GDig::OnDnsConfig(const DnsConfig& dns_config_const) { scoped_ptr<DnsClient> dns_client(DnsClient::CreateClient(NULL)); dns_client->SetConfig(dns_config); + HostResolver::Options options; + options.max_concurrent_resolves = parallellism_; + options.max_retry_attempts = 1u; scoped_ptr<HostResolverImpl> resolver( - new HostResolverImpl( - HostCache::CreateDefaultCache(), - PrioritizedDispatcher::Limits(NUM_PRIORITIES, parallellism_), - HostResolverImpl::ProcTaskParams(NULL, 1), - log_.get())); + new HostResolverImpl(options, log_.get())); resolver->SetDnsClient(dns_client.Pass()); resolver_ = resolver.Pass(); |