| 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/host_resolver_impl.h" | 5 #include "net/dns/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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 const BoundNetLog& job_net_log) | 555 const BoundNetLog& job_net_log) |
| 556 : key_(key), | 556 : key_(key), |
| 557 params_(params), | 557 params_(params), |
| 558 callback_(callback), | 558 callback_(callback), |
| 559 origin_loop_(base::MessageLoopProxy::current()), | 559 origin_loop_(base::MessageLoopProxy::current()), |
| 560 attempt_number_(0), | 560 attempt_number_(0), |
| 561 completed_attempt_number_(0), | 561 completed_attempt_number_(0), |
| 562 completed_attempt_error_(ERR_UNEXPECTED), | 562 completed_attempt_error_(ERR_UNEXPECTED), |
| 563 had_non_speculative_request_(false), | 563 had_non_speculative_request_(false), |
| 564 net_log_(job_net_log) { | 564 net_log_(job_net_log) { |
| 565 if (!params_.resolver_proc) | 565 if (!params_.resolver_proc.get()) |
| 566 params_.resolver_proc = HostResolverProc::GetDefault(); | 566 params_.resolver_proc = HostResolverProc::GetDefault(); |
| 567 // If default is unset, use the system proc. | 567 // If default is unset, use the system proc. |
| 568 if (!params_.resolver_proc) | 568 if (!params_.resolver_proc.get()) |
| 569 params_.resolver_proc = new SystemHostResolverProc(); | 569 params_.resolver_proc = new SystemHostResolverProc(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void Start() { | 572 void Start() { |
| 573 DCHECK(origin_loop_->BelongsToCurrentThread()); | 573 DCHECK(origin_loop_->BelongsToCurrentThread()); |
| 574 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK); | 574 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK); |
| 575 StartLookupAttempt(); | 575 StartLookupAttempt(); |
| 576 } | 576 } |
| 577 | 577 |
| 578 // Cancels this ProcTask. It will be orphaned. Any outstanding resolve | 578 // Cancels this ProcTask. It will be orphaned. Any outstanding resolve |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1253 |
| 1254 net_log_.AddEvent( | 1254 net_log_.AddEvent( |
| 1255 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, | 1255 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, |
| 1256 base::Bind(&NetLogJobAttachCallback, | 1256 base::Bind(&NetLogJobAttachCallback, |
| 1257 req->request_net_log().source(), | 1257 req->request_net_log().source(), |
| 1258 priority())); | 1258 priority())); |
| 1259 | 1259 |
| 1260 // TODO(szym): Check if this is still needed. | 1260 // TODO(szym): Check if this is still needed. |
| 1261 if (!req->info().is_speculative()) { | 1261 if (!req->info().is_speculative()) { |
| 1262 had_non_speculative_request_ = true; | 1262 had_non_speculative_request_ = true; |
| 1263 if (proc_task_) | 1263 if (proc_task_.get()) |
| 1264 proc_task_->set_had_non_speculative_request(); | 1264 proc_task_->set_had_non_speculative_request(); |
| 1265 } | 1265 } |
| 1266 | 1266 |
| 1267 requests_.push_back(req.release()); | 1267 requests_.push_back(req.release()); |
| 1268 | 1268 |
| 1269 UpdatePriority(); | 1269 UpdatePriority(); |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 // Marks |req| as cancelled. If it was the last active Request, also finishes | 1272 // Marks |req| as cancelled. If it was the last active Request, also finishes |
| 1273 // this Job, marking it as cancelled, and deletes it. | 1273 // this Job, marking it as cancelled, and deletes it. |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 // |this| may be deleted inside AbortAllInProgressJobs(). | 2195 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2196 if (self) | 2196 if (self) |
| 2197 TryServingAllJobsFromHosts(); | 2197 TryServingAllJobsFromHosts(); |
| 2198 } | 2198 } |
| 2199 | 2199 |
| 2200 bool HostResolverImpl::HaveDnsConfig() const { | 2200 bool HostResolverImpl::HaveDnsConfig() const { |
| 2201 // Use DnsClient only if it's fully configured and there is no override by | 2201 // Use DnsClient only if it's fully configured and there is no override by |
| 2202 // ScopedDefaultHostResolverProc. | 2202 // ScopedDefaultHostResolverProc. |
| 2203 // The alternative is to use NetworkChangeNotifier to override DnsConfig, | 2203 // The alternative is to use NetworkChangeNotifier to override DnsConfig, |
| 2204 // but that would introduce construction order requirements for NCN and SDHRP. | 2204 // but that would introduce construction order requirements for NCN and SDHRP. |
| 2205 return (dns_client_.get() != NULL) && | 2205 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL) && |
| 2206 (dns_client_->GetConfig() != NULL) && | 2206 !(proc_params_.resolver_proc.get() == NULL && |
| 2207 !(proc_params_.resolver_proc == NULL && | |
| 2208 HostResolverProc::GetDefault() != NULL); | 2207 HostResolverProc::GetDefault() != NULL); |
| 2209 } | 2208 } |
| 2210 | 2209 |
| 2211 void HostResolverImpl::OnDnsTaskResolve(int net_error) { | 2210 void HostResolverImpl::OnDnsTaskResolve(int net_error) { |
| 2212 DCHECK(dns_client_); | 2211 DCHECK(dns_client_); |
| 2213 if (net_error == OK) { | 2212 if (net_error == OK) { |
| 2214 num_dns_failures_ = 0; | 2213 num_dns_failures_ = 0; |
| 2215 return; | 2214 return; |
| 2216 } | 2215 } |
| 2217 ++num_dns_failures_; | 2216 ++num_dns_failures_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2239 } | 2238 } |
| 2240 DnsConfig dns_config; | 2239 DnsConfig dns_config; |
| 2241 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2240 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2242 dns_client_->SetConfig(dns_config); | 2241 dns_client_->SetConfig(dns_config); |
| 2243 num_dns_failures_ = 0; | 2242 num_dns_failures_ = 0; |
| 2244 if (dns_config.IsValid()) | 2243 if (dns_config.IsValid()) |
| 2245 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2244 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2246 } | 2245 } |
| 2247 | 2246 |
| 2248 } // namespace net | 2247 } // namespace net |
| OLD | NEW |