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

Unified Diff: net/dns/host_resolver_impl.cc

Issue 2577503003: Misc HostResolverImpl refactors. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index 161796e54223a6fe3ecb9aa7f97d0be172050c0d..2a2febf14babd0e8cd87a254023cf5eaee7bd28a 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -1458,9 +1458,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
requests_.front()->info(),
&addr_list)) {
// This will destroy the Job.
- CompleteRequests(
- HostCache::Entry(OK, MakeAddressListForRequest(addr_list)),
- base::TimeDelta());
+ CompleteRequests(MakeCacheEntry(OK, addr_list), base::TimeDelta());
return true;
}
return false;
@@ -1500,6 +1498,25 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
DCHECK_EQ(1u, num_occupied_job_slots_);
}
+ // MakeCacheEntry() and MakeCacheEntryWithTTL() are helpers to build a
+ // HostCache::Entry(). The address list is omited from the cache entry
+ // for errors.
+ HostCache::Entry MakeCacheEntry(int net_error,
+ const AddressList& addr_list) const {
+ return HostCache::Entry(
+ net_error,
+ net_error == OK ? MakeAddressListForRequest(addr_list) : AddressList());
+ }
+
+ HostCache::Entry MakeCacheEntryWithTTL(int net_error,
+ const AddressList& addr_list,
+ base::TimeDelta ttl) const {
+ return HostCache::Entry(
+ net_error,
+ net_error == OK ? MakeAddressListForRequest(addr_list) : AddressList(),
+ ttl);
+ }
+
AddressList MakeAddressListForRequest(const AddressList& list) const {
if (requests_.empty())
return list;
@@ -1628,9 +1645,7 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds);
// Don't store the |ttl| in cache since it's not obtained from the server.
- CompleteRequests(
- HostCache::Entry(net_error, MakeAddressListForRequest(addr_list)),
- ttl);
+ CompleteRequests(MakeCacheEntry(net_error, addr_list), ttl);
}
void StartDnsTask() {
@@ -1712,12 +1727,12 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
base::TimeDelta bounded_ttl =
std::max(ttl, base::TimeDelta::FromSeconds(kMinimumTTLSeconds));
- if (ContainsIcannNameCollisionIp(addr_list))
- net_error = ERR_ICANN_NAME_COLLISION;
-
- CompleteRequests(
- HostCache::Entry(net_error, MakeAddressListForRequest(addr_list), ttl),
- bounded_ttl);
+ if (ContainsIcannNameCollisionIp(addr_list)) {
+ CompleteRequestsWithError(ERR_ICANN_NAME_COLLISION);
eroman 2016/12/14 00:19:52 This has a subtly different behavior for caching (
+ } else {
+ CompleteRequests(MakeCacheEntryWithTTL(net_error, addr_list, ttl),
+ bounded_ttl);
+ }
}
void OnFirstDnsTransactionComplete() override {
« no previous file with comments | « no previous file | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698