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/dns/host_resolver.h" | 5 #include "net/dns/host_resolver.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "net/base/net_errors.h" |
12 #include "net/dns/dns_client.h" | 13 #include "net/dns/dns_client.h" |
13 #include "net/dns/dns_config_service.h" | 14 #include "net/dns/dns_config_service.h" |
14 #include "net/dns/host_cache.h" | 15 #include "net/dns/host_cache.h" |
15 #include "net/dns/host_resolver_impl.h" | 16 #include "net/dns/host_resolver_impl.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Maximum of 6 concurrent resolver threads (excluding retries). | 22 // Maximum of 6 concurrent resolver threads (excluding retries). |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 : host_port_pair_(host_port_pair), | 94 : host_port_pair_(host_port_pair), |
94 address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 95 address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
95 host_resolver_flags_(0), | 96 host_resolver_flags_(0), |
96 allow_cached_response_(true), | 97 allow_cached_response_(true), |
97 is_speculative_(false), | 98 is_speculative_(false), |
98 is_my_ip_address_(false) {} | 99 is_my_ip_address_(false) {} |
99 | 100 |
100 HostResolver::~HostResolver() { | 101 HostResolver::~HostResolver() { |
101 } | 102 } |
102 | 103 |
| 104 int HostResolver::ResolveStaleFromCache(const RequestInfo& info, |
| 105 AddressList* addresses, |
| 106 HostCache::StaleEntryInfo* stale_info, |
| 107 const BoundNetLog& net_log) { |
| 108 // If a resolver doesn't know how to get potentially-stale results from the |
| 109 // cache, just get fresh results instead. |
| 110 return ResolveFromCache(info, addresses, net_log); |
| 111 } |
| 112 |
| 113 int HostResolver::ResolveStale(const RequestInfo& info, |
| 114 RequestPriority priority, |
| 115 AddressList* addresses, |
| 116 const CompletionCallback& callback, |
| 117 RequestHandle* out_req, |
| 118 int* stale_error, |
| 119 AddressList* stale_addresses, |
| 120 HostCache::StaleEntryInfo* stale_info, |
| 121 const BoundNetLog& net_log) { |
| 122 int rv = ResolveStaleFromCache(info, addresses, stale_info, net_log); |
| 123 // If it's a fresh cache hit, return it synchronously. |
| 124 if (rv != ERR_DNS_CACHE_MISS && !stale_info->is_stale()) { |
| 125 *stale_error = ERR_UNEXPECTED; |
| 126 stale_addresses->clear(); |
| 127 return rv; |
| 128 } |
| 129 |
| 130 *stale_error = rv; |
| 131 *stale_addresses = *addresses; |
| 132 addresses->clear(); |
| 133 |
| 134 return Resolve(info, priority, addresses, callback, out_req, net_log); |
| 135 } |
| 136 |
103 void HostResolver::SetDnsClientEnabled(bool enabled) { | 137 void HostResolver::SetDnsClientEnabled(bool enabled) { |
104 } | 138 } |
105 | 139 |
106 HostCache* HostResolver::GetHostCache() { | 140 HostCache* HostResolver::GetHostCache() { |
107 return NULL; | 141 return nullptr; |
108 } | 142 } |
109 | 143 |
110 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { | 144 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { |
111 return nullptr; | 145 return nullptr; |
112 } | 146 } |
113 | 147 |
114 // static | 148 // static |
115 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( | 149 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( |
116 const Options& options, | 150 const Options& options, |
117 NetLog* net_log) { | 151 NetLog* net_log) { |
118 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); | 152 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); |
119 } | 153 } |
120 | 154 |
121 // static | 155 // static |
122 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( | 156 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( |
123 NetLog* net_log) { | 157 NetLog* net_log) { |
124 return std::unique_ptr<HostResolver>( | 158 return std::unique_ptr<HostResolver>( |
125 new HostResolverImpl(Options(), net_log)); | 159 new HostResolverImpl(Options(), net_log)); |
126 } | 160 } |
127 | 161 |
128 HostResolver::HostResolver() { | 162 HostResolver::HostResolver() { |
129 } | 163 } |
130 | 164 |
131 } // namespace net | 165 } // namespace net |
OLD | NEW |