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

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

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DNS_HOST_RESOLVER_H_ 5 #ifndef NET_DNS_HOST_RESOLVER_H_
6 #define NET_DNS_HOST_RESOLVER_H_ 6 #define NET_DNS_HOST_RESOLVER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 24 matching lines...) Expand all
35 // literal) to an AddressList object. 35 // literal) to an AddressList object.
36 // 36 //
37 // HostResolver can handle multiple requests at a time, so when cancelling a 37 // HostResolver can handle multiple requests at a time, so when cancelling a
38 // request the RequestHandle that was returned by Resolve() needs to be 38 // request the RequestHandle that was returned by Resolve() needs to be
39 // given. A simpler alternative for consumers that only have 1 outstanding 39 // given. A simpler alternative for consumers that only have 1 outstanding
40 // request at a time is to create a SingleRequestHostResolver wrapper around 40 // request at a time is to create a SingleRequestHostResolver wrapper around
41 // HostResolver (which will automatically cancel the single request when it 41 // HostResolver (which will automatically cancel the single request when it
42 // goes out of scope). 42 // goes out of scope).
43 class NET_EXPORT HostResolver { 43 class NET_EXPORT HostResolver {
44 public: 44 public:
45 class NET_EXPORT Request {
mmenke 2016/07/12 18:50:23 Document this class. (Owned by the consumer, dele
maksims (do not use this acc) 2016/07/19 15:00:26 Done.
46 public:
47 virtual ~Request() {}
48
49 // Changes the priority of the request. ChangeRequestPriority must NOT be
50 // called after the request's completion callback has already run.
51 virtual void ChangeRequestPriority(RequestPriority priority) = 0;
52 };
53
45 // |max_concurrent_resolves| is how many resolve requests will be allowed to 54 // |max_concurrent_resolves| is how many resolve requests will be allowed to
46 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a 55 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a
47 // default value. 56 // default value.
48 // |max_retry_attempts| is the maximum number of times we will retry for host 57 // |max_retry_attempts| is the maximum number of times we will retry for host
49 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default 58 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default
50 // value. 59 // value.
51 // |enable_caching| controls whether a HostCache is used. 60 // |enable_caching| controls whether a HostCache is used.
52 struct NET_EXPORT Options { 61 struct NET_EXPORT Options {
53 Options(); 62 Options();
54 63
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 bool allow_cached_response_; 117 bool allow_cached_response_;
109 118
110 // Whether this request was started by the DNS prefetcher. 119 // Whether this request was started by the DNS prefetcher.
111 bool is_speculative_; 120 bool is_speculative_;
112 121
113 // Indicates a request for myIpAddress (to differentiate from other requests 122 // Indicates a request for myIpAddress (to differentiate from other requests
114 // for localhost, currently used by Chrome OS). 123 // for localhost, currently used by Chrome OS).
115 bool is_my_ip_address_; 124 bool is_my_ip_address_;
116 }; 125 };
117 126
118 // Opaque type used to cancel a request.
119 typedef void* RequestHandle;
120
121 // Set Options.max_concurrent_resolves to this to select a default level 127 // Set Options.max_concurrent_resolves to this to select a default level
122 // of concurrency. 128 // of concurrency.
123 static const size_t kDefaultParallelism = 0; 129 static const size_t kDefaultParallelism = 0;
124 130
125 // Set Options.max_retry_attempts to this to select a default retry value. 131 // Set Options.max_retry_attempts to this to select a default retry value.
126 static const size_t kDefaultRetryAttempts = static_cast<size_t>(-1); 132 static const size_t kDefaultRetryAttempts = static_cast<size_t>(-1);
127 133
128 // If any completion callbacks are pending when the resolver is destroyed, 134 // If any completion callbacks are pending when the resolver is destroyed,
129 // the host resolutions are cancelled, and the completion callbacks will not 135 // the host resolutions are cancelled, and the completion callbacks will not
130 // be called. 136 // be called.
131 virtual ~HostResolver(); 137 virtual ~HostResolver();
132 138
133 // Resolves the given hostname (or IP address literal), filling out the 139 // Resolves the given hostname (or IP address literal), filling out the
134 // |addresses| object upon success. The |info.port| parameter will be set as 140 // |addresses| object upon success. The |info.port| parameter will be set as
135 // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if 141 // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if
136 // successful or an error code upon failure. Returns 142 // successful or an error code upon failure. Returns
137 // ERR_NAME_NOT_RESOLVED if hostname is invalid, or if it is an 143 // ERR_NAME_NOT_RESOLVED if hostname is invalid, or if it is an
138 // incompatible IP literal (e.g. IPv6 is disabled and it is an IPv6 144 // incompatible IP literal (e.g. IPv6 is disabled and it is an IPv6
139 // literal). 145 // literal).
140 // 146 //
141 // If the operation cannot be completed synchronously, ERR_IO_PENDING will 147 // If the operation cannot be completed synchronously, ERR_IO_PENDING will
142 // be returned and the real result code will be passed to the completion 148 // be returned and the real result code will be passed to the completion
143 // callback. Otherwise the result code is returned immediately from this 149 // callback. Otherwise the result code is returned immediately from this
144 // call. 150 // call.
145 // 151 //
146 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to 152 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to
Devlin 2016/07/12 15:04:51 is out_req still allowed to be null? It doesn't l
147 // the async request. This handle is not valid after the request has 153 // the async request. This handle is not valid after the request has
148 // completed. 154 // completed.
mmenke 2016/07/12 18:50:23 This entire paragraph needs to be re-written.
maksims (do not use this acc) 2016/07/19 15:00:26 Done.
149 // 155 //
150 // Profiling information for the request is saved to |net_log| if non-NULL. 156 // Profiling information for the request is saved to |net_log| if non-NULL.
151 virtual int Resolve(const RequestInfo& info, 157 virtual int Resolve(const RequestInfo& info,
152 RequestPriority priority, 158 RequestPriority priority,
153 AddressList* addresses, 159 AddressList* addresses,
154 const CompletionCallback& callback, 160 const CompletionCallback& callback,
155 RequestHandle* out_req, 161 std::unique_ptr<Request>* out_req,
Devlin 2016/07/12 15:04:51 I'm not familiar with the implementation here at a
mmenke 2016/07/12 18:50:23 No - it should be deleted the cancel the request.
maksims (do not use this acc) 2016/07/19 15:00:25 Done.
156 const BoundNetLog& net_log) = 0; 162 const BoundNetLog& net_log) = 0;
157 163
158 // Changes the priority of the specified request. |req| is the handle returned
159 // by Resolve(). ChangeRequestPriority must NOT be called after the request's
160 // completion callback has already run or the request was canceled.
161 virtual void ChangeRequestPriority(RequestHandle req,
162 RequestPriority priority);
163
164 // Cancels the specified request. |req| is the handle returned by Resolve().
165 // After a request is canceled, its completion callback will not be called.
166 // CancelRequest must NOT be called after the request's completion callback
167 // has already run or the request was canceled.
168 virtual void CancelRequest(RequestHandle req) = 0;
169
170 // Resolves the given hostname (or IP address literal) out of cache or HOSTS 164 // Resolves the given hostname (or IP address literal) out of cache or HOSTS
171 // file (if enabled) only. This is guaranteed to complete synchronously. 165 // file (if enabled) only. This is guaranteed to complete synchronously.
172 // This acts like |Resolve()| if the hostname is IP literal, or cached value 166 // This acts like |Resolve()| if the hostname is IP literal, or cached value
173 // or HOSTS entry exists. Otherwise, ERR_DNS_CACHE_MISS is returned. 167 // or HOSTS entry exists. Otherwise, ERR_DNS_CACHE_MISS is returned.
174 virtual int ResolveFromCache(const RequestInfo& info, 168 virtual int ResolveFromCache(const RequestInfo& info,
175 AddressList* addresses, 169 AddressList* addresses,
176 const BoundNetLog& net_log) = 0; 170 const BoundNetLog& net_log) = 0;
177 171
178 // Enable or disable the built-in asynchronous DnsClient. 172 // Enable or disable the built-in asynchronous DnsClient.
179 virtual void SetDnsClientEnabled(bool enabled); 173 virtual void SetDnsClientEnabled(bool enabled);
(...skipping 19 matching lines...) Expand all
199 protected: 193 protected:
200 HostResolver(); 194 HostResolver();
201 195
202 private: 196 private:
203 DISALLOW_COPY_AND_ASSIGN(HostResolver); 197 DISALLOW_COPY_AND_ASSIGN(HostResolver);
204 }; 198 };
205 199
206 } // namespace net 200 } // namespace net
207 201
208 #endif // NET_DNS_HOST_RESOLVER_H_ 202 #endif // NET_DNS_HOST_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698