| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 int RuleBasedHostResolverProc::Resolve(const std::string& host, | 340 int RuleBasedHostResolverProc::Resolve(const std::string& host, |
| 341 AddressFamily address_family, | 341 AddressFamily address_family, |
| 342 HostResolverFlags host_resolver_flags, | 342 HostResolverFlags host_resolver_flags, |
| 343 AddressList* addrlist, | 343 AddressList* addrlist, |
| 344 int* os_error) { | 344 int* os_error) { |
| 345 RuleList::iterator r; | 345 RuleList::iterator r; |
| 346 for (r = rules_.begin(); r != rules_.end(); ++r) { | 346 for (r = rules_.begin(); r != rules_.end(); ++r) { |
| 347 bool matches_address_family = | 347 bool matches_address_family = |
| 348 r->address_family == ADDRESS_FAMILY_UNSPECIFIED || | 348 r->address_family == ADDRESS_FAMILY_UNSPECIFIED || |
| 349 r->address_family == address_family; | 349 r->address_family == address_family; |
| 350 // Ignore HOST_RESOLVER_SYSTEM_ONLY, since it should have no impact on |
| 351 // whether a rule matches. |
| 352 HostResolverFlags flags = host_resolver_flags & ~HOST_RESOLVER_SYSTEM_ONLY; |
| 350 // Flags match if all of the bitflags in host_resolver_flags are enabled | 353 // Flags match if all of the bitflags in host_resolver_flags are enabled |
| 351 // in the rule's host_resolver_flags. However, the rule may have additional | 354 // in the rule's host_resolver_flags. However, the rule may have additional |
| 352 // flags specified, in which case the flags should still be considered a | 355 // flags specified, in which case the flags should still be considered a |
| 353 // match. | 356 // match. |
| 354 bool matches_flags = (r->host_resolver_flags & host_resolver_flags) == | 357 bool matches_flags = (r->host_resolver_flags & flags) == flags; |
| 355 host_resolver_flags; | |
| 356 if (matches_flags && matches_address_family && | 358 if (matches_flags && matches_address_family && |
| 357 MatchPattern(host, r->host_pattern)) { | 359 MatchPattern(host, r->host_pattern)) { |
| 358 if (r->latency_ms != 0) { | 360 if (r->latency_ms != 0) { |
| 359 base::PlatformThread::Sleep( | 361 base::PlatformThread::Sleep( |
| 360 base::TimeDelta::FromMilliseconds(r->latency_ms)); | 362 base::TimeDelta::FromMilliseconds(r->latency_ms)); |
| 361 } | 363 } |
| 362 | 364 |
| 363 // Remap to a new host. | 365 // Remap to a new host. |
| 364 const std::string& effective_host = | 366 const std::string& effective_host = |
| 365 r->replacement.empty() ? host : r->replacement; | 367 r->replacement.empty() ? host : r->replacement; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 CHECK_EQ(old_proc, current_proc_); | 436 CHECK_EQ(old_proc, current_proc_); |
| 435 } | 437 } |
| 436 | 438 |
| 437 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 439 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
| 438 current_proc_ = proc; | 440 current_proc_ = proc; |
| 439 previous_proc_ = HostResolverProc::SetDefault(current_proc_.get()); | 441 previous_proc_ = HostResolverProc::SetDefault(current_proc_.get()); |
| 440 current_proc_->SetLastProc(previous_proc_.get()); | 442 current_proc_->SetLastProc(previous_proc_.get()); |
| 441 } | 443 } |
| 442 | 444 |
| 443 } // namespace net | 445 } // namespace net |
| OLD | NEW |