| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/base/net_log.h" | 6 #include "net/base/net_log.h" |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <deque> | 9 #include <deque> |
| 10 | 10 |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 ipv6_probe_monitoring_(false) { | 676 ipv6_probe_monitoring_(false) { |
| 677 DCHECK_GT(max_jobs, 0u); | 677 DCHECK_GT(max_jobs, 0u); |
| 678 | 678 |
| 679 // It is cumbersome to expose all of the constraints in the constructor, | 679 // It is cumbersome to expose all of the constraints in the constructor, |
| 680 // so we choose some defaults, which users can override later. | 680 // so we choose some defaults, which users can override later. |
| 681 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 681 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
| 682 | 682 |
| 683 #if defined(OS_WIN) | 683 #if defined(OS_WIN) |
| 684 EnsureWinsockInit(); | 684 EnsureWinsockInit(); |
| 685 #endif | 685 #endif |
| 686 if (network_change_notifier_) |
| 687 network_change_notifier_->AddObserver(this); |
| 686 } | 688 } |
| 687 | 689 |
| 688 HostResolverImpl::~HostResolverImpl() { | 690 HostResolverImpl::~HostResolverImpl() { |
| 689 // Cancel the outstanding jobs. Those jobs may contain several attached | 691 // Cancel the outstanding jobs. Those jobs may contain several attached |
| 690 // requests, which will also be cancelled. | 692 // requests, which will also be cancelled. |
| 691 DiscardIPv6ProbeJob(); | 693 DiscardIPv6ProbeJob(); |
| 692 | 694 |
| 693 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 695 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 694 it->second->Cancel(); | 696 it->second->Cancel(); |
| 695 | 697 |
| 696 // In case we are being deleted during the processing of a callback. | 698 // In case we are being deleted during the processing of a callback. |
| 697 if (cur_completing_job_) | 699 if (cur_completing_job_) |
| 698 cur_completing_job_->Cancel(); | 700 cur_completing_job_->Cancel(); |
| 699 | 701 |
| 702 if (network_change_notifier_) |
| 703 network_change_notifier_->RemoveObserver(this); |
| 704 |
| 700 // Delete the job pools. | 705 // Delete the job pools. |
| 701 for (size_t i = 0u; i < arraysize(job_pools_); ++i) | 706 for (size_t i = 0u; i < arraysize(job_pools_); ++i) |
| 702 delete job_pools_[i]; | 707 delete job_pools_[i]; |
| 703 } | 708 } |
| 704 | 709 |
| 705 // TODO(eroman): Don't create cache entries for hostnames which are simply IP | 710 // TODO(eroman): Don't create cache entries for hostnames which are simply IP |
| 706 // address literals. | 711 // address literals. |
| 707 int HostResolverImpl::Resolve(const RequestInfo& info, | 712 int HostResolverImpl::Resolve(const RequestInfo& info, |
| 708 AddressList* addresses, | 713 AddressList* addresses, |
| 709 CompletionCallback* callback, | 714 CompletionCallback* callback, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 | 839 |
| 835 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { | 840 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { |
| 836 ipv6_probe_monitoring_ = false; | 841 ipv6_probe_monitoring_ = false; |
| 837 DiscardIPv6ProbeJob(); | 842 DiscardIPv6ProbeJob(); |
| 838 default_address_family_ = address_family; | 843 default_address_family_ = address_family; |
| 839 } | 844 } |
| 840 | 845 |
| 841 void HostResolverImpl::ProbeIPv6Support() { | 846 void HostResolverImpl::ProbeIPv6Support() { |
| 842 DCHECK(!ipv6_probe_monitoring_); | 847 DCHECK(!ipv6_probe_monitoring_); |
| 843 ipv6_probe_monitoring_ = true; | 848 ipv6_probe_monitoring_ = true; |
| 844 Flush(); // Give initial setup call. | 849 OnIPAddressChanged(); // Give initial setup call. |
| 845 } | 850 } |
| 846 | 851 |
| 847 void HostResolverImpl::Shutdown() { | 852 void HostResolverImpl::Shutdown() { |
| 848 shutdown_ = true; | 853 shutdown_ = true; |
| 849 | 854 |
| 850 // Cancel the outstanding jobs. | 855 // Cancel the outstanding jobs. |
| 851 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 856 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 852 it->second->Cancel(); | 857 it->second->Cancel(); |
| 853 jobs_.clear(); | 858 jobs_.clear(); |
| 854 } | 859 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 it != observers_.end(); ++it) { | 1072 it != observers_.end(); ++it) { |
| 1068 (*it)->OnCancelResolution(request_id, info); | 1073 (*it)->OnCancelResolution(request_id, info); |
| 1069 } | 1074 } |
| 1070 | 1075 |
| 1071 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); | 1076 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONCANCEL); |
| 1072 } | 1077 } |
| 1073 | 1078 |
| 1074 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); | 1079 net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); |
| 1075 } | 1080 } |
| 1076 | 1081 |
| 1077 void HostResolverImpl::Flush() { | 1082 void HostResolverImpl::OnIPAddressChanged() { |
| 1078 if (cache_.get()) | 1083 if (cache_.get()) |
| 1079 cache_->clear(); | 1084 cache_->clear(); |
| 1080 if (ipv6_probe_monitoring_) { | 1085 if (ipv6_probe_monitoring_) { |
| 1081 DiscardIPv6ProbeJob(); | 1086 DiscardIPv6ProbeJob(); |
| 1082 ipv6_probe_job_ = new IPv6ProbeJob(this); | 1087 ipv6_probe_job_ = new IPv6ProbeJob(this); |
| 1083 ipv6_probe_job_->Start(); | 1088 ipv6_probe_job_->Start(); |
| 1084 } | 1089 } |
| 1085 } | 1090 } |
| 1086 | 1091 |
| 1087 void HostResolverImpl::DiscardIPv6ProbeJob() { | 1092 void HostResolverImpl::DiscardIPv6ProbeJob() { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 if (r == req) | 1190 if (r == req) |
| 1186 return error; | 1191 return error; |
| 1187 | 1192 |
| 1188 r->OnComplete(error, AddressList()); | 1193 r->OnComplete(error, AddressList()); |
| 1189 } | 1194 } |
| 1190 | 1195 |
| 1191 return ERR_IO_PENDING; | 1196 return ERR_IO_PENDING; |
| 1192 } | 1197 } |
| 1193 | 1198 |
| 1194 } // namespace net | 1199 } // namespace net |
| OLD | NEW |