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/mock_host_resolver.h" | 5 #include "net/base/mock_host_resolver.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 const std::string& replacement) { | 149 const std::string& replacement) { |
150 AddRuleForAddressFamily(host_pattern, ADDRESS_FAMILY_UNSPECIFIED, | 150 AddRuleForAddressFamily(host_pattern, ADDRESS_FAMILY_UNSPECIFIED, |
151 replacement); | 151 replacement); |
152 } | 152 } |
153 | 153 |
154 void RuleBasedHostResolverProc::AddRuleForAddressFamily( | 154 void RuleBasedHostResolverProc::AddRuleForAddressFamily( |
155 const std::string& host_pattern, | 155 const std::string& host_pattern, |
156 AddressFamily address_family, | 156 AddressFamily address_family, |
157 const std::string& replacement) { | 157 const std::string& replacement) { |
158 DCHECK(!replacement.empty()); | 158 DCHECK(!replacement.empty()); |
159 Rule rule(Rule::kResolverTypeSystem, host_pattern, | 159 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
160 address_family, 0, replacement, "", 0); | 160 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 161 Rule rule(Rule::kResolverTypeSystem, host_pattern, address_family, flags, |
| 162 replacement, "", 0); |
161 rules_.push_back(rule); | 163 rules_.push_back(rule); |
162 } | 164 } |
163 | 165 |
164 void RuleBasedHostResolverProc::AddIPLiteralRule( | 166 void RuleBasedHostResolverProc::AddIPLiteralRule( |
165 const std::string& host_pattern, | 167 const std::string& host_pattern, |
166 const std::string& ip_literal, | 168 const std::string& ip_literal, |
167 const std::string& canonical_name) { | 169 const std::string& canonical_name) { |
168 // Literals are always resolved to themselves by HostResolverImpl, | 170 // Literals are always resolved to themselves by HostResolverImpl, |
169 // consequently we do not support remapping them. | 171 // consequently we do not support remapping them. |
170 IPAddressNumber ip_number; | 172 IPAddressNumber ip_number; |
171 DCHECK(!ParseIPLiteralToNumber(host_pattern, &ip_number)); | 173 DCHECK(!ParseIPLiteralToNumber(host_pattern, &ip_number)); |
172 Rule rule(Rule::kResolverTypeIPLiteral, | 174 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
173 host_pattern, | 175 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
174 ADDRESS_FAMILY_UNSPECIFIED, | 176 if (!canonical_name.empty()) |
175 canonical_name.empty() ? 0 : HOST_RESOLVER_CANONNAME, | 177 flags |= HOST_RESOLVER_CANONNAME; |
176 ip_literal, | 178 Rule rule(Rule::kResolverTypeIPLiteral, host_pattern, |
177 canonical_name, | 179 ADDRESS_FAMILY_UNSPECIFIED, flags, ip_literal, canonical_name, 0); |
178 0); | |
179 rules_.push_back(rule); | 180 rules_.push_back(rule); |
180 } | 181 } |
181 | 182 |
182 void RuleBasedHostResolverProc::AddRuleWithLatency( | 183 void RuleBasedHostResolverProc::AddRuleWithLatency( |
183 const std::string& host_pattern, | 184 const std::string& host_pattern, |
184 const std::string& replacement, | 185 const std::string& replacement, |
185 int latency_ms) { | 186 int latency_ms) { |
186 DCHECK(!replacement.empty()); | 187 DCHECK(!replacement.empty()); |
187 Rule rule(Rule::kResolverTypeSystem, host_pattern, | 188 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
188 ADDRESS_FAMILY_UNSPECIFIED, 0, replacement, "", latency_ms); | 189 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 190 Rule rule(Rule::kResolverTypeSystem, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, |
| 191 flags, replacement, "", latency_ms); |
189 rules_.push_back(rule); | 192 rules_.push_back(rule); |
190 } | 193 } |
191 | 194 |
192 void RuleBasedHostResolverProc::AllowDirectLookup( | 195 void RuleBasedHostResolverProc::AllowDirectLookup( |
193 const std::string& host_pattern) { | 196 const std::string& host_pattern) { |
194 Rule rule(Rule::kResolverTypeSystem, host_pattern, | 197 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
195 ADDRESS_FAMILY_UNSPECIFIED, 0, "", "", 0); | 198 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 199 Rule rule(Rule::kResolverTypeSystem, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, |
| 200 flags, "", "", 0); |
196 rules_.push_back(rule); | 201 rules_.push_back(rule); |
197 } | 202 } |
198 | 203 |
199 void RuleBasedHostResolverProc::AddSimulatedFailure( | 204 void RuleBasedHostResolverProc::AddSimulatedFailure( |
200 const std::string& host_pattern) { | 205 const std::string& host_pattern) { |
201 Rule rule(Rule::kResolverTypeFail, host_pattern, | 206 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
202 ADDRESS_FAMILY_UNSPECIFIED, 0, "", "", 0); | 207 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
| 208 Rule rule(Rule::kResolverTypeFail, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, |
| 209 flags, "", "", 0); |
203 rules_.push_back(rule); | 210 rules_.push_back(rule); |
204 } | 211 } |
205 | 212 |
206 int RuleBasedHostResolverProc::Resolve(const std::string& host, | 213 int RuleBasedHostResolverProc::Resolve(const std::string& host, |
207 AddressFamily address_family, | 214 AddressFamily address_family, |
208 HostResolverFlags host_resolver_flags, | 215 HostResolverFlags host_resolver_flags, |
209 AddressList* addrlist, | 216 AddressList* addrlist, |
210 int* os_error) { | 217 int* os_error) { |
211 RuleList::iterator r; | 218 RuleList::iterator r; |
212 for (r = rules_.begin(); r != rules_.end(); ++r) { | 219 for (r = rules_.begin(); r != rules_.end(); ++r) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 CHECK_EQ(old_proc, current_proc_); | 269 CHECK_EQ(old_proc, current_proc_); |
263 } | 270 } |
264 | 271 |
265 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 272 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
266 current_proc_ = proc; | 273 current_proc_ = proc; |
267 previous_proc_ = HostResolverProc::SetDefault(current_proc_); | 274 previous_proc_ = HostResolverProc::SetDefault(current_proc_); |
268 current_proc_->SetLastProc(previous_proc_); | 275 current_proc_->SetLastProc(previous_proc_); |
269 } | 276 } |
270 | 277 |
271 } // namespace net | 278 } // namespace net |
OLD | NEW |