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