| 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.h" | 5 #include "net/base/host_resolver.h" |
| 6 | 6 |
| 7 #include "net/base/host_cache.h" |
| 8 #include "net/base/host_resolver_impl.h" |
| 9 #include "net/dns/dns_client.h" |
| 10 #include "net/dns/dns_config_service.h" |
| 11 |
| 7 namespace net { | 12 namespace net { |
| 8 | 13 |
| 14 namespace { |
| 15 |
| 16 // Maximum of 6 concurrent resolver threads (excluding retries). |
| 17 // Some routers (or resolvers) appear to start to provide host-not-found if |
| 18 // too many simultaneous resolutions are pending. This number needs to be |
| 19 // further optimized, but 8 is what FF currently does. We found some routers |
| 20 // that limit this to 6, so we're temporarily holding it at that level. |
| 21 const size_t kDefaultMaxProcTasks = 6u; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 HostResolver::Options::Options() |
| 26 : max_concurrent_resolves(kDefaultParallelism), |
| 27 max_retry_attempts(kDefaultRetryAttempts), |
| 28 enable_caching(true), |
| 29 enable_async(false) { |
| 30 } |
| 31 |
| 9 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair) | 32 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair) |
| 10 : host_port_pair_(host_port_pair), | 33 : host_port_pair_(host_port_pair), |
| 11 address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 34 address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 12 host_resolver_flags_(0), | 35 host_resolver_flags_(0), |
| 13 allow_cached_response_(true), | 36 allow_cached_response_(true), |
| 14 is_speculative_(false), | 37 is_speculative_(false), |
| 15 priority_(MEDIUM) { | 38 priority_(MEDIUM) { |
| 16 } | 39 } |
| 17 | 40 |
| 18 HostResolver::~HostResolver() { | 41 HostResolver::~HostResolver() { |
| 19 } | 42 } |
| 20 | 43 |
| 21 AddressFamily HostResolver::GetDefaultAddressFamily() const { | 44 AddressFamily HostResolver::GetDefaultAddressFamily() const { |
| 22 return ADDRESS_FAMILY_UNSPECIFIED; | 45 return ADDRESS_FAMILY_UNSPECIFIED; |
| 23 } | 46 } |
| 24 | 47 |
| 25 void HostResolver::ProbeIPv6Support() { | 48 void HostResolver::ProbeIPv6Support() { |
| 26 } | 49 } |
| 27 | 50 |
| 28 HostCache* HostResolver::GetHostCache() { | 51 HostCache* HostResolver::GetHostCache() { |
| 29 return NULL; | 52 return NULL; |
| 30 } | 53 } |
| 31 | 54 |
| 32 base::Value* HostResolver::GetDnsConfigAsValue() const { | 55 base::Value* HostResolver::GetDnsConfigAsValue() const { |
| 33 return NULL; | 56 return NULL; |
| 34 } | 57 } |
| 35 | 58 |
| 59 // static |
| 60 scoped_ptr<HostResolver> |
| 61 HostResolver::CreateSystemResolver(const Options& options, NetLog* net_log) { |
| 62 size_t max_concurrent_resolves = options.max_concurrent_resolves; |
| 63 if (max_concurrent_resolves == kDefaultParallelism) |
| 64 max_concurrent_resolves = kDefaultMaxProcTasks; |
| 65 |
| 66 scoped_ptr<HostCache> cache; |
| 67 if (options.enable_caching) |
| 68 cache = HostCache::CreateDefaultCache(); |
| 69 scoped_ptr<DnsClient> dns_client; |
| 70 if (options.enable_async) { |
| 71 #if !defined(ENABLE_BUILT_IN_DNS) |
| 72 NOTREACHED(); |
| 73 return scoped_ptr<HostResolver>(); |
| 74 #else |
| 75 dns_client = DnsClient::CreateClient(net_log); |
| 76 #endif |
| 77 } |
| 78 |
| 79 return scoped_ptr<HostResolver>(new HostResolverImpl( |
| 80 cache.Pass(), |
| 81 PrioritizedDispatcher::Limits(NUM_PRIORITIES, |
| 82 max_concurrent_resolves), |
| 83 HostResolverImpl::ProcTaskParams(NULL, options.max_retry_attempts), |
| 84 dns_client.Pass(), |
| 85 net_log)); |
| 86 } |
| 87 |
| 88 // static |
| 89 scoped_ptr<HostResolver> |
| 90 HostResolver::CreateDefaultResolver(NetLog* net_log) { |
| 91 return CreateSystemResolver(Options(), net_log); |
| 92 } |
| 93 |
| 36 HostResolver::HostResolver() { | 94 HostResolver::HostResolver() { |
| 37 } | 95 } |
| 38 | 96 |
| 39 } // namespace net | 97 } // namespace net |
| OLD | NEW |