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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/pattern.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
18 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
19 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" |
20 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
21 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
22 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
23 #include "net/dns/host_cache.h" | 24 #include "net/dns/host_cache.h" |
24 | 25 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 r->address_family == address_family; | 359 r->address_family == address_family; |
359 // Ignore HOST_RESOLVER_SYSTEM_ONLY, since it should have no impact on | 360 // Ignore HOST_RESOLVER_SYSTEM_ONLY, since it should have no impact on |
360 // whether a rule matches. | 361 // whether a rule matches. |
361 HostResolverFlags flags = host_resolver_flags & ~HOST_RESOLVER_SYSTEM_ONLY; | 362 HostResolverFlags flags = host_resolver_flags & ~HOST_RESOLVER_SYSTEM_ONLY; |
362 // Flags match if all of the bitflags in host_resolver_flags are enabled | 363 // Flags match if all of the bitflags in host_resolver_flags are enabled |
363 // in the rule's host_resolver_flags. However, the rule may have additional | 364 // in the rule's host_resolver_flags. However, the rule may have additional |
364 // flags specified, in which case the flags should still be considered a | 365 // flags specified, in which case the flags should still be considered a |
365 // match. | 366 // match. |
366 bool matches_flags = (r->host_resolver_flags & flags) == flags; | 367 bool matches_flags = (r->host_resolver_flags & flags) == flags; |
367 if (matches_flags && matches_address_family && | 368 if (matches_flags && matches_address_family && |
368 MatchPattern(host, r->host_pattern)) { | 369 base::MatchPattern(host, r->host_pattern)) { |
369 if (r->latency_ms != 0) { | 370 if (r->latency_ms != 0) { |
370 base::PlatformThread::Sleep( | 371 base::PlatformThread::Sleep( |
371 base::TimeDelta::FromMilliseconds(r->latency_ms)); | 372 base::TimeDelta::FromMilliseconds(r->latency_ms)); |
372 } | 373 } |
373 | 374 |
374 // Remap to a new host. | 375 // Remap to a new host. |
375 const std::string& effective_host = | 376 const std::string& effective_host = |
376 r->replacement.empty() ? host : r->replacement; | 377 r->replacement.empty() ? host : r->replacement; |
377 | 378 |
378 // Apply the resolving function to the remapped hostname. | 379 // Apply the resolving function to the remapped hostname. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 CHECK_EQ(old_proc, current_proc_.get()); | 446 CHECK_EQ(old_proc, current_proc_.get()); |
446 } | 447 } |
447 | 448 |
448 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { | 449 void ScopedDefaultHostResolverProc::Init(HostResolverProc* proc) { |
449 current_proc_ = proc; | 450 current_proc_ = proc; |
450 previous_proc_ = HostResolverProc::SetDefault(current_proc_.get()); | 451 previous_proc_ = HostResolverProc::SetDefault(current_proc_.get()); |
451 current_proc_->SetLastProc(previous_proc_.get()); | 452 current_proc_->SetLastProc(previous_proc_.get()); |
452 } | 453 } |
453 | 454 |
454 } // namespace net | 455 } // namespace net |
OLD | NEW |