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::EntryStaleness* stale_info, | |
107 const BoundNetLog& net_log) { | |
108 // If a resolver doesn't know how to get potentially-stale results from the | |
109 // cache, blank |*stale_info| and just get fresh results instead. | |
110 stale_info->expired_by = base::TimeDelta::FromSeconds(-1); | |
111 stale_info->network_changes = 0u; | |
112 stale_info->stale_hits = 0u; | |
113 return ResolveFromCache(info, addresses, net_log); | |
114 } | |
115 | |
116 int HostResolver::ResolveStale(const RequestInfo& info, | |
117 RequestPriority priority, | |
118 AddressList* addresses, | |
119 const CompletionCallback& callback, | |
120 RequestHandle* out_req, | |
121 int* stale_error, | |
122 AddressList* stale_addresses, | |
123 HostCache::EntryStaleness* stale_info, | |
124 const BoundNetLog& net_log) { | |
125 int rv = ResolveStaleFromCache(info, addresses, stale_info, net_log); | |
126 // If it's a fresh cache hit, return it synchronously. | |
127 if (rv != ERR_DNS_CACHE_MISS && !stale_info->is_stale()) { | |
128 *stale_error = ERR_UNEXPECTED; | |
129 stale_addresses->clear(); | |
130 return rv; | |
131 } | |
132 | |
133 *stale_error = rv; | |
134 *stale_addresses = *addresses; | |
Randy Smith (Not in Mondays)
2016/05/04 19:46:59
I wince a bit at setting *stale_addresses in the E
Julia Tuttle
2016/05/05 15:42:54
Fixed.
| |
135 addresses->clear(); | |
Randy Smith (Not in Mondays)
2016/05/04 19:46:59
So both this and the ResolveStaleFromCache() call
Julia Tuttle
2016/05/05 15:42:54
Fixed.
| |
136 | |
137 return Resolve(info, priority, addresses, callback, out_req, net_log); | |
138 } | |
139 | |
103 void HostResolver::SetDnsClientEnabled(bool enabled) { | 140 void HostResolver::SetDnsClientEnabled(bool enabled) { |
104 } | 141 } |
105 | 142 |
106 HostCache* HostResolver::GetHostCache() { | 143 HostCache* HostResolver::GetHostCache() { |
107 return NULL; | 144 return nullptr; |
108 } | 145 } |
109 | 146 |
110 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { | 147 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { |
111 return nullptr; | 148 return nullptr; |
112 } | 149 } |
113 | 150 |
114 // static | 151 // static |
115 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( | 152 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( |
116 const Options& options, | 153 const Options& options, |
117 NetLog* net_log) { | 154 NetLog* net_log) { |
118 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); | 155 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); |
119 } | 156 } |
120 | 157 |
121 // static | 158 // static |
122 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( | 159 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( |
123 NetLog* net_log) { | 160 NetLog* net_log) { |
124 return std::unique_ptr<HostResolver>( | 161 return std::unique_ptr<HostResolver>( |
125 new HostResolverImpl(Options(), net_log)); | 162 new HostResolverImpl(Options(), net_log)); |
126 } | 163 } |
127 | 164 |
128 HostResolver::HostResolver() { | 165 HostResolver::HostResolver() { |
129 } | 166 } |
130 | 167 |
131 } // namespace net | 168 } // namespace net |
OLD | NEW |