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

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: Tweak histograms per asvitkine's suggestions on another CL. 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.
Ryan Sleevi 2016/04/29 01:04:09 Suggestion: Explain a little more about the trade-
Julia Tuttle 2016/04/29 18:04:29 Done.
29 bool allow_other_network;
30
31 // If positive, the maximum number of times a stale entry can be used. If
32 // zero, there is no limit. (Note that this count is kept by the HostCache,
33 // so it is shared across all StaleHostResolvers and any other callers who
34 // request potentially stale data.)
Randy Smith (Not in Mondays) 2016/04/28 17:48:25 nit: How hard would it be to change this? I suspe
Ryan Sleevi 2016/04/29 01:04:09 What HostCache? Who owns it? Is it a global? (My
Julia Tuttle 2016/04/29 18:04:30 We could keep a std::map<HostCache::Key, int> stal
Randy Smith (Not in Mondays) 2016/05/04 21:00:28 So currently StaleHostResolver owns (does not shar
35 unsigned max_stale_uses;
36 };
37
38 // Creates a StaleHostResolver that uses |inner_resolver| for actual
39 // resolution but potentially returns stale data according to |stale_options|.
Ryan Sleevi 2016/04/29 01:04:09 s/resolution but/resolution, but/
Julia Tuttle 2016/04/29 18:04:30 Done.
40 StaleHostResolver(std::unique_ptr<HostResolver> inner_resolver,
41 const StaleOptions& stale_options);
42
43 ~StaleHostResolver() override;
44
45 // Resolves as a regular HostResolver, but if stale data is available and
46 // usable (according to the options passed to the constructor), returns it
47 // after the specified delay instead.
Randy Smith (Not in Mondays) 2016/04/28 17:48:25 I presume if fresh data is available in that time
Julia Tuttle 2016/04/29 18:04:29 Clarified.
48 //
49 // If stale data is returned, the StaleHostResolver allows the underlying
50 // request to continue in order to repopulate the cache.
51 int Resolve(const RequestInfo& info,
52 RequestPriority priority,
53 AddressList* addresses,
54 const CompletionCallback& callback,
55 RequestHandle* out_req,
56 const BoundNetLog& net_log) override;
57
58 // Cancels a request created by |Resolve|.
59 //
60 // It is not valid to cancel a request once it has returned a result, even if
61 // the result was stale data and the underlying request on the inner resolver
62 // is still running.
63 void CancelRequest(RequestHandle req) override;
64
65 // The remaining methods pass through to the inner resolver:
66
Ryan Sleevi 2016/04/29 01:04:09 delete newline?
Julia Tuttle 2016/04/29 18:04:29 Done.
67 int ResolveFromCache(const RequestInfo& info,
68 AddressList* addresses,
69 const BoundNetLog& net_log) override;
70 int ResolveStaleFromCache(const RequestInfo& info,
71 AddressList* addresses,
72 HostCache::StaleEntryInfo* stale_info,
73 const BoundNetLog& net_log) override;
74 void SetDnsClientEnabled(bool enabled) override;
75 HostCache* GetHostCache() override;
76 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override;
77
78 private:
79 class Request;
80
81 void OnRequestComplete(Request* request,
82 const CompletionCallback& outer_callback,
83 int error);
84
85 std::unique_ptr<HostResolver> resolver_;
86 StaleOptions options_;
87 std::set<Request*> pending_requests_;
88 };
89
90 } // namespace net
91
92 #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