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