Improve HostResolver cache-only and stale support

Added HostResolverSource::LOCAL_ONLY setting to only allow local (eg
cache and HOSTS) resolution through the newer API. This will replace the
old ResolveFromCache() method (which was poorly named as it could do
other non-cache local sources).

Also turned |allow_cached_response| into |cache_usage| that adds a third
|STALE_ALLOWED| option. Setting this will replace the old
ResolveStaleFromCache() method, except that it doesn't do cache-only
unless also paired with LOCAL_ONLY.

EntryStaleness works a bit differently in the new API. Before it was
returned iff ResolveStaleFromCache() was used (and set to a default
non-stale value if the result doesn't come from the cache). Now it gets
set on the ResolveHostRequest object iff the result came from cache
(even if |STALE_ALLOWED| is not set). More consistent and more
reasonable for the newer pattern of results being on-demand through
Get*() methods rather that an out parameter.

Bug: 922699
Change-Id: Ia5c55beaf3c3c931a9503bb80e0b95f3334c5266
Reviewed-on: https://chromium-review.googlesource.com/c/1423577
Commit-Queue: Eric Orth <[email protected]>
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Asanka Herath <[email protected]>
Cr-Commit-Position: refs/heads/master@{#626287}
diff --git a/net/dns/host_resolver_source.h b/net/dns/host_resolver_source.h
index 794c5f3..cf9633b 100644
--- a/net/dns/host_resolver_source.h
+++ b/net/dns/host_resolver_source.h
@@ -26,12 +26,19 @@
   // Results will only come from Multicast DNS queries.
   MULTICAST_DNS,
 
-  MAX = MULTICAST_DNS
+  // No external sources will be used. Results will only come from fast local
+  // sources that are available no matter the source setting, e.g. cache, hosts
+  // file, IP literal resolution, etc. Resolves with this setting are guaranteed
+  // to finish synchronously.
+  LOCAL_ONLY,
+
+  MAX = LOCAL_ONLY
 };
 
 const HostResolverSource kHostResolverSources[] = {
     HostResolverSource::ANY, HostResolverSource::SYSTEM,
-    HostResolverSource::DNS, HostResolverSource::MULTICAST_DNS};
+    HostResolverSource::DNS, HostResolverSource::MULTICAST_DNS,
+    HostResolverSource::LOCAL_ONLY};
 
 static_assert(
     base::size(kHostResolverSources) ==