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

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: http_stream_factory_impl_job_controller_unittest RequestHandle* to unique_ptr Created 4 years, 4 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 // HostResolver::Request class is used to cancel the request and change it's
46 // priority. It must be owned by consumer. Deletion cancels the request.
47 class Request {
48 public:
49 virtual ~Request() {}
50
51 // Changes the priority of the specified request. Can be called after
52 // Resolve() is called. Can't be called once the request is cancelled or
53 // completed.
54 virtual void ChangeRequestPriority(RequestPriority priority) = 0;
55 };
56
45 // |max_concurrent_resolves| is how many resolve requests will be allowed to 57 // |max_concurrent_resolves| is how many resolve requests will be allowed to
46 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a 58 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a
47 // default value. 59 // default value.
48 // |max_retry_attempts| is the maximum number of times we will retry for host 60 // |max_retry_attempts| is the maximum number of times we will retry for host
49 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default 61 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default
50 // value. 62 // value.
51 // |enable_caching| controls whether a HostCache is used. 63 // |enable_caching| controls whether a HostCache is used.
52 struct NET_EXPORT Options { 64 struct NET_EXPORT Options {
53 Options(); 65 Options();
54 66
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 bool allow_cached_response_; 120 bool allow_cached_response_;
109 121
110 // Whether this request was started by the DNS prefetcher. 122 // Whether this request was started by the DNS prefetcher.
111 bool is_speculative_; 123 bool is_speculative_;
112 124
113 // Indicates a request for myIpAddress (to differentiate from other requests 125 // Indicates a request for myIpAddress (to differentiate from other requests
114 // for localhost, currently used by Chrome OS). 126 // for localhost, currently used by Chrome OS).
115 bool is_my_ip_address_; 127 bool is_my_ip_address_;
116 }; 128 };
117 129
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 130 // Set Options.max_concurrent_resolves to this to select a default level
122 // of concurrency. 131 // of concurrency.
123 static const size_t kDefaultParallelism = 0; 132 static const size_t kDefaultParallelism = 0;
124 133
125 // Set Options.max_retry_attempts to this to select a default retry value. 134 // Set Options.max_retry_attempts to this to select a default retry value.
126 static const size_t kDefaultRetryAttempts = static_cast<size_t>(-1); 135 static const size_t kDefaultRetryAttempts = static_cast<size_t>(-1);
127 136
128 // If any completion callbacks are pending when the resolver is destroyed, 137 // If any completion callbacks are pending when the resolver is destroyed,
129 // the host resolutions are cancelled, and the completion callbacks will not 138 // the host resolutions are cancelled, and the completion callbacks will not
130 // be called. 139 // be called.
131 virtual ~HostResolver(); 140 virtual ~HostResolver();
132 141
133 // Resolves the given hostname (or IP address literal), filling out the 142 // Resolves the given hostname (or IP address literal), filling out the
134 // |addresses| object upon success. The |info.port| parameter will be set as 143 // |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 144 // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if
136 // successful or an error code upon failure. Returns 145 // successful or an error code upon failure. Returns
137 // ERR_NAME_NOT_RESOLVED if hostname is invalid, or if it is an 146 // 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 147 // incompatible IP literal (e.g. IPv6 is disabled and it is an IPv6
139 // literal). 148 // literal).
140 // 149 //
141 // If the operation cannot be completed synchronously, ERR_IO_PENDING will 150 // 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 151 // be returned and the real result code will be passed to the completion
143 // callback. Otherwise the result code is returned immediately from this 152 // callback. Otherwise the result code is returned immediately from this
144 // call. 153 // call.
145 // 154 //
146 // If |out_req| is non-NULL, then |*out_req| will be filled with a handle to 155 // [out_req] must be owned by a caller. If the request is not completed
147 // the async request. This handle is not valid after the request has 156 // synchronously, it will be filled with a handle to the request. It must be
148 // completed. 157 // completed before the HostResolver itself is destroyed.
158 //
159 // Requests can be cancelled any time by deletion of the [out_req]. Deleting
160 // |out_req| will cancel the request, and cause |callback| not to be invoked.
149 // 161 //
150 // Profiling information for the request is saved to |net_log| if non-NULL. 162 // Profiling information for the request is saved to |net_log| if non-NULL.
151 virtual int Resolve(const RequestInfo& info, 163 virtual int Resolve(const RequestInfo& info,
152 RequestPriority priority, 164 RequestPriority priority,
153 AddressList* addresses, 165 AddressList* addresses,
154 const CompletionCallback& callback, 166 const CompletionCallback& callback,
155 RequestHandle* out_req, 167 std::unique_ptr<Request>* out_req,
156 const BoundNetLog& net_log) = 0; 168 const BoundNetLog& net_log) = 0;
157 169
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 170 // Resolves the given hostname (or IP address literal) out of cache or HOSTS
171 // file (if enabled) only. This is guaranteed to complete synchronously. 171 // file (if enabled) only. This is guaranteed to complete synchronously.
172 // This acts like |Resolve()| if the hostname is IP literal, or cached value 172 // 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. 173 // or HOSTS entry exists. Otherwise, ERR_DNS_CACHE_MISS is returned.
174 virtual int ResolveFromCache(const RequestInfo& info, 174 virtual int ResolveFromCache(const RequestInfo& info,
175 AddressList* addresses, 175 AddressList* addresses,
176 const BoundNetLog& net_log) = 0; 176 const BoundNetLog& net_log) = 0;
177 177
178 // Enable or disable the built-in asynchronous DnsClient. 178 // Enable or disable the built-in asynchronous DnsClient.
179 virtual void SetDnsClientEnabled(bool enabled); 179 virtual void SetDnsClientEnabled(bool enabled);
(...skipping 19 matching lines...) Expand all
199 protected: 199 protected:
200 HostResolver(); 200 HostResolver();
201 201
202 private: 202 private:
203 DISALLOW_COPY_AND_ASSIGN(HostResolver); 203 DISALLOW_COPY_AND_ASSIGN(HostResolver);
204 }; 204 };
205 205
206 } // namespace net 206 } // namespace net
207 207
208 #endif // NET_DNS_HOST_RESOLVER_H_ 208 #endif // NET_DNS_HOST_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698