OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BASE_HOST_RESOLVER_H_ | 5 #ifndef NET_BASE_HOST_RESOLVER_H_ |
6 #define NET_BASE_HOST_RESOLVER_H_ | 6 #define NET_BASE_HOST_RESOLVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool is_speculative_; | 91 bool is_speculative_; |
92 | 92 |
93 // The priority for the request. | 93 // The priority for the request. |
94 RequestPriority priority_; | 94 RequestPriority priority_; |
95 | 95 |
96 // Optional data for consumption by observers. This is the URL of the | 96 // Optional data for consumption by observers. This is the URL of the |
97 // page that lead us to the navigation, for DNS prefetcher's benefit. | 97 // page that lead us to the navigation, for DNS prefetcher's benefit. |
98 GURL referrer_; | 98 GURL referrer_; |
99 }; | 99 }; |
100 | 100 |
101 // Interface for observing the requests that flow through a HostResolver. | |
102 class Observer { | |
103 public: | |
104 virtual ~Observer() {} | |
105 | |
106 // Called at the start of HostResolver::Resolve(). |id| is a unique number | |
107 // given to the request, so it can be matched up with a corresponding call | |
108 // to OnFinishResolutionWithStatus() or OnCancelResolution(). | |
109 virtual void OnStartResolution(int id, const RequestInfo& info) = 0; | |
110 | |
111 // Called on completion of request |id|. Note that if the request was | |
112 // cancelled, OnCancelResolution() will be called instead. | |
113 virtual void OnFinishResolutionWithStatus(int id, bool was_resolved, | |
114 const RequestInfo& info) = 0; | |
115 | |
116 // Called when request |id| has been cancelled. A request is "cancelled" | |
117 // if either the HostResolver is destroyed while a resolution is in | |
118 // progress, or HostResolver::CancelRequest() is called. | |
119 virtual void OnCancelResolution(int id, const RequestInfo& info) = 0; | |
120 }; | |
121 | |
122 // Opaque type used to cancel a request. | 101 // Opaque type used to cancel a request. |
123 typedef void* RequestHandle; | 102 typedef void* RequestHandle; |
124 | 103 |
125 // This value can be passed into CreateSystemHostResolver as the | 104 // This value can be passed into CreateSystemHostResolver as the |
126 // |max_concurrent_resolves| parameter. It will select a default level of | 105 // |max_concurrent_resolves| parameter. It will select a default level of |
127 // concurrency. | 106 // concurrency. |
128 static const size_t kDefaultParallelism = 0; | 107 static const size_t kDefaultParallelism = 0; |
129 | 108 |
130 // This value can be passed into CreateSystemHostResolver as the | 109 // This value can be passed into CreateSystemHostResolver as the |
131 // |max_retry_attempts| parameter. This is the maximum number of times we | 110 // |max_retry_attempts| parameter. This is the maximum number of times we |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // |Resolve()| if the hostname is IP literal or cached value exists. | 145 // |Resolve()| if the hostname is IP literal or cached value exists. |
167 // Otherwise, ERR_DNS_CACHE_MISS is returned. | 146 // Otherwise, ERR_DNS_CACHE_MISS is returned. |
168 virtual int ResolveFromCache(const RequestInfo& info, | 147 virtual int ResolveFromCache(const RequestInfo& info, |
169 AddressList* addresses, | 148 AddressList* addresses, |
170 const BoundNetLog& net_log) = 0; | 149 const BoundNetLog& net_log) = 0; |
171 | 150 |
172 // Cancels the specified request. |req| is the handle returned by Resolve(). | 151 // Cancels the specified request. |req| is the handle returned by Resolve(). |
173 // After a request is cancelled, its completion callback will not be called. | 152 // After a request is cancelled, its completion callback will not be called. |
174 virtual void CancelRequest(RequestHandle req) = 0; | 153 virtual void CancelRequest(RequestHandle req) = 0; |
175 | 154 |
176 // Adds an observer to this resolver. The observer will be notified of the | |
177 // start and completion of all requests (excluding cancellation). |observer| | |
178 // must remain valid for the duration of this HostResolver's lifetime. | |
179 virtual void AddObserver(Observer* observer) = 0; | |
180 | |
181 // Unregisters an observer previously added by AddObserver(). | |
182 virtual void RemoveObserver(Observer* observer) = 0; | |
183 | |
184 // Sets the default AddressFamily to use when requests have left it | 155 // Sets the default AddressFamily to use when requests have left it |
185 // unspecified. For example, this could be used to restrict resolution | 156 // unspecified. For example, this could be used to restrict resolution |
186 // results to AF_INET by passing in ADDRESS_FAMILY_IPV4, or to | 157 // results to AF_INET by passing in ADDRESS_FAMILY_IPV4, or to |
187 // AF_INET6 by passing in ADDRESS_FAMILY_IPV6. | 158 // AF_INET6 by passing in ADDRESS_FAMILY_IPV6. |
188 virtual void SetDefaultAddressFamily(AddressFamily address_family) {} | 159 virtual void SetDefaultAddressFamily(AddressFamily address_family) {} |
189 virtual AddressFamily GetDefaultAddressFamily() const; | 160 virtual AddressFamily GetDefaultAddressFamily() const; |
190 | 161 |
191 // Continuously observe whether IPv6 is supported, and set the allowable | 162 // Continuously observe whether IPv6 is supported, and set the allowable |
192 // address family to IPv4 iff IPv6 is not supported. | 163 // address family to IPv4 iff IPv6 is not supported. |
193 virtual void ProbeIPv6Support(); | 164 virtual void ProbeIPv6Support(); |
(...skipping 24 matching lines...) Expand all Loading... |
218 NetLog* net_log); | 189 NetLog* net_log); |
219 | 190 |
220 // Creates a HostResolver implementation that sends actual DNS queries to | 191 // Creates a HostResolver implementation that sends actual DNS queries to |
221 // the specified DNS server and parses response and returns results. | 192 // the specified DNS server and parses response and returns results. |
222 NET_EXPORT HostResolver* CreateAsyncHostResolver(size_t max_concurrent_resolves, | 193 NET_EXPORT HostResolver* CreateAsyncHostResolver(size_t max_concurrent_resolves, |
223 const IPAddressNumber& dns_ip, | 194 const IPAddressNumber& dns_ip, |
224 NetLog* net_log); | 195 NetLog* net_log); |
225 } // namespace net | 196 } // namespace net |
226 | 197 |
227 #endif // NET_BASE_HOST_RESOLVER_H_ | 198 #endif // NET_BASE_HOST_RESOLVER_H_ |
OLD | NEW |