| 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 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 probe_weak_ptr_factory_.InvalidateWeakPtrs(); | 2282 probe_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 2283 if (cache_.get()) | 2283 if (cache_.get()) |
| 2284 cache_->clear(); | 2284 cache_->clear(); |
| 2285 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 2285 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 2286 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); | 2286 new LoopbackProbeJob(probe_weak_ptr_factory_.GetWeakPtr()); |
| 2287 #endif | 2287 #endif |
| 2288 AbortAllInProgressJobs(); | 2288 AbortAllInProgressJobs(); |
| 2289 // |this| may be deleted inside AbortAllInProgressJobs(). | 2289 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2290 } | 2290 } |
| 2291 | 2291 |
| 2292 void HostResolverImpl::OnInitialDNSConfigRead() { |
| 2293 UpdateDNSConfig(false); |
| 2294 } |
| 2295 |
| 2292 void HostResolverImpl::OnDNSChanged() { | 2296 void HostResolverImpl::OnDNSChanged() { |
| 2297 UpdateDNSConfig(true); |
| 2298 } |
| 2299 |
| 2300 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { |
| 2293 DnsConfig dns_config; | 2301 DnsConfig dns_config; |
| 2294 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2302 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2295 | 2303 |
| 2296 if (net_log_) { | 2304 if (net_log_) { |
| 2297 net_log_->AddGlobalEntry( | 2305 net_log_->AddGlobalEntry( |
| 2298 NetLog::TYPE_DNS_CONFIG_CHANGED, | 2306 NetLog::TYPE_DNS_CONFIG_CHANGED, |
| 2299 base::Bind(&NetLogDnsConfigCallback, &dns_config)); | 2307 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
| 2300 } | 2308 } |
| 2301 | 2309 |
| 2302 // TODO(szym): Remove once http://crbug.com/137914 is resolved. | 2310 // TODO(szym): Remove once http://crbug.com/137914 is resolved. |
| 2303 received_dns_config_ = dns_config.IsValid(); | 2311 received_dns_config_ = dns_config.IsValid(); |
| 2304 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. | 2312 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. |
| 2305 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; | 2313 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; |
| 2306 | 2314 |
| 2307 num_dns_failures_ = 0; | 2315 num_dns_failures_ = 0; |
| 2308 | 2316 |
| 2309 // We want a new DnsSession in place, before we Abort running Jobs, so that | 2317 // We want a new DnsSession in place, before we Abort running Jobs, so that |
| 2310 // the newly started jobs use the new config. | 2318 // the newly started jobs use the new config. |
| 2311 if (dns_client_.get()) { | 2319 if (dns_client_.get()) { |
| 2312 dns_client_->SetConfig(dns_config); | 2320 dns_client_->SetConfig(dns_config); |
| 2313 if (dns_client_->GetConfig()) | 2321 if (dns_client_->GetConfig()) { |
| 2314 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2322 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2323 // If we just switched DnsClients, restart jobs using new resolver. |
| 2324 // TODO(pauljensen): Is this necessary? |
| 2325 config_changed = true; |
| 2326 } |
| 2315 } | 2327 } |
| 2316 | 2328 |
| 2317 // If the DNS server has changed, existing cached info could be wrong so we | 2329 if (config_changed) { |
| 2318 // have to drop our internal cache :( Note that OS level DNS caches, such | 2330 // If the DNS server has changed, existing cached info could be wrong so we |
| 2319 // as NSCD's cache should be dropped automatically by the OS when | 2331 // have to drop our internal cache :( Note that OS level DNS caches, such |
| 2320 // resolv.conf changes so we don't need to do anything to clear that cache. | 2332 // as NSCD's cache should be dropped automatically by the OS when |
| 2321 if (cache_.get()) | 2333 // resolv.conf changes so we don't need to do anything to clear that cache. |
| 2322 cache_->clear(); | 2334 if (cache_.get()) |
| 2335 cache_->clear(); |
| 2323 | 2336 |
| 2324 // Life check to bail once |this| is deleted. | 2337 // Life check to bail once |this| is deleted. |
| 2325 base::WeakPtr<HostResolverImpl> self = weak_ptr_factory_.GetWeakPtr(); | 2338 base::WeakPtr<HostResolverImpl> self = weak_ptr_factory_.GetWeakPtr(); |
| 2326 | 2339 |
| 2327 // Existing jobs will have been sent to the original server so they need to | 2340 // Existing jobs will have been sent to the original server so they need to |
| 2328 // be aborted. | 2341 // be aborted. |
| 2329 AbortAllInProgressJobs(); | 2342 AbortAllInProgressJobs(); |
| 2330 | 2343 |
| 2331 // |this| may be deleted inside AbortAllInProgressJobs(). | 2344 // |this| may be deleted inside AbortAllInProgressJobs(). |
| 2332 if (self.get()) | 2345 if (self.get()) |
| 2333 TryServingAllJobsFromHosts(); | 2346 TryServingAllJobsFromHosts(); |
| 2347 } |
| 2334 } | 2348 } |
| 2335 | 2349 |
| 2336 bool HostResolverImpl::HaveDnsConfig() const { | 2350 bool HostResolverImpl::HaveDnsConfig() const { |
| 2337 // Use DnsClient only if it's fully configured and there is no override by | 2351 // Use DnsClient only if it's fully configured and there is no override by |
| 2338 // ScopedDefaultHostResolverProc. | 2352 // ScopedDefaultHostResolverProc. |
| 2339 // The alternative is to use NetworkChangeNotifier to override DnsConfig, | 2353 // The alternative is to use NetworkChangeNotifier to override DnsConfig, |
| 2340 // but that would introduce construction order requirements for NCN and SDHRP. | 2354 // but that would introduce construction order requirements for NCN and SDHRP. |
| 2341 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL) && | 2355 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL) && |
| 2342 !(proc_params_.resolver_proc.get() == NULL && | 2356 !(proc_params_.resolver_proc.get() == NULL && |
| 2343 HostResolverProc::GetDefault() != NULL); | 2357 HostResolverProc::GetDefault() != NULL); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2377 dns_client_->SetConfig(dns_config); | 2391 dns_client_->SetConfig(dns_config); |
| 2378 num_dns_failures_ = 0; | 2392 num_dns_failures_ = 0; |
| 2379 if (dns_client_->GetConfig()) | 2393 if (dns_client_->GetConfig()) |
| 2380 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2394 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
| 2381 } | 2395 } |
| 2382 | 2396 |
| 2383 AbortDnsTasks(); | 2397 AbortDnsTasks(); |
| 2384 } | 2398 } |
| 2385 | 2399 |
| 2386 } // namespace net | 2400 } // namespace net |
| OLD | NEW |