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

Side by Side Diff: net/dns/stale_host_resolver.h

Issue 1898873006: Cronet: Use stale DNS cache entries experimentally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dns_stale2
Patch Set: Fix missing #include >.< 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
« no previous file with comments | « no previous file | net/dns/stale_host_resolver.cc » ('j') | net/dns/stale_host_resolver.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_DNS_STALE_HOST_RESOLVER_H_
6 #define NET_DNS_STALE_HOST_RESOLVER_H_
7
8 #include <set>
9
10 #include "net/dns/host_resolver.h"
11
12 namespace net {
13
14 // A HostResolver that wraps another HostResolver that uses it to make requests
15 // but "impatiently" returns stale data (if available and usable) after a delay,
16 // to reduce DNS latency at the expense of accuracy.
17 class NET_EXPORT StaleHostResolver : public HostResolver {
18 public:
19 struct NET_EXPORT StaleOptions {
20 // How long to wait before returning stale data, if available.
21 base::TimeDelta delay;
22
23 // If positive, how long stale data can be past the expiration time before
24 // it's considered unusable. If zero or negative, stale data can be used
25 // indefinitely.
26 base::TimeDelta max_expired_time;
27
28 // If set, stale data from previous networks is usable; if clear, it's not.
29 //
30 // If the other network had a working, correct DNS setup, this can increase
31 // the availability of useful stale results.
32 //
33 // If the other network had a broken (e.g. hijacked for captive portal) DNS
34 // setup, this will instead end up returning useless results.
35 bool allow_other_network;
36
37 // If positive, the maximum number of times a stale entry can be used. If
38 // zero, there is no limit.
39 int max_stale_uses;
40 };
41
42 // Creates a StaleHostResolver that uses |inner_resolver| for actual
43 // resolution, but potentially returns stale data according to
44 // |stale_options|.
45 StaleHostResolver(std::unique_ptr<HostResolver> inner_resolver,
46 const StaleOptions& stale_options);
47
48 ~StaleHostResolver() override;
49
50 // Resolves as a regular HostResolver, but if stale data is available and
51 // usable (according to the options passed to the constructor), and fresh data
52 // is not returned before the specified delay, returns the stale data instead.
53 //
54 // If stale data is returned, the StaleHostResolver allows the underlying
55 // request to continue in order to repopulate the cache.
56 int Resolve(const RequestInfo& info,
57 RequestPriority priority,
58 AddressList* addresses,
59 const CompletionCallback& callback,
60 RequestHandle* out_req,
61 const BoundNetLog& net_log) override;
62
63 // Cancels a request created by |Resolve|.
64 //
65 // It is not valid to cancel a request once it has returned a result, even if
66 // the result was stale data and the underlying request on the inner resolver
67 // is still running.
68 void CancelRequest(RequestHandle req) override;
69
70 // The remaining public methods pass through to the inner resolver:
Randy Smith (Not in Mondays) 2016/05/04 21:00:28 So there's a code smell here, and I'm really not s
Ryan Sleevi 2016/05/04 21:14:38 I'm not going to be able to offer review feedback
Ryan Sleevi 2016/05/10 18:59:13 Right, I totally agree with Randy here.
71 int ResolveFromCache(const RequestInfo& info,
72 AddressList* addresses,
73 const BoundNetLog& net_log) override;
74 int ResolveStaleFromCache(const RequestInfo& info,
75 AddressList* addresses,
76 HostCache::EntryStaleness* stale_info,
77 const BoundNetLog& net_log) override;
78 void SetDnsClientEnabled(bool enabled) override;
79 HostCache* GetHostCache() override;
80 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override;
81
82 private:
83 class Request;
84
85 void OnRequestComplete(Request* request,
86 const CompletionCallback& outer_callback,
87 int error);
88
89 std::unique_ptr<HostResolver> resolver_;
90 StaleOptions options_;
91 std::set<Request*> pending_requests_;
92 };
93
94 } // namespace net
95
96 #endif // NET_DNS_STALE_HOST_RESOLVER_H_
OLDNEW
« no previous file with comments | « no previous file | net/dns/stale_host_resolver.cc » ('j') | net/dns/stale_host_resolver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698