| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Limit the size of hostnames that will be resolved to combat issues in | 56 // Limit the size of hostnames that will be resolved to combat issues in |
| 57 // some platform's resolvers. | 57 // some platform's resolvers. |
| 58 const size_t kMaxHostLength = 4096; | 58 const size_t kMaxHostLength = 4096; |
| 59 | 59 |
| 60 // Default TTL for successful resolutions with ProcTask. | 60 // Default TTL for successful resolutions with ProcTask. |
| 61 const unsigned kCacheEntryTTLSeconds = 60; | 61 const unsigned kCacheEntryTTLSeconds = 60; |
| 62 | 62 |
| 63 // Default TTL for unsuccessful resolutions with ProcTask. | 63 // Default TTL for unsuccessful resolutions with ProcTask. |
| 64 const unsigned kNegativeCacheEntryTTLSeconds = 0; | 64 const unsigned kNegativeCacheEntryTTLSeconds = 0; |
| 65 | 65 |
| 66 // Maximum of 6 concurrent resolver threads (excluding retries). | |
| 67 // Some routers (or resolvers) appear to start to provide host-not-found if | |
| 68 // too many simultaneous resolutions are pending. This number needs to be | |
| 69 // further optimized, but 8 is what FF currently does. We found some routers | |
| 70 // that limit this to 6, so we're temporarily holding it at that level. | |
| 71 static const size_t kDefaultMaxProcTasks = 6u; | |
| 72 | |
| 73 // We use a separate histogram name for each platform to facilitate the | 66 // We use a separate histogram name for each platform to facilitate the |
| 74 // display of error codes by their symbolic name (since each platform has | 67 // display of error codes by their symbolic name (since each platform has |
| 75 // different mappings). | 68 // different mappings). |
| 76 const char kOSErrorsForGetAddrinfoHistogramName[] = | 69 const char kOSErrorsForGetAddrinfoHistogramName[] = |
| 77 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
| 78 "Net.OSErrorsForGetAddrinfo_Win"; | 71 "Net.OSErrorsForGetAddrinfo_Win"; |
| 79 #elif defined(OS_MACOSX) | 72 #elif defined(OS_MACOSX) |
| 80 "Net.OSErrorsForGetAddrinfo_Mac"; | 73 "Net.OSErrorsForGetAddrinfo_Mac"; |
| 81 #elif defined(OS_LINUX) | 74 #elif defined(OS_LINUX) |
| 82 "Net.OSErrorsForGetAddrinfo_Linux"; | 75 "Net.OSErrorsForGetAddrinfo_Linux"; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 if (total_count_ == 0) | 395 if (total_count_ == 0) |
| 403 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); | 396 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); |
| 404 } | 397 } |
| 405 | 398 |
| 406 private: | 399 private: |
| 407 RequestPriority highest_priority_; | 400 RequestPriority highest_priority_; |
| 408 size_t total_count_; | 401 size_t total_count_; |
| 409 size_t counts_[NUM_PRIORITIES]; | 402 size_t counts_[NUM_PRIORITIES]; |
| 410 }; | 403 }; |
| 411 | 404 |
| 412 //----------------------------------------------------------------------------- | 405 } // namespace |
| 413 | |
| 414 HostResolver* CreateHostResolver(size_t max_concurrent_resolves, | |
| 415 size_t max_retry_attempts, | |
| 416 HostCache* cache, | |
| 417 scoped_ptr<DnsClient> dns_client, | |
| 418 NetLog* net_log) { | |
| 419 if (max_concurrent_resolves == HostResolver::kDefaultParallelism) | |
| 420 max_concurrent_resolves = kDefaultMaxProcTasks; | |
| 421 | |
| 422 // TODO(szym): Add experiments with reserved slots for higher priority | |
| 423 // requests. | |
| 424 | |
| 425 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves); | |
| 426 | |
| 427 HostResolverImpl* resolver = new HostResolverImpl( | |
| 428 cache, | |
| 429 limits, | |
| 430 HostResolverImpl::ProcTaskParams(NULL, max_retry_attempts), | |
| 431 dns_client.Pass(), | |
| 432 net_log); | |
| 433 | |
| 434 return resolver; | |
| 435 } | |
| 436 | |
| 437 } // anonymous namespace | |
| 438 | 406 |
| 439 //----------------------------------------------------------------------------- | 407 //----------------------------------------------------------------------------- |
| 440 | 408 |
| 441 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, | |
| 442 size_t max_retry_attempts, | |
| 443 NetLog* net_log) { | |
| 444 return CreateHostResolver(max_concurrent_resolves, | |
| 445 max_retry_attempts, | |
| 446 HostCache::CreateDefaultCache(), | |
| 447 scoped_ptr<DnsClient>(NULL), | |
| 448 net_log); | |
| 449 } | |
| 450 | |
| 451 HostResolver* CreateNonCachingSystemHostResolver(size_t max_concurrent_resolves, | |
| 452 size_t max_retry_attempts, | |
| 453 NetLog* net_log) { | |
| 454 return CreateHostResolver(max_concurrent_resolves, | |
| 455 max_retry_attempts, | |
| 456 NULL, | |
| 457 scoped_ptr<DnsClient>(NULL), | |
| 458 net_log); | |
| 459 } | |
| 460 | |
| 461 HostResolver* CreateAsyncHostResolver(size_t max_concurrent_resolves, | |
| 462 size_t max_retry_attempts, | |
| 463 NetLog* net_log) { | |
| 464 #if !defined(ENABLE_BUILT_IN_DNS) | |
| 465 NOTREACHED(); | |
| 466 return NULL; | |
| 467 #else | |
| 468 return CreateHostResolver(max_concurrent_resolves, | |
| 469 max_retry_attempts, | |
| 470 HostCache::CreateDefaultCache(), | |
| 471 DnsClient::CreateClient(net_log), | |
| 472 net_log); | |
| 473 #endif // !defined(ENABLE_BUILT_IN_DNS) | |
| 474 } | |
| 475 | |
| 476 //----------------------------------------------------------------------------- | |
| 477 | |
| 478 // Holds the data for a request that could not be completed synchronously. | 409 // Holds the data for a request that could not be completed synchronously. |
| 479 // It is owned by a Job. Canceled Requests are only marked as canceled rather | 410 // It is owned by a Job. Canceled Requests are only marked as canceled rather |
| 480 // than removed from the Job's |requests_| list. | 411 // than removed from the Job's |requests_| list. |
| 481 class HostResolverImpl::Request { | 412 class HostResolverImpl::Request { |
| 482 public: | 413 public: |
| 483 Request(const BoundNetLog& source_net_log, | 414 Request(const BoundNetLog& source_net_log, |
| 484 const BoundNetLog& request_net_log, | 415 const BoundNetLog& request_net_log, |
| 485 const RequestInfo& info, | 416 const RequestInfo& info, |
| 486 const CompletionCallback& callback, | 417 const CompletionCallback& callback, |
| 487 AddressList* addresses) | 418 AddressList* addresses) |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 size_t max_retry_attempts) | 1599 size_t max_retry_attempts) |
| 1669 : resolver_proc(resolver_proc), | 1600 : resolver_proc(resolver_proc), |
| 1670 max_retry_attempts(max_retry_attempts), | 1601 max_retry_attempts(max_retry_attempts), |
| 1671 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), | 1602 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), |
| 1672 retry_factor(2) { | 1603 retry_factor(2) { |
| 1673 } | 1604 } |
| 1674 | 1605 |
| 1675 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} | 1606 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} |
| 1676 | 1607 |
| 1677 HostResolverImpl::HostResolverImpl( | 1608 HostResolverImpl::HostResolverImpl( |
| 1678 HostCache* cache, | 1609 scoped_ptr<HostCache> cache, |
| 1679 const PrioritizedDispatcher::Limits& job_limits, | 1610 const PrioritizedDispatcher::Limits& job_limits, |
| 1680 const ProcTaskParams& proc_params, | 1611 const ProcTaskParams& proc_params, |
| 1681 scoped_ptr<DnsClient> dns_client, | 1612 scoped_ptr<DnsClient> dns_client, |
| 1682 NetLog* net_log) | 1613 NetLog* net_log) |
| 1683 : cache_(cache), | 1614 : cache_(cache.Pass()), |
| 1684 dispatcher_(job_limits), | 1615 dispatcher_(job_limits), |
| 1685 max_queued_jobs_(job_limits.total_jobs * 100u), | 1616 max_queued_jobs_(job_limits.total_jobs * 100u), |
| 1686 proc_params_(proc_params), | 1617 proc_params_(proc_params), |
| 1687 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 1618 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 1688 weak_ptr_factory_(this), | 1619 weak_ptr_factory_(this), |
| 1689 dns_client_(dns_client.Pass()), | 1620 dns_client_(dns_client.Pass()), |
| 1690 received_dns_config_(false), | 1621 received_dns_config_(false), |
| 1691 ipv6_probe_monitoring_(false), | 1622 ipv6_probe_monitoring_(false), |
| 1692 additional_resolver_flags_(0), | 1623 additional_resolver_flags_(0), |
| 1693 net_log_(net_log) { | 1624 net_log_(net_log) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 // |this| may be deleted inside AbortAllInProgressJobs(). | 2092 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2162 if (self) | 2093 if (self) |
| 2163 TryServingAllJobsFromHosts(); | 2094 TryServingAllJobsFromHosts(); |
| 2164 } | 2095 } |
| 2165 | 2096 |
| 2166 bool HostResolverImpl::HaveDnsConfig() const { | 2097 bool HostResolverImpl::HaveDnsConfig() const { |
| 2167 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 2098 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
| 2168 } | 2099 } |
| 2169 | 2100 |
| 2170 } // namespace net | 2101 } // namespace net |
| OLD | NEW |