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