Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: net/dns/host_resolver.cc

Issue 1903263002: DNS: Expose stale results through HostResolverImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dns_stale1
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 int rv = ResolveFromCache(info, addresses, net_log);
111 if (rv != ERR_DNS_CACHE_MISS) {
112 stale_info->expired_by = base::TimeDelta::FromSeconds(-1);
113 stale_info->network_changes = 0u;
114 stale_info->stale_hits = 0u;
115 }
116 return rv;
117 }
118
119 int HostResolver::ResolveStale(const RequestInfo& info,
120 RequestPriority priority,
121 AddressList* addresses,
122 const CompletionCallback& callback,
123 RequestHandle* out_req,
124 int* stale_error,
125 AddressList* stale_addresses,
126 HostCache::EntryStaleness* stale_info,
127 const BoundNetLog& net_log) {
128 AddressList cache_addresses;
129 int cache_rv =
130 ResolveStaleFromCache(info, &cache_addresses, stale_info, net_log);
131 // If it's a fresh cache hit (or literal), return it synchronously.
132 if (cache_rv != ERR_DNS_CACHE_MISS && !stale_info->is_stale()) {
133 *stale_error = ERR_UNEXPECTED;
Randy Smith (Not in Mondays) 2016/05/17 20:39:35 Why set |*stale_error| if it isn't stale? Isn't t
Julia Tuttle 2016/05/20 17:54:42 It's mostly defensive -- if someone accidentally g
134 *addresses = cache_addresses;
135 return cache_rv;
136 }
137
138 // If it's a stale cache hit, fill in |*stale_addresses| but run the network
139 // request anyway.
140 if (cache_rv != ERR_DNS_CACHE_MISS)
141 *stale_addresses = cache_addresses;
142
143 *stale_error = cache_rv;
144
145 // Don't check the cache again.
146 RequestInfo no_cache_info(info);
147 no_cache_info.set_allow_cached_response(false);
148 return Resolve(no_cache_info, priority, addresses, callback, out_req,
149 net_log);
150 }
151
103 void HostResolver::SetDnsClientEnabled(bool enabled) { 152 void HostResolver::SetDnsClientEnabled(bool enabled) {
104 } 153 }
105 154
106 void HostResolver::ChangeRequestPriority(RequestHandle req, 155 void HostResolver::ChangeRequestPriority(RequestHandle req,
107 RequestPriority priority) { 156 RequestPriority priority) {
108 NOTIMPLEMENTED(); 157 NOTIMPLEMENTED();
109 } 158 }
110 159
111 HostCache* HostResolver::GetHostCache() { 160 HostCache* HostResolver::GetHostCache() {
112 return NULL; 161 return nullptr;
113 } 162 }
114 163
115 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const { 164 std::unique_ptr<base::Value> HostResolver::GetDnsConfigAsValue() const {
116 return nullptr; 165 return nullptr;
117 } 166 }
118 167
119 // static 168 // static
120 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver( 169 std::unique_ptr<HostResolver> HostResolver::CreateSystemResolver(
121 const Options& options, 170 const Options& options,
122 NetLog* net_log) { 171 NetLog* net_log) {
123 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log)); 172 return std::unique_ptr<HostResolver>(new HostResolverImpl(options, net_log));
124 } 173 }
125 174
126 // static 175 // static
127 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver( 176 std::unique_ptr<HostResolver> HostResolver::CreateDefaultResolver(
128 NetLog* net_log) { 177 NetLog* net_log) {
129 return std::unique_ptr<HostResolver>( 178 return std::unique_ptr<HostResolver>(
130 new HostResolverImpl(Options(), net_log)); 179 new HostResolverImpl(Options(), net_log));
131 } 180 }
132 181
133 HostResolver::HostResolver() { 182 HostResolver::HostResolver() {
134 } 183 }
135 184
136 } // namespace net 185 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698