| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return info; | 66 return info; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // A variant of WaitingHostResolverProc that pushes each host mapped into a | 69 // A variant of WaitingHostResolverProc that pushes each host mapped into a |
| 70 // list. | 70 // list. |
| 71 // (and uses a manual-reset event rather than auto-reset). | 71 // (and uses a manual-reset event rather than auto-reset). |
| 72 class CapturingHostResolverProc : public HostResolverProc { | 72 class CapturingHostResolverProc : public HostResolverProc { |
| 73 public: | 73 public: |
| 74 struct CaptureEntry { | 74 struct CaptureEntry { |
| 75 CaptureEntry(const std::string& hostname, AddressFamily address_family) | 75 CaptureEntry(const std::string& hostname, AddressFamily address_family) |
| 76 : hostname(hostname), address_family(address_family) {} | 76 : hostname(hostname), |
| 77 address_family(address_family) {} |
| 77 std::string hostname; | 78 std::string hostname; |
| 78 AddressFamily address_family; | 79 AddressFamily address_family; |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 typedef std::vector<CaptureEntry> CaptureList; | 82 typedef std::vector<CaptureEntry> CaptureList; |
| 82 | 83 |
| 83 explicit CapturingHostResolverProc(HostResolverProc* previous) | 84 explicit CapturingHostResolverProc(HostResolverProc* previous) |
| 84 : HostResolverProc(previous), event_(true, false) { | 85 : HostResolverProc(previous), event_(true, false) { |
| 85 } | 86 } |
| 86 | 87 |
| 87 void Signal() { | 88 void Signal() { |
| 88 event_.Signal(); | 89 event_.Signal(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 virtual int Resolve(const std::string& hostname, | 92 virtual int Resolve(const std::string& hostname, |
| 92 AddressFamily address_family, | 93 AddressFamily address_family, |
| 94 HostResolverFlags host_resolver_flags, |
| 93 AddressList* addrlist) { | 95 AddressList* addrlist) { |
| 94 event_.Wait(); | 96 event_.Wait(); |
| 95 { | 97 { |
| 96 AutoLock l(lock_); | 98 AutoLock l(lock_); |
| 97 capture_list_.push_back(CaptureEntry(hostname, address_family)); | 99 capture_list_.push_back(CaptureEntry(hostname, address_family)); |
| 98 } | 100 } |
| 99 return ResolveUsingPrevious(hostname, address_family, addrlist); | 101 return ResolveUsingPrevious(hostname, address_family, |
| 102 host_resolver_flags, addrlist); |
| 100 } | 103 } |
| 101 | 104 |
| 102 CaptureList GetCaptureList() const { | 105 CaptureList GetCaptureList() const { |
| 103 CaptureList copy; | 106 CaptureList copy; |
| 104 { | 107 { |
| 105 AutoLock l(lock_); | 108 AutoLock l(lock_); |
| 106 copy = capture_list_; | 109 copy = capture_list_; |
| 107 } | 110 } |
| 108 return copy; | 111 return copy; |
| 109 } | 112 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 // x = length of hostname | 130 // x = length of hostname |
| 128 // y = ASCII value of hostname[0] | 131 // y = ASCII value of hostname[0] |
| 129 // z = value of address_family | 132 // z = value of address_family |
| 130 // | 133 // |
| 131 class EchoingHostResolverProc : public HostResolverProc { | 134 class EchoingHostResolverProc : public HostResolverProc { |
| 132 public: | 135 public: |
| 133 EchoingHostResolverProc() : HostResolverProc(NULL) {} | 136 EchoingHostResolverProc() : HostResolverProc(NULL) {} |
| 134 | 137 |
| 135 virtual int Resolve(const std::string& hostname, | 138 virtual int Resolve(const std::string& hostname, |
| 136 AddressFamily address_family, | 139 AddressFamily address_family, |
| 140 HostResolverFlags host_resolver_flags, |
| 137 AddressList* addrlist) { | 141 AddressList* addrlist) { |
| 138 // Encode the request's hostname and address_family in the output address. | 142 // Encode the request's hostname and address_family in the output address. |
| 139 std::string ip_literal = StringPrintf("192.%d.%d.%d", | 143 std::string ip_literal = StringPrintf("192.%d.%d.%d", |
| 140 static_cast<int>(hostname.size()), | 144 static_cast<int>(hostname.size()), |
| 141 static_cast<int>(hostname[0]), | 145 static_cast<int>(hostname[0]), |
| 142 static_cast<int>(address_family)); | 146 static_cast<int>(address_family)); |
| 143 | 147 |
| 144 return SystemHostResolverProc(ip_literal, | 148 return SystemHostResolverProc(ip_literal, |
| 145 ADDRESS_FAMILY_UNSPECIFIED, | 149 ADDRESS_FAMILY_UNSPECIFIED, |
| 150 host_resolver_flags, |
| 146 addrlist); | 151 addrlist); |
| 147 } | 152 } |
| 148 }; | 153 }; |
| 149 | 154 |
| 150 // Helper that represents a single Resolve() result, used to inspect all the | 155 // Helper that represents a single Resolve() result, used to inspect all the |
| 151 // resolve results by forwarding them to Delegate. | 156 // resolve results by forwarding them to Delegate. |
| 152 class ResolveRequest { | 157 class ResolveRequest { |
| 153 public: | 158 public: |
| 154 // Delegate interface, for notification when the ResolveRequest completes. | 159 // Delegate interface, for notification when the ResolveRequest completes. |
| 155 class Delegate { | 160 class Delegate { |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 // Addresses take the form: 192.x.y.z | 1489 // Addresses take the form: 192.x.y.z |
| 1485 // x = length of hostname | 1490 // x = length of hostname |
| 1486 // y = ASCII value of hostname[0] | 1491 // y = ASCII value of hostname[0] |
| 1487 // z = value of address family | 1492 // z = value of address family |
| 1488 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); | 1493 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); |
| 1489 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); | 1494 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); |
| 1490 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); | 1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); |
| 1491 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); | 1496 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); |
| 1492 } | 1497 } |
| 1493 | 1498 |
| 1499 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags. |
| 1500 |
| 1494 } // namespace | 1501 } // namespace |
| 1495 | 1502 |
| 1496 } // namespace net | 1503 } // namespace net |
| OLD | NEW |