| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 HostResolverProc::~HostResolverProc() { | 69 HostResolverProc::~HostResolverProc() { |
| 70 } | 70 } |
| 71 | 71 |
| 72 int HostResolverProc::ResolveUsingPrevious( | 72 int HostResolverProc::ResolveUsingPrevious( |
| 73 const std::string& host, | 73 const std::string& host, |
| 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_.get()) { |
| 79 return previous_proc_->Resolve(host, address_family, host_resolver_flags, | 79 return previous_proc_->Resolve( |
| 80 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(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_.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 |
| 96 void HostResolverProc::SetLastProc(HostResolverProc* proc) { | 96 void HostResolverProc::SetLastProc(HostResolverProc* proc) { |
| 97 GetLastProc(this)->SetPreviousProc(proc); | 97 GetLastProc(this)->SetPreviousProc(proc); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 HostResolverProc* HostResolverProc::GetLastProc(HostResolverProc* proc) { | 101 HostResolverProc* HostResolverProc::GetLastProc(HostResolverProc* proc) { |
| 102 if (proc == NULL) | 102 if (proc == NULL) |
| 103 return NULL; | 103 return NULL; |
| 104 HostResolverProc* last_proc = proc; | 104 HostResolverProc* last_proc = proc; |
| 105 while (last_proc->previous_proc_ != NULL) | 105 while (last_proc->previous_proc_.get() != NULL) |
| 106 last_proc = last_proc->previous_proc_; | 106 last_proc = last_proc->previous_proc_.get(); |
| 107 return last_proc; | 107 return last_proc; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 HostResolverProc* HostResolverProc::SetDefault(HostResolverProc* proc) { | 111 HostResolverProc* HostResolverProc::SetDefault(HostResolverProc* proc) { |
| 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 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 return SystemHostResolverCall(hostname, | 258 return SystemHostResolverCall(hostname, |
| 259 address_family, | 259 address_family, |
| 260 host_resolver_flags, | 260 host_resolver_flags, |
| 261 addr_list, | 261 addr_list, |
| 262 os_error); | 262 os_error); |
| 263 } | 263 } |
| 264 | 264 |
| 265 SystemHostResolverProc::~SystemHostResolverProc() {} | 265 SystemHostResolverProc::~SystemHostResolverProc() {} |
| 266 | 266 |
| 267 } // namespace net | 267 } // namespace net |
| OLD | NEW |