| 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 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 HostResolverProc* resolver_proc, | 708 HostResolverProc* resolver_proc, |
| 709 HostCache* cache, | 709 HostCache* cache, |
| 710 size_t max_jobs) | 710 size_t max_jobs) |
| 711 : cache_(cache), | 711 : cache_(cache), |
| 712 max_jobs_(max_jobs), | 712 max_jobs_(max_jobs), |
| 713 next_request_id_(0), | 713 next_request_id_(0), |
| 714 next_job_id_(0), | 714 next_job_id_(0), |
| 715 resolver_proc_(resolver_proc), | 715 resolver_proc_(resolver_proc), |
| 716 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), | 716 default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), |
| 717 shutdown_(false), | 717 shutdown_(false), |
| 718 ipv6_probe_monitoring_(false) { | 718 ipv6_probe_monitoring_(false), |
| 719 additional_resolver_flags_(0) { |
| 719 DCHECK_GT(max_jobs, 0u); | 720 DCHECK_GT(max_jobs, 0u); |
| 720 | 721 |
| 721 // It is cumbersome to expose all of the constraints in the constructor, | 722 // It is cumbersome to expose all of the constraints in the constructor, |
| 722 // so we choose some defaults, which users can override later. | 723 // so we choose some defaults, which users can override later. |
| 723 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); | 724 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); |
| 724 | 725 |
| 725 #if defined(OS_WIN) | 726 #if defined(OS_WIN) |
| 726 EnsureWinsockInit(); | 727 EnsureWinsockInit(); |
| 727 #endif | 728 #endif |
| 729 #if defined(OS_LINUX) |
| 730 if (HaveOnlyLoopbackAddresses()) |
| 731 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
| 732 #endif |
| 728 NetworkChangeNotifier::AddObserver(this); | 733 NetworkChangeNotifier::AddObserver(this); |
| 729 } | 734 } |
| 730 | 735 |
| 731 HostResolverImpl::~HostResolverImpl() { | 736 HostResolverImpl::~HostResolverImpl() { |
| 732 // Cancel the outstanding jobs. Those jobs may contain several attached | 737 // Cancel the outstanding jobs. Those jobs may contain several attached |
| 733 // requests, which will also be cancelled. | 738 // requests, which will also be cancelled. |
| 734 DiscardIPv6ProbeJob(); | 739 DiscardIPv6ProbeJob(); |
| 735 | 740 |
| 736 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 741 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 737 it->second->Cancel(); | 742 it->second->Cancel(); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 if (cache_.get()) | 1052 if (cache_.get()) |
| 1048 cache_->clear(); | 1053 cache_->clear(); |
| 1049 if (ipv6_probe_monitoring_) { | 1054 if (ipv6_probe_monitoring_) { |
| 1050 DCHECK(!shutdown_); | 1055 DCHECK(!shutdown_); |
| 1051 if (shutdown_) | 1056 if (shutdown_) |
| 1052 return; | 1057 return; |
| 1053 DiscardIPv6ProbeJob(); | 1058 DiscardIPv6ProbeJob(); |
| 1054 ipv6_probe_job_ = new IPv6ProbeJob(this); | 1059 ipv6_probe_job_ = new IPv6ProbeJob(this); |
| 1055 ipv6_probe_job_->Start(); | 1060 ipv6_probe_job_->Start(); |
| 1056 } | 1061 } |
| 1062 #if defined(OS_LINUX) |
| 1063 if (HaveOnlyLoopbackAddresses()) { |
| 1064 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; |
| 1065 } else { |
| 1066 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; |
| 1067 } |
| 1068 #endif |
| 1057 } | 1069 } |
| 1058 | 1070 |
| 1059 void HostResolverImpl::DiscardIPv6ProbeJob() { | 1071 void HostResolverImpl::DiscardIPv6ProbeJob() { |
| 1060 if (ipv6_probe_job_.get()) { | 1072 if (ipv6_probe_job_.get()) { |
| 1061 ipv6_probe_job_->Cancel(); | 1073 ipv6_probe_job_->Cancel(); |
| 1062 ipv6_probe_job_ = NULL; | 1074 ipv6_probe_job_ = NULL; |
| 1063 } | 1075 } |
| 1064 } | 1076 } |
| 1065 | 1077 |
| 1066 void HostResolverImpl::IPv6ProbeSetDefaultAddressFamily( | 1078 void HostResolverImpl::IPv6ProbeSetDefaultAddressFamily( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 pool->MoveRequestsToJob(job); | 1129 pool->MoveRequestsToJob(job); |
| 1118 } | 1130 } |
| 1119 } | 1131 } |
| 1120 | 1132 |
| 1121 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( | 1133 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( |
| 1122 const RequestInfo& info) const { | 1134 const RequestInfo& info) const { |
| 1123 AddressFamily effective_address_family = info.address_family(); | 1135 AddressFamily effective_address_family = info.address_family(); |
| 1124 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) | 1136 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED) |
| 1125 effective_address_family = default_address_family_; | 1137 effective_address_family = default_address_family_; |
| 1126 return Key(info.hostname(), effective_address_family, | 1138 return Key(info.hostname(), effective_address_family, |
| 1127 info.host_resolver_flags()); | 1139 info.host_resolver_flags() | additional_resolver_flags_); |
| 1128 } | 1140 } |
| 1129 | 1141 |
| 1130 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { | 1142 HostResolverImpl::Job* HostResolverImpl::CreateAndStartJob(Request* req) { |
| 1131 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); | 1143 DCHECK(CanCreateJobForPool(*GetPoolForRequest(req))); |
| 1132 Key key = GetEffectiveKeyForRequest(req->info()); | 1144 Key key = GetEffectiveKeyForRequest(req->info()); |
| 1133 scoped_refptr<Job> job = new Job(next_job_id_++, this, key); | 1145 scoped_refptr<Job> job = new Job(next_job_id_++, this, key); |
| 1134 job->AddRequest(req); | 1146 job->AddRequest(req); |
| 1135 AddOutstandingJob(job); | 1147 AddOutstandingJob(job); |
| 1136 job->Start(); | 1148 job->Start(); |
| 1137 return job.get(); | 1149 return job.get(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1153 if (r == req) | 1165 if (r == req) |
| 1154 return error; | 1166 return error; |
| 1155 | 1167 |
| 1156 r->OnComplete(error, AddressList()); | 1168 r->OnComplete(error, AddressList()); |
| 1157 } | 1169 } |
| 1158 | 1170 |
| 1159 return ERR_IO_PENDING; | 1171 return ERR_IO_PENDING; |
| 1160 } | 1172 } |
| 1161 | 1173 |
| 1162 } // namespace net | 1174 } // namespace net |
| OLD | NEW |