| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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 <cmath> | 7 #include <cmath> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug_util.h" | 12 #include "base/debug_util.h" |
| 13 #include "base/lock.h" | 13 #include "base/lock.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/worker_pool.h" | 18 #include "base/worker_pool.h" |
| 19 #include "net/base/address_list.h" | 19 #include "net/base/address_list.h" |
| 20 #include "net/base/host_resolver_proc.h" | 20 #include "net/base/host_resolver_proc.h" |
| 21 #include "net/base/load_log.h" | 21 #include "net/base/load_log.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/net_util.h" | |
| 24 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
| 25 | 24 |
| 26 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 27 #include "net/base/winsock_init.h" | 26 #include "net/base/winsock_init.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace net { | 29 namespace net { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 HostCache* cache, | 568 HostCache* cache, |
| 570 NetworkChangeNotifier* network_change_notifier, | 569 NetworkChangeNotifier* network_change_notifier, |
| 571 size_t max_jobs) | 570 size_t max_jobs) |
| 572 : cache_(cache), | 571 : cache_(cache), |
| 573 max_jobs_(max_jobs), | 572 max_jobs_(max_jobs), |
| 574 next_request_id_(0), | 573 next_request_id_(0), |
| 575 next_job_id_(0), | 574 next_job_id_(0), |
| 576 resolver_proc_(resolver_proc), | 575 resolver_proc_(resolver_proc), |
| 577 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 576 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 578 shutdown_(false), | 577 shutdown_(false), |
| 579 network_change_notifier_(network_change_notifier), | 578 network_change_notifier_(network_change_notifier) { |
| 580 ipv6_probe_monitoring_(false) { | |
| 581 DCHECK_GT(max_jobs, 0u); | 579 DCHECK_GT(max_jobs, 0u); |
| 582 | 580 |
| 583 // It is cumbersome to expose all of the constraints in the constructor, | 581 // It is cumbersome to expose all of the constraints in the constructor, |
| 584 // so we choose some defaults, which users can override later. | 582 // so we choose some defaults, which users can override later. |
| 585 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 583 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
| 586 | 584 |
| 587 #if defined(OS_WIN) | 585 #if defined(OS_WIN) |
| 588 EnsureWinsockInit(); | 586 EnsureWinsockInit(); |
| 589 #endif | 587 #endif |
| 590 if (network_change_notifier_) | 588 if (network_change_notifier_) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 void HostResolverImpl::RemoveObserver(HostResolver::Observer* observer) { | 729 void HostResolverImpl::RemoveObserver(HostResolver::Observer* observer) { |
| 732 ObserversList::iterator it = | 730 ObserversList::iterator it = |
| 733 std::find(observers_.begin(), observers_.end(), observer); | 731 std::find(observers_.begin(), observers_.end(), observer); |
| 734 | 732 |
| 735 // Observer must exist. | 733 // Observer must exist. |
| 736 DCHECK(it != observers_.end()); | 734 DCHECK(it != observers_.end()); |
| 737 | 735 |
| 738 observers_.erase(it); | 736 observers_.erase(it); |
| 739 } | 737 } |
| 740 | 738 |
| 741 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { | |
| 742 ipv6_probe_monitoring_ = false; | |
| 743 default_address_family_ = address_family; | |
| 744 } | |
| 745 | |
| 746 void HostResolverImpl::ProbeIPv6Support() { | |
| 747 DCHECK(!ipv6_probe_monitoring_); | |
| 748 ipv6_probe_monitoring_ = true; | |
| 749 OnIPAddressChanged(); // Give initial setup call. | |
| 750 } | |
| 751 | |
| 752 void HostResolverImpl::Shutdown() { | 739 void HostResolverImpl::Shutdown() { |
| 753 shutdown_ = true; | 740 shutdown_ = true; |
| 754 | 741 |
| 755 // Cancel the outstanding jobs. | 742 // Cancel the outstanding jobs. |
| 756 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 743 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 757 it->second->Cancel(); | 744 it->second->Cancel(); |
| 758 jobs_.clear(); | 745 jobs_.clear(); |
| 759 } | 746 } |
| 760 | 747 |
| 761 void HostResolverImpl::ClearRequestsTrace() { | 748 void HostResolverImpl::ClearRequestsTrace() { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 LoadLog::EndEvent( | 970 LoadLog::EndEvent( |
| 984 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 971 load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
| 985 } | 972 } |
| 986 | 973 |
| 987 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); | 974 LoadLog::EndEvent(load_log, LoadLog::TYPE_HOST_RESOLVER_IMPL); |
| 988 } | 975 } |
| 989 | 976 |
| 990 void HostResolverImpl::OnIPAddressChanged() { | 977 void HostResolverImpl::OnIPAddressChanged() { |
| 991 if (cache_.get()) | 978 if (cache_.get()) |
| 992 cache_->clear(); | 979 cache_->clear(); |
| 993 if (ipv6_probe_monitoring_) { | |
| 994 bool support = IPv6Supported(); | |
| 995 default_address_family_ = support ? ADDRESS_FAMILY_UNSPECIFIED | |
| 996 : ADDRESS_FAMILY_IPV4; | |
| 997 LOG(INFO) << "IPv6Probe forced AddressFamily setting to " | |
| 998 << (support ? "ADDRESS_FAMILY_UNSPECIFIED" | |
| 999 : "ADDRESS_FAMILY_IPV4"); | |
| 1000 } | |
| 1001 } | 980 } |
| 1002 | 981 |
| 1003 // static | 982 // static |
| 1004 HostResolverImpl::JobPoolIndex HostResolverImpl::GetJobPoolIndexForRequest( | 983 HostResolverImpl::JobPoolIndex HostResolverImpl::GetJobPoolIndexForRequest( |
| 1005 const Request* req) { | 984 const Request* req) { |
| 1006 return POOL_NORMAL; | 985 return POOL_NORMAL; |
| 1007 } | 986 } |
| 1008 | 987 |
| 1009 bool HostResolverImpl::CanCreateJobForPool(const JobPool& pool) const { | 988 bool HostResolverImpl::CanCreateJobForPool(const JobPool& pool) const { |
| 1010 DCHECK_LE(jobs_.size(), max_jobs_); | 989 DCHECK_LE(jobs_.size(), max_jobs_); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 if (r == req) | 1057 if (r == req) |
| 1079 return error; | 1058 return error; |
| 1080 | 1059 |
| 1081 r->OnComplete(error, AddressList()); | 1060 r->OnComplete(error, AddressList()); |
| 1082 } | 1061 } |
| 1083 | 1062 |
| 1084 return ERR_IO_PENDING; | 1063 return ERR_IO_PENDING; |
| 1085 } | 1064 } |
| 1086 | 1065 |
| 1087 } // namespace net | 1066 } // namespace net |
| OLD | NEW |