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/mock_host_resolver.h" | 5 #include "net/dns/mock_host_resolver.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 replacement); | 249 replacement); |
250 } | 250 } |
251 | 251 |
252 void RuleBasedHostResolverProc::AddRuleForAddressFamily( | 252 void RuleBasedHostResolverProc::AddRuleForAddressFamily( |
253 const std::string& host_pattern, | 253 const std::string& host_pattern, |
254 AddressFamily address_family, | 254 AddressFamily address_family, |
255 const std::string& replacement) { | 255 const std::string& replacement) { |
256 DCHECK(!replacement.empty()); | 256 DCHECK(!replacement.empty()); |
257 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | | 257 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
258 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 258 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
259 Rule rule(Rule::kResolverTypeSystem, host_pattern, address_family, flags, | 259 Rule rule(Rule::kResolverTypeSystem, |
260 replacement, "", 0); | 260 host_pattern, |
| 261 address_family, |
| 262 flags, |
| 263 replacement, |
| 264 std::string(), |
| 265 0); |
261 rules_.push_back(rule); | 266 rules_.push_back(rule); |
262 } | 267 } |
263 | 268 |
264 void RuleBasedHostResolverProc::AddIPLiteralRule( | 269 void RuleBasedHostResolverProc::AddIPLiteralRule( |
265 const std::string& host_pattern, | 270 const std::string& host_pattern, |
266 const std::string& ip_literal, | 271 const std::string& ip_literal, |
267 const std::string& canonical_name) { | 272 const std::string& canonical_name) { |
268 // Literals are always resolved to themselves by HostResolverImpl, | 273 // Literals are always resolved to themselves by HostResolverImpl, |
269 // consequently we do not support remapping them. | 274 // consequently we do not support remapping them. |
270 IPAddressNumber ip_number; | 275 IPAddressNumber ip_number; |
271 DCHECK(!ParseIPLiteralToNumber(host_pattern, &ip_number)); | 276 DCHECK(!ParseIPLiteralToNumber(host_pattern, &ip_number)); |
272 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | | 277 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
273 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 278 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
274 if (!canonical_name.empty()) | 279 if (!canonical_name.empty()) |
275 flags |= HOST_RESOLVER_CANONNAME; | 280 flags |= HOST_RESOLVER_CANONNAME; |
276 Rule rule(Rule::kResolverTypeIPLiteral, host_pattern, | 281 Rule rule(Rule::kResolverTypeIPLiteral, host_pattern, |
277 ADDRESS_FAMILY_UNSPECIFIED, flags, ip_literal, canonical_name, | 282 ADDRESS_FAMILY_UNSPECIFIED, flags, ip_literal, canonical_name, |
278 0); | 283 0); |
279 rules_.push_back(rule); | 284 rules_.push_back(rule); |
280 } | 285 } |
281 | 286 |
282 void RuleBasedHostResolverProc::AddRuleWithLatency( | 287 void RuleBasedHostResolverProc::AddRuleWithLatency( |
283 const std::string& host_pattern, | 288 const std::string& host_pattern, |
284 const std::string& replacement, | 289 const std::string& replacement, |
285 int latency_ms) { | 290 int latency_ms) { |
286 DCHECK(!replacement.empty()); | 291 DCHECK(!replacement.empty()); |
287 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | | 292 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
288 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 293 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
289 Rule rule(Rule::kResolverTypeSystem, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, | 294 Rule rule(Rule::kResolverTypeSystem, |
290 flags, replacement, "", latency_ms); | 295 host_pattern, |
| 296 ADDRESS_FAMILY_UNSPECIFIED, |
| 297 flags, |
| 298 replacement, |
| 299 std::string(), |
| 300 latency_ms); |
291 rules_.push_back(rule); | 301 rules_.push_back(rule); |
292 } | 302 } |
293 | 303 |
294 void RuleBasedHostResolverProc::AllowDirectLookup( | 304 void RuleBasedHostResolverProc::AllowDirectLookup( |
295 const std::string& host_pattern) { | 305 const std::string& host_pattern) { |
296 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | | 306 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
297 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 307 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
298 Rule rule(Rule::kResolverTypeSystem, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, | 308 Rule rule(Rule::kResolverTypeSystem, |
299 flags, "", "", 0); | 309 host_pattern, |
| 310 ADDRESS_FAMILY_UNSPECIFIED, |
| 311 flags, |
| 312 std::string(), |
| 313 std::string(), |
| 314 0); |
300 rules_.push_back(rule); | 315 rules_.push_back(rule); |
301 } | 316 } |
302 | 317 |
303 void RuleBasedHostResolverProc::AddSimulatedFailure( | 318 void RuleBasedHostResolverProc::AddSimulatedFailure( |
304 const std::string& host_pattern) { | 319 const std::string& host_pattern) { |
305 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | | 320 HostResolverFlags flags = HOST_RESOLVER_LOOPBACK_ONLY | |
306 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 321 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
307 Rule rule(Rule::kResolverTypeFail, host_pattern, ADDRESS_FAMILY_UNSPECIFIED, | 322 Rule rule(Rule::kResolverTypeFail, |
308 flags, "", "", 0); | 323 host_pattern, |
| 324 ADDRESS_FAMILY_UNSPECIFIED, |
| 325 flags, |
| 326 std::string(), |
| 327 std::string(), |
| 328 0); |
309 rules_.push_back(rule); | 329 rules_.push_back(rule); |
310 } | 330 } |
311 | 331 |
312 void RuleBasedHostResolverProc::ClearRules() { | 332 void RuleBasedHostResolverProc::ClearRules() { |
313 rules_.clear(); | 333 rules_.clear(); |
314 } | 334 } |
315 | 335 |
316 int RuleBasedHostResolverProc::Resolve(const std::string& host, | 336 int RuleBasedHostResolverProc::Resolve(const std::string& host, |
317 AddressFamily address_family, | 337 AddressFamily address_family, |
318 HostResolverFlags host_resolver_flags, | 338 HostResolverFlags host_resolver_flags, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 CHECK_EQ(old_proc, current_proc_); | 428 CHECK_EQ(old_proc, current_proc_); |
409 } | 429 } |
410 | 430 |
411 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 431 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
412 current_proc_ = proc; | 432 current_proc_ = proc; |
413 previous_proc_ = HostResolverProc::SetDefault(current_proc_); | 433 previous_proc_ = HostResolverProc::SetDefault(current_proc_); |
414 current_proc_->SetLastProc(previous_proc_); | 434 current_proc_->SetLastProc(previous_proc_); |
415 } | 435 } |
416 | 436 |
417 } // namespace net | 437 } // namespace net |
OLD | NEW |