| 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_.get()) { | 78 if (previous_proc_.get()) { |
| 79 return previous_proc_->Resolve( | 79 return previous_proc_->Resolve( |
| 80 host, address_family, host_resolver_flags, addrlist, os_error); | 80 host, address_family, host_resolver_flags, addrlist, os_error); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Final fallback is the system resolver. | 83 // Final fallback is the system resolver. |
| 84 return SystemHostResolverCall(host, address_family, host_resolver_flags, | 84 return SystemHostResolverCall( |
| 85 addrlist, os_error); | 85 host, address_family, host_resolver_flags, 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_.get(); | 89 HostResolverProc* current_previous = previous_proc_.get(); |
| 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 } |
| 95 | 95 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 if (err) { | 217 if (err) { |
| 218 #if defined(OS_WIN) | 218 #if defined(OS_WIN) |
| 219 err = WSAGetLastError(); | 219 err = WSAGetLastError(); |
| 220 #endif | 220 #endif |
| 221 | 221 |
| 222 // Return the OS error to the caller. | 222 // Return the OS error to the caller. |
| 223 if (os_error) | 223 if (os_error) |
| 224 *os_error = err; | 224 *os_error = err; |
| 225 | 225 |
| 226 // If the call to getaddrinfo() failed because of a system error, report | 226 // If the call to getaddrinfo() failed because of a system error, report |
| 227 // it separately from ERR_NAME_NOT_RESOLVED. | 227 // it separately from ERR_NAME_NOT_RESOLVED. |
| 228 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| 229 if (err != WSAHOST_NOT_FOUND && err != WSANO_DATA) | 229 if (err != WSAHOST_NOT_FOUND && err != WSANO_DATA) |
| 230 return ERR_NAME_RESOLUTION_FAILED; | 230 return ERR_NAME_RESOLUTION_FAILED; |
| 231 #elif defined(OS_POSIX) && !defined(OS_FREEBSD) | 231 #elif defined(OS_POSIX) && !defined(OS_FREEBSD) |
| 232 if (err != EAI_NONAME && err != EAI_NODATA) | 232 if (err != EAI_NONAME && err != EAI_NODATA) |
| 233 return ERR_NAME_RESOLUTION_FAILED; | 233 return ERR_NAME_RESOLUTION_FAILED; |
| 234 #endif | 234 #endif |
| 235 | 235 |
| 236 return ERR_NAME_NOT_RESOLVED; | 236 return ERR_NAME_NOT_RESOLVED; |
| 237 } | 237 } |
| 238 | 238 |
| 239 #if defined(OS_ANDROID) | 239 #if defined(OS_ANDROID) |
| 240 // Workaround for Android's getaddrinfo leaving ai==NULL without an error. | 240 // Workaround for Android's getaddrinfo leaving ai==NULL without an error. |
| 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) {} | 251 SystemHostResolverProc::SystemHostResolverProc() : HostResolverProc(NULL) { |
| 252 } |
| 252 | 253 |
| 253 int SystemHostResolverProc::Resolve(const std::string& hostname, | 254 int SystemHostResolverProc::Resolve(const std::string& hostname, |
| 254 AddressFamily address_family, | 255 AddressFamily address_family, |
| 255 HostResolverFlags host_resolver_flags, | 256 HostResolverFlags host_resolver_flags, |
| 256 AddressList* addr_list, | 257 AddressList* addr_list, |
| 257 int* os_error) { | 258 int* os_error) { |
| 258 return SystemHostResolverCall(hostname, | 259 return SystemHostResolverCall( |
| 259 address_family, | 260 hostname, address_family, host_resolver_flags, addr_list, os_error); |
| 260 host_resolver_flags, | |
| 261 addr_list, | |
| 262 os_error); | |
| 263 } | 261 } |
| 264 | 262 |
| 265 SystemHostResolverProc::~SystemHostResolverProc() {} | 263 SystemHostResolverProc::~SystemHostResolverProc() { |
| 264 } |
| 266 | 265 |
| 267 } // namespace net | 266 } // namespace net |
| OLD | NEW |