| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/address_family.h" |
| 12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 13 | 14 |
| 14 class MessageLoop; | 15 class MessageLoop; |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 class AddressList; | 19 class AddressList; |
| 19 class HostCache; | 20 class HostCache; |
| 20 class LoadLog; | 21 class LoadLog; |
| 21 | 22 |
| 22 // This class represents the task of resolving hostnames (or IP address | 23 // This class represents the task of resolving hostnames (or IP address |
| 23 // literal) to an AddressList object. | 24 // literal) to an AddressList object. |
| 24 // | 25 // |
| 25 // HostResolver can handle multiple requests at a time, so when cancelling a | 26 // HostResolver can handle multiple requests at a time, so when cancelling a |
| 26 // request the RequestHandle that was returned by Resolve() needs to be | 27 // request the RequestHandle that was returned by Resolve() needs to be |
| 27 // given. A simpler alternative for consumers that only have 1 outstanding | 28 // given. A simpler alternative for consumers that only have 1 outstanding |
| 28 // request at a time is to create a SingleRequestHostResolver wrapper around | 29 // request at a time is to create a SingleRequestHostResolver wrapper around |
| 29 // HostResolver (which will automatically cancel the single request when it | 30 // HostResolver (which will automatically cancel the single request when it |
| 30 // goes out of scope). | 31 // goes out of scope). |
| 31 class HostResolver : public base::RefCountedThreadSafe<HostResolver> { | 32 class HostResolver : public base::RefCountedThreadSafe<HostResolver> { |
| 32 public: | 33 public: |
| 33 // The parameters for doing a Resolve(). |hostname| and |port| are required, | 34 // The parameters for doing a Resolve(). |hostname| and |port| are required, |
| 34 // the rest are optional (and have reasonable defaults). | 35 // the rest are optional (and have reasonable defaults). |
| 35 class RequestInfo { | 36 class RequestInfo { |
| 36 public: | 37 public: |
| 37 RequestInfo(const std::string& hostname, int port) | 38 RequestInfo(const std::string& hostname, int port) |
| 38 : hostname_(hostname), | 39 : hostname_(hostname), |
| 40 address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 39 port_(port), | 41 port_(port), |
| 40 allow_cached_response_(true), | 42 allow_cached_response_(true), |
| 41 is_speculative_(false) {} | 43 is_speculative_(false) {} |
| 42 | 44 |
| 43 const int port() const { return port_; } | 45 const int port() const { return port_; } |
| 44 const std::string& hostname() const { return hostname_; } | 46 const std::string& hostname() const { return hostname_; } |
| 45 | 47 |
| 48 AddressFamily address_family() const { return address_family_; } |
| 49 void set_address_family(AddressFamily address_family) { |
| 50 address_family_ = address_family; |
| 51 } |
| 52 |
| 46 bool allow_cached_response() const { return allow_cached_response_; } | 53 bool allow_cached_response() const { return allow_cached_response_; } |
| 47 void set_allow_cached_response(bool b) { allow_cached_response_ = b; } | 54 void set_allow_cached_response(bool b) { allow_cached_response_ = b; } |
| 48 | 55 |
| 49 bool is_speculative() const { return is_speculative_; } | 56 bool is_speculative() const { return is_speculative_; } |
| 50 void set_is_speculative(bool b) { is_speculative_ = b; } | 57 void set_is_speculative(bool b) { is_speculative_ = b; } |
| 51 | 58 |
| 52 const GURL& referrer() const { return referrer_; } | 59 const GURL& referrer() const { return referrer_; } |
| 53 void set_referrer(const GURL& referrer) { referrer_ = referrer; } | 60 void set_referrer(const GURL& referrer) { referrer_ = referrer; } |
| 54 | 61 |
| 55 private: | 62 private: |
| 56 // The hostname to resolve. | 63 // The hostname to resolve. |
| 57 std::string hostname_; | 64 std::string hostname_; |
| 58 | 65 |
| 66 // The address family to restrict results to. |
| 67 AddressFamily address_family_; |
| 68 |
| 59 // The port number to set in the result's sockaddrs. | 69 // The port number to set in the result's sockaddrs. |
| 60 int port_; | 70 int port_; |
| 61 | 71 |
| 62 // Whether it is ok to return a result from the host cache. | 72 // Whether it is ok to return a result from the host cache. |
| 63 bool allow_cached_response_; | 73 bool allow_cached_response_; |
| 64 | 74 |
| 65 // Whether this request was started by the DNS prefetcher. | 75 // Whether this request was started by the DNS prefetcher. |
| 66 bool is_speculative_; | 76 bool is_speculative_; |
| 67 | 77 |
| 68 // Optional data for consumption by observers. This is the URL of the | 78 // Optional data for consumption by observers. This is the URL of the |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Unregisters an observer previously added by AddObserver(). | 141 // Unregisters an observer previously added by AddObserver(). |
| 132 virtual void RemoveObserver(Observer* observer) = 0; | 142 virtual void RemoveObserver(Observer* observer) = 0; |
| 133 | 143 |
| 134 // Returns the host cache, or NULL if this implementation does not use | 144 // Returns the host cache, or NULL if this implementation does not use |
| 135 // a HostCache. | 145 // a HostCache. |
| 136 virtual HostCache* GetHostCache() = 0; | 146 virtual HostCache* GetHostCache() = 0; |
| 137 | 147 |
| 138 // TODO(eroman): temp hack for http://crbug.com/18373 | 148 // TODO(eroman): temp hack for http://crbug.com/18373 |
| 139 virtual void Shutdown() = 0; | 149 virtual void Shutdown() = 0; |
| 140 | 150 |
| 151 // Disables or enables support for IPv6 results. |
| 152 virtual void DisableIPv6(bool disable_ipv6) {} |
| 153 |
| 141 protected: | 154 protected: |
| 142 HostResolver() { } | 155 HostResolver() { } |
| 143 | 156 |
| 144 private: | 157 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(HostResolver); | 158 DISALLOW_COPY_AND_ASSIGN(HostResolver); |
| 146 }; | 159 }; |
| 147 | 160 |
| 148 // This class represents the task of resolving a hostname (or IP address | 161 // This class represents the task of resolving a hostname (or IP address |
| 149 // literal) to an AddressList object. It wraps HostResolver to resolve only a | 162 // literal) to an AddressList object. It wraps HostResolver to resolve only a |
| 150 // single hostname at a time and cancels this request when going out of scope. | 163 // single hostname at a time and cancels this request when going out of scope. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 }; | 196 }; |
| 184 | 197 |
| 185 // Creates a HostResolver implementation that queries the underlying system. | 198 // Creates a HostResolver implementation that queries the underlying system. |
| 186 // (Except if a unit-test has changed the global HostResolverProc using | 199 // (Except if a unit-test has changed the global HostResolverProc using |
| 187 // ScopedHostResolverProc to intercept requests to the system). | 200 // ScopedHostResolverProc to intercept requests to the system). |
| 188 HostResolver* CreateSystemHostResolver(); | 201 HostResolver* CreateSystemHostResolver(); |
| 189 | 202 |
| 190 } // namespace net | 203 } // namespace net |
| 191 | 204 |
| 192 #endif // NET_BASE_HOST_RESOLVER_H_ | 205 #endif // NET_BASE_HOST_RESOLVER_H_ |
| OLD | NEW |