| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/base/host_resolver_proc.h" | 5 #include "net/base/host_resolver_proc.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 9 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 10 #include <resolv.h> | 10 #include <resolv.h> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 HostResolverProc* HostResolverProc::default_proc_ = NULL; | 57 HostResolverProc* HostResolverProc::default_proc_ = NULL; |
| 58 | 58 |
| 59 HostResolverProc::HostResolverProc(HostResolverProc* previous) { | 59 HostResolverProc::HostResolverProc(HostResolverProc* previous) { |
| 60 SetPreviousProc(previous); | 60 SetPreviousProc(previous); |
| 61 | 61 |
| 62 // Implicitly fall-back to the global default procedure. | 62 // Implicitly fall-back to the global default procedure. |
| 63 if (!previous) | 63 if (!previous) |
| 64 SetPreviousProc(default_proc_); | 64 SetPreviousProc(default_proc_); |
| 65 } | 65 } |
| 66 | 66 |
| 67 HostResolverProc::~HostResolverProc() { |
| 68 } |
| 69 |
| 70 int HostResolverProc::ResolveUsingPrevious( |
| 71 const std::string& host, |
| 72 AddressFamily address_family, |
| 73 HostResolverFlags host_resolver_flags, |
| 74 AddressList* addrlist, |
| 75 int* os_error) { |
| 76 if (previous_proc_) { |
| 77 return previous_proc_->Resolve(host, address_family, host_resolver_flags, |
| 78 addrlist, os_error); |
| 79 } |
| 80 |
| 81 // Final fallback is the system resolver. |
| 82 return SystemHostResolverProc(host, address_family, host_resolver_flags, |
| 83 addrlist, os_error); |
| 84 } |
| 85 |
| 67 void HostResolverProc::SetPreviousProc(HostResolverProc* proc) { | 86 void HostResolverProc::SetPreviousProc(HostResolverProc* proc) { |
| 68 HostResolverProc* current_previous = previous_proc_; | 87 HostResolverProc* current_previous = previous_proc_; |
| 69 previous_proc_ = NULL; | 88 previous_proc_ = NULL; |
| 70 // Now that we've guaranteed |this| is the last proc in a chain, we can | 89 // Now that we've guaranteed |this| is the last proc in a chain, we can |
| 71 // detect potential cycles using GetLastProc(). | 90 // detect potential cycles using GetLastProc(). |
| 72 previous_proc_ = (GetLastProc(proc) == this) ? current_previous : proc; | 91 previous_proc_ = (GetLastProc(proc) == this) ? current_previous : proc; |
| 73 } | 92 } |
| 74 | 93 |
| 75 void HostResolverProc::SetLastProc(HostResolverProc* proc) { | 94 void HostResolverProc::SetLastProc(HostResolverProc* proc) { |
| 76 GetLastProc(this)->SetPreviousProc(proc); | 95 GetLastProc(this)->SetPreviousProc(proc); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 HostResolverProc* old = default_proc_; | 110 HostResolverProc* old = default_proc_; |
| 92 default_proc_ = proc; | 111 default_proc_ = proc; |
| 93 return old; | 112 return old; |
| 94 } | 113 } |
| 95 | 114 |
| 96 // static | 115 // static |
| 97 HostResolverProc* HostResolverProc::GetDefault() { | 116 HostResolverProc* HostResolverProc::GetDefault() { |
| 98 return default_proc_; | 117 return default_proc_; |
| 99 } | 118 } |
| 100 | 119 |
| 101 HostResolverProc::~HostResolverProc() { | |
| 102 } | |
| 103 | |
| 104 int HostResolverProc::ResolveUsingPrevious( | |
| 105 const std::string& host, | |
| 106 AddressFamily address_family, | |
| 107 HostResolverFlags host_resolver_flags, | |
| 108 AddressList* addrlist, | |
| 109 int* os_error) { | |
| 110 if (previous_proc_) { | |
| 111 return previous_proc_->Resolve(host, address_family, host_resolver_flags, | |
| 112 addrlist, os_error); | |
| 113 } | |
| 114 | |
| 115 // Final fallback is the system resolver. | |
| 116 return SystemHostResolverProc(host, address_family, host_resolver_flags, | |
| 117 addrlist, os_error); | |
| 118 } | |
| 119 | |
| 120 int SystemHostResolverProc(const std::string& host, | 120 int SystemHostResolverProc(const std::string& host, |
| 121 AddressFamily address_family, | 121 AddressFamily address_family, |
| 122 HostResolverFlags host_resolver_flags, | 122 HostResolverFlags host_resolver_flags, |
| 123 AddressList* addrlist, | 123 AddressList* addrlist, |
| 124 int* os_error) { | 124 int* os_error) { |
| 125 static const size_t kMaxHostLength = 4096; | 125 static const size_t kMaxHostLength = 4096; |
| 126 | 126 |
| 127 if (os_error) | 127 if (os_error) |
| 128 *os_error = 0; | 128 *os_error = 0; |
| 129 | 129 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 #endif | 254 #endif |
| 255 | 255 |
| 256 return ERR_NAME_NOT_RESOLVED; | 256 return ERR_NAME_NOT_RESOLVED; |
| 257 } | 257 } |
| 258 | 258 |
| 259 addrlist->Adopt(ai); | 259 addrlist->Adopt(ai); |
| 260 return OK; | 260 return OK; |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace net | 263 } // namespace net |
| OLD | NEW |