| 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_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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/base/address_family.h" | 11 #include "net/base/address_family.h" |
| 11 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
| 12 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 13 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 14 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 15 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class Value; | 19 class Value; |
| 19 } | 20 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 // literal) to an AddressList object. | 31 // literal) to an AddressList object. |
| 31 // | 32 // |
| 32 // HostResolver can handle multiple requests at a time, so when cancelling a | 33 // HostResolver can handle multiple requests at a time, so when cancelling a |
| 33 // request the RequestHandle that was returned by Resolve() needs to be | 34 // request the RequestHandle that was returned by Resolve() needs to be |
| 34 // given. A simpler alternative for consumers that only have 1 outstanding | 35 // given. A simpler alternative for consumers that only have 1 outstanding |
| 35 // request at a time is to create a SingleRequestHostResolver wrapper around | 36 // request at a time is to create a SingleRequestHostResolver wrapper around |
| 36 // HostResolver (which will automatically cancel the single request when it | 37 // HostResolver (which will automatically cancel the single request when it |
| 37 // goes out of scope). | 38 // goes out of scope). |
| 38 class NET_EXPORT HostResolver { | 39 class NET_EXPORT HostResolver { |
| 39 public: | 40 public: |
| 41 // |max_concurrent_resolves| is how many resolve requests will be allowed to |
| 42 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a |
| 43 // default value. |
| 44 // |max_retry_attempts| is the maximum number of times we will retry for host |
| 45 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default |
| 46 // value. |
| 47 // |enable_caching| controls whether a HostCache is used. |
| 48 // |enable_async| controls whether a DnsClient is used. |
| 49 struct NET_EXPORT Options { |
| 50 Options(); |
| 51 |
| 52 size_t max_concurrent_resolves; |
| 53 size_t max_retry_attempts; |
| 54 bool enable_caching; |
| 55 bool enable_async; |
| 56 }; |
| 57 |
| 40 // The parameters for doing a Resolve(). A hostname and port are required, | 58 // The parameters for doing a Resolve(). A hostname and port are required, |
| 41 // the rest are optional (and have reasonable defaults). | 59 // the rest are optional (and have reasonable defaults). |
| 42 class NET_EXPORT RequestInfo { | 60 class NET_EXPORT RequestInfo { |
| 43 public: | 61 public: |
| 44 explicit RequestInfo(const HostPortPair& host_port_pair); | 62 explicit RequestInfo(const HostPortPair& host_port_pair); |
| 45 | 63 |
| 46 const HostPortPair& host_port_pair() const { return host_port_pair_; } | 64 const HostPortPair& host_port_pair() const { return host_port_pair_; } |
| 47 void set_host_port_pair(const HostPortPair& host_port_pair) { | 65 void set_host_port_pair(const HostPortPair& host_port_pair) { |
| 48 host_port_pair_ = host_port_pair; | 66 host_port_pair_ = host_port_pair; |
| 49 } | 67 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // Whether this request was started by the DNS prefetcher. | 106 // Whether this request was started by the DNS prefetcher. |
| 89 bool is_speculative_; | 107 bool is_speculative_; |
| 90 | 108 |
| 91 // The priority for the request. | 109 // The priority for the request. |
| 92 RequestPriority priority_; | 110 RequestPriority priority_; |
| 93 }; | 111 }; |
| 94 | 112 |
| 95 // Opaque type used to cancel a request. | 113 // Opaque type used to cancel a request. |
| 96 typedef void* RequestHandle; | 114 typedef void* RequestHandle; |
| 97 | 115 |
| 98 // This value can be passed into CreateSystemHostResolver as the | 116 // This value can be passed into CreateSystemResolver as the |
| 99 // |max_concurrent_resolves| parameter. It will select a default level of | 117 // |max_concurrent_resolves| parameter. It will select a default level of |
| 100 // concurrency. | 118 // concurrency. |
| 101 static const size_t kDefaultParallelism = 0; | 119 static const size_t kDefaultParallelism = 0; |
| 102 | 120 |
| 103 // This value can be passed into CreateSystemHostResolver as the | 121 // This value can be passed into CreateSystemResolver as the |
| 104 // |max_retry_attempts| parameter. This is the maximum number of times we | 122 // |max_retry_attempts| parameter. |
| 105 // will retry for host resolution. | |
| 106 static const size_t kDefaultRetryAttempts = -1; | 123 static const size_t kDefaultRetryAttempts = -1; |
| 107 | 124 |
| 108 // If any completion callbacks are pending when the resolver is destroyed, | 125 // If any completion callbacks are pending when the resolver is destroyed, |
| 109 // the host resolutions are cancelled, and the completion callbacks will not | 126 // the host resolutions are cancelled, and the completion callbacks will not |
| 110 // be called. | 127 // be called. |
| 111 virtual ~HostResolver(); | 128 virtual ~HostResolver(); |
| 112 | 129 |
| 113 // Resolves the given hostname (or IP address literal), filling out the | 130 // Resolves the given hostname (or IP address literal), filling out the |
| 114 // |addresses| object upon success. The |info.port| parameter will be set as | 131 // |addresses| object upon success. The |info.port| parameter will be set as |
| 115 // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if | 132 // the sin(6)_port field of the sockaddr_in{6} struct. Returns OK if |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 178 |
| 162 // Returns the HostResolverCache |this| uses, or NULL if there isn't one. | 179 // Returns the HostResolverCache |this| uses, or NULL if there isn't one. |
| 163 // Used primarily to clear the cache and for getting debug information. | 180 // Used primarily to clear the cache and for getting debug information. |
| 164 virtual HostCache* GetHostCache(); | 181 virtual HostCache* GetHostCache(); |
| 165 | 182 |
| 166 // Returns the current DNS configuration |this| is using, as a Value, or NULL | 183 // Returns the current DNS configuration |this| is using, as a Value, or NULL |
| 167 // if it's configured to always use the system host resolver. Caller takes | 184 // if it's configured to always use the system host resolver. Caller takes |
| 168 // ownership of the returned Value. | 185 // ownership of the returned Value. |
| 169 virtual base::Value* GetDnsConfigAsValue() const; | 186 virtual base::Value* GetDnsConfigAsValue() const; |
| 170 | 187 |
| 188 // Creates a HostResolver implementation that queries the underlying system. |
| 189 // (Except if a unit-test has changed the global HostResolverProc using |
| 190 // ScopedHostResolverProc to intercept requests to the system). |
| 191 static scoped_ptr<HostResolver> CreateSystemResolver( |
| 192 const Options& options, |
| 193 NetLog* net_log); |
| 194 |
| 195 // As above, but uses default parameters. |
| 196 static scoped_ptr<HostResolver> CreateDefaultResolver(NetLog* net_log); |
| 197 |
| 171 protected: | 198 protected: |
| 172 HostResolver(); | 199 HostResolver(); |
| 173 | 200 |
| 174 private: | 201 private: |
| 175 DISALLOW_COPY_AND_ASSIGN(HostResolver); | 202 DISALLOW_COPY_AND_ASSIGN(HostResolver); |
| 176 }; | 203 }; |
| 177 | 204 |
| 178 // Creates a HostResolver implementation that queries the underlying system. | |
| 179 // (Except if a unit-test has changed the global HostResolverProc using | |
| 180 // ScopedHostResolverProc to intercept requests to the system). | |
| 181 // |max_concurrent_resolves| is how many resolve requests will be allowed to | |
| 182 // run in parallel. Pass HostResolver::kDefaultParallelism to choose a | |
| 183 // default value. | |
| 184 // |max_retry_attempts| is the maximum number of times we will retry for host | |
| 185 // resolution. Pass HostResolver::kDefaultRetryAttempts to choose a default | |
| 186 // value. | |
| 187 // The created HostResolver uses an instance of DnsConfigService to retrieve | |
| 188 // system DNS configuration. | |
| 189 // This resolver should not be used in test context. Instead, use | |
| 190 // MockHostResolver from net/base/mock_host_resolver.h. | |
| 191 NET_EXPORT HostResolver* CreateSystemHostResolver( | |
| 192 size_t max_concurrent_resolves, | |
| 193 size_t max_retry_attempts, | |
| 194 NetLog* net_log); | |
| 195 | |
| 196 // As above, but the created HostResolver does not use a cache. | |
| 197 NET_EXPORT HostResolver* CreateNonCachingSystemHostResolver( | |
| 198 size_t max_concurrent_resolves, | |
| 199 size_t max_retry_attempts, | |
| 200 NetLog* net_log); | |
| 201 | |
| 202 // As above, but the HostResolver will use the asynchronous DNS client in | |
| 203 // DnsTransaction, which will be configured using DnsConfigService to match | |
| 204 // the system DNS settings. If the client fails, the resolver falls back to | |
| 205 // the global HostResolverProc. | |
| 206 NET_EXPORT HostResolver* CreateAsyncHostResolver(size_t max_concurrent_resolves, | |
| 207 size_t max_retry_attempts, | |
| 208 NetLog* net_log); | |
| 209 } // namespace net | 205 } // namespace net |
| 210 | 206 |
| 211 #endif // NET_BASE_HOST_RESOLVER_H_ | 207 #endif // NET_BASE_HOST_RESOLVER_H_ |
| OLD | NEW |