Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: net/base/host_resolver_impl_unittest.cc

Issue 1629005: Revert 43826 - HostResolver now adds AI_CANONNAME to the hint flags if a requ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/host_resolver_proc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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
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), 76 : hostname(hostname), address_family(address_family) {}
77 address_family(address_family) {}
78 std::string hostname; 77 std::string hostname;
79 AddressFamily address_family; 78 AddressFamily address_family;
80 }; 79 };
81 80
82 typedef std::vector<CaptureEntry> CaptureList; 81 typedef std::vector<CaptureEntry> CaptureList;
83 82
84 explicit CapturingHostResolverProc(HostResolverProc* previous) 83 explicit CapturingHostResolverProc(HostResolverProc* previous)
85 : HostResolverProc(previous), event_(true, false) { 84 : HostResolverProc(previous), event_(true, false) {
86 } 85 }
87 86
88 void Signal() { 87 void Signal() {
89 event_.Signal(); 88 event_.Signal();
90 } 89 }
91 90
92 virtual int Resolve(const std::string& hostname, 91 virtual int Resolve(const std::string& hostname,
93 AddressFamily address_family, 92 AddressFamily address_family,
94 HostResolverFlags host_resolver_flags,
95 AddressList* addrlist) { 93 AddressList* addrlist) {
96 event_.Wait(); 94 event_.Wait();
97 { 95 {
98 AutoLock l(lock_); 96 AutoLock l(lock_);
99 capture_list_.push_back(CaptureEntry(hostname, address_family)); 97 capture_list_.push_back(CaptureEntry(hostname, address_family));
100 } 98 }
101 return ResolveUsingPrevious(hostname, address_family, 99 return ResolveUsingPrevious(hostname, address_family, addrlist);
102 host_resolver_flags, addrlist);
103 } 100 }
104 101
105 CaptureList GetCaptureList() const { 102 CaptureList GetCaptureList() const {
106 CaptureList copy; 103 CaptureList copy;
107 { 104 {
108 AutoLock l(lock_); 105 AutoLock l(lock_);
109 copy = capture_list_; 106 copy = capture_list_;
110 } 107 }
111 return copy; 108 return copy;
112 } 109 }
(...skipping 17 matching lines...) Expand all
130 // x = length of hostname 127 // x = length of hostname
131 // y = ASCII value of hostname[0] 128 // y = ASCII value of hostname[0]
132 // z = value of address_family 129 // z = value of address_family
133 // 130 //
134 class EchoingHostResolverProc : public HostResolverProc { 131 class EchoingHostResolverProc : public HostResolverProc {
135 public: 132 public:
136 EchoingHostResolverProc() : HostResolverProc(NULL) {} 133 EchoingHostResolverProc() : HostResolverProc(NULL) {}
137 134
138 virtual int Resolve(const std::string& hostname, 135 virtual int Resolve(const std::string& hostname,
139 AddressFamily address_family, 136 AddressFamily address_family,
140 HostResolverFlags host_resolver_flags,
141 AddressList* addrlist) { 137 AddressList* addrlist) {
142 // Encode the request's hostname and address_family in the output address. 138 // Encode the request's hostname and address_family in the output address.
143 std::string ip_literal = StringPrintf("192.%d.%d.%d", 139 std::string ip_literal = StringPrintf("192.%d.%d.%d",
144 static_cast<int>(hostname.size()), 140 static_cast<int>(hostname.size()),
145 static_cast<int>(hostname[0]), 141 static_cast<int>(hostname[0]),
146 static_cast<int>(address_family)); 142 static_cast<int>(address_family));
147 143
148 return SystemHostResolverProc(ip_literal, 144 return SystemHostResolverProc(ip_literal,
149 ADDRESS_FAMILY_UNSPECIFIED, 145 ADDRESS_FAMILY_UNSPECIFIED,
150 host_resolver_flags,
151 addrlist); 146 addrlist);
152 } 147 }
153 }; 148 };
154 149
155 // Helper that represents a single Resolve() result, used to inspect all the 150 // Helper that represents a single Resolve() result, used to inspect all the
156 // resolve results by forwarding them to Delegate. 151 // resolve results by forwarding them to Delegate.
157 class ResolveRequest { 152 class ResolveRequest {
158 public: 153 public:
159 // Delegate interface, for notification when the ResolveRequest completes. 154 // Delegate interface, for notification when the ResolveRequest completes.
160 class Delegate { 155 class Delegate {
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // Addresses take the form: 192.x.y.z 1484 // Addresses take the form: 192.x.y.z
1490 // x = length of hostname 1485 // x = length of hostname
1491 // y = ASCII value of hostname[0] 1486 // y = ASCII value of hostname[0]
1492 // z = value of address family 1487 // z = value of address family
1493 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head())); 1488 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[0].head()));
1494 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head())); 1489 EXPECT_EQ("192.1.98.2", NetAddressToString(addrlist[1].head()));
1495 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head())); 1490 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[2].head()));
1496 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head())); 1491 EXPECT_EQ("192.1.98.1", NetAddressToString(addrlist[3].head()));
1497 } 1492 }
1498 1493
1499 // TODO(cbentzel): Test a mix of requests with different HostResolverFlags.
1500
1501 } // namespace 1494 } // namespace
1502 1495
1503 } // namespace net 1496 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/host_resolver_proc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698