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 #include "net/dns/host_resolver_proc.h" | 5 #include "net/dns/host_resolver_proc.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 AddressFamily address_family, | 74 AddressFamily address_family, |
75 HostResolverFlags host_resolver_flags, | 75 HostResolverFlags host_resolver_flags, |
76 AddressList* addrlist, | 76 AddressList* addrlist, |
77 int* os_error) { | 77 int* os_error) { |
78 if (previous_proc_) { | 78 if (previous_proc_) { |
79 return previous_proc_->Resolve(host, address_family, host_resolver_flags, | 79 return previous_proc_->Resolve(host, address_family, host_resolver_flags, |
80 addrlist, os_error); | 80 addrlist, os_error); |
81 } | 81 } |
82 | 82 |
83 // Final fallback is the system resolver. | 83 // Final fallback is the system resolver. |
84 return SystemHostResolverProc(host, address_family, host_resolver_flags, | 84 return SystemHostResolverCall(host, address_family, host_resolver_flags, |
85 addrlist, os_error); | 85 addrlist, os_error); |
86 } | 86 } |
87 | 87 |
88 void HostResolverProc::SetPreviousProc(HostResolverProc* proc) { | 88 void HostResolverProc::SetPreviousProc(HostResolverProc* proc) { |
89 HostResolverProc* current_previous = previous_proc_; | 89 HostResolverProc* current_previous = previous_proc_; |
90 previous_proc_ = NULL; | 90 previous_proc_ = NULL; |
91 // Now that we've guaranteed |this| is the last proc in a chain, we can | 91 // Now that we've guaranteed |this| is the last proc in a chain, we can |
92 // detect potential cycles using GetLastProc(). | 92 // detect potential cycles using GetLastProc(). |
93 previous_proc_ = (GetLastProc(proc) == this) ? current_previous : proc; | 93 previous_proc_ = (GetLastProc(proc) == this) ? current_previous : proc; |
94 } | 94 } |
(...skipping 17 matching lines...) Expand all Loading... |
112 HostResolverProc* old = default_proc_; | 112 HostResolverProc* old = default_proc_; |
113 default_proc_ = proc; | 113 default_proc_ = proc; |
114 return old; | 114 return old; |
115 } | 115 } |
116 | 116 |
117 // static | 117 // static |
118 HostResolverProc* HostResolverProc::GetDefault() { | 118 HostResolverProc* HostResolverProc::GetDefault() { |
119 return default_proc_; | 119 return default_proc_; |
120 } | 120 } |
121 | 121 |
122 int SystemHostResolverProc(const std::string& host, | 122 int SystemHostResolverCall(const std::string& host, |
123 AddressFamily address_family, | 123 AddressFamily address_family, |
124 HostResolverFlags host_resolver_flags, | 124 HostResolverFlags host_resolver_flags, |
125 AddressList* addrlist, | 125 AddressList* addrlist, |
126 int* os_error) { | 126 int* os_error) { |
127 if (os_error) | 127 if (os_error) |
128 *os_error = 0; | 128 *os_error = 0; |
129 | 129 |
130 struct addrinfo* ai = NULL; | 130 struct addrinfo* ai = NULL; |
131 struct addrinfo hints = {0}; | 131 struct addrinfo hints = {0}; |
132 | 132 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // http://crbug.com/134142 | 241 // http://crbug.com/134142 |
242 if (ai == NULL) | 242 if (ai == NULL) |
243 return ERR_NAME_NOT_RESOLVED; | 243 return ERR_NAME_NOT_RESOLVED; |
244 #endif | 244 #endif |
245 | 245 |
246 *addrlist = AddressList::CreateFromAddrinfo(ai); | 246 *addrlist = AddressList::CreateFromAddrinfo(ai); |
247 freeaddrinfo(ai); | 247 freeaddrinfo(ai); |
248 return OK; | 248 return OK; |
249 } | 249 } |
250 | 250 |
| 251 SystemHostResolverProc::SystemHostResolverProc() : HostResolverProc(NULL) {} |
| 252 |
| 253 int SystemHostResolverProc::Resolve(const std::string& hostname, |
| 254 AddressFamily address_family, |
| 255 HostResolverFlags host_resolver_flags, |
| 256 AddressList* addr_list, |
| 257 int* os_error) { |
| 258 return SystemHostResolverCall(hostname, |
| 259 address_family, |
| 260 host_resolver_flags, |
| 261 addr_list, |
| 262 os_error); |
| 263 } |
| 264 |
| 265 SystemHostResolverProc::~SystemHostResolverProc() {} |
| 266 |
251 } // namespace net | 267 } // namespace net |
OLD | NEW |