OLD | NEW |
---|---|
(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 COMPONENTS_CRONET_STALE_HOST_RESOLVER_H_ | |
6 #define COMPONENTS_CRONET_STALE_HOST_RESOLVER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "net/dns/host_resolver.h" | |
11 #include "net/dns/host_resolver_impl.h" | |
12 | |
13 namespace cronet { | |
14 | |
15 // A HostResolver that wraps another HostResolver that uses it to make requests | |
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
nit: We're no longer wrapping an arbitrary HostRes
Julia Tuttle
2016/06/10 17:31:44
Done.
| |
16 // but "impatiently" returns stale data (if available and usable) after a delay, | |
17 // to reduce DNS latency at the expense of accuracy. | |
18 class NET_EXPORT StaleHostResolver : public net::HostResolver { | |
19 public: | |
20 struct NET_EXPORT StaleOptions { | |
21 // How long to wait before returning stale data, if available. | |
22 base::TimeDelta delay; | |
23 | |
24 // If positive, how long stale data can be past the expiration time before | |
25 // it's considered unusable. If zero or negative, stale data can be used | |
26 // indefinitely. | |
27 base::TimeDelta max_expired_time; | |
28 | |
29 // If set, stale data from previous networks is usable; if clear, it's not. | |
30 // | |
31 // If the other network had a working, correct DNS setup, this can increase | |
32 // the availability of useful stale results. | |
33 // | |
34 // If the other network had a broken (e.g. hijacked for captive portal) DNS | |
35 // setup, this will instead end up returning useless results. | |
36 bool allow_other_network; | |
37 | |
38 // If positive, the maximum number of times a stale entry can be used. If | |
39 // zero, there is no limit. | |
40 int max_stale_uses; | |
41 }; | |
42 | |
43 // Creates a StaleHostResolver that uses |inner_resolver| for actual | |
44 // resolution, but potentially returns stale data according to | |
45 // |stale_options|. | |
46 StaleHostResolver(std::unique_ptr<net::HostResolverImpl> inner_resolver, | |
47 const StaleOptions& stale_options); | |
48 | |
49 // Cancels all pending calls to Resolve, and does not call their callbacks. | |
50 ~StaleHostResolver() override; | |
51 | |
52 // Resolves as a regular HostResolver, but if stale data is available and | |
53 // usable (according to the options passed to the constructor), and fresh data | |
54 // is not returned before the specified delay, returns the stale data instead. | |
55 // | |
56 // If stale data is returned, the StaleHostResolver allows the underlying | |
57 // request to continue in order to repopulate the cache. | |
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
I'm a bit torn about all the commenting on the met
Julia Tuttle
2016/06/10 17:31:44
Done.
| |
58 // | |
59 // |addresses| must remain valid until the request completes (synchronously or | |
60 // via |callback|) or is canceled (via |CancelRequest| or | |
61 // |~StaleHostResolver()|). | |
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
This is actually a comment on the interface, not t
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
nit: Looks like line break in the wrong place?
Julia Tuttle
2016/06/10 17:31:44
Done.
Julia Tuttle
2016/06/10 17:31:45
Done.
| |
62 int Resolve(const RequestInfo& info, | |
63 net::RequestPriority priority, | |
64 net::AddressList* addresses, | |
65 const net::CompletionCallback& callback, | |
66 RequestHandle* out_req, | |
67 const net::BoundNetLog& net_log) override; | |
68 | |
69 // Cancels a request created by |Resolve|. | |
70 // | |
71 // It is not valid to cancel a request once it has returned a result, even if | |
72 // the result was stale data and the underlying request on the inner resolver | |
73 // is still running. | |
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
This seems like a comment that applies to the inte
Julia Tuttle
2016/06/10 17:31:45
Done.
| |
74 void CancelRequest(RequestHandle req) override; | |
75 | |
76 // The remaining public methods pass through to the inner resolver: | |
77 int ResolveFromCache(const RequestInfo& info, | |
78 net::AddressList* addresses, | |
79 const net::BoundNetLog& net_log) override; | |
80 void SetDnsClientEnabled(bool enabled) override; | |
81 net::HostCache* GetHostCache() override; | |
82 std::unique_ptr<base::Value> GetDnsConfigAsValue() const override; | |
83 | |
84 private: | |
85 class Request; | |
86 | |
87 void OnRequestComplete(Request* request, | |
88 const net::CompletionCallback& outer_callback, | |
89 int error); | |
90 | |
91 std::unique_ptr<net::HostResolverImpl> resolver_; | |
92 StaleOptions options_; | |
93 std::set<Request*> pending_requests_; | |
Randy Smith (Not in Mondays)
2016/06/08 19:20:03
These are owned by this class, right? Would std::
Julia Tuttle
2016/06/10 17:31:45
It wouldn't be ideal; Requests delete themselves w
| |
94 }; | |
95 | |
96 } // namespace cronet | |
97 | |
98 #endif // COMPONENTS_CRONET_STALE_HOST_RESOLVER_H_ | |
OLD | NEW |