Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 10830271: [net] Use only DnsConfigService to detect DNS changes in HostResolverImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/host_resolver_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 #if defined(OS_WIN) 1595 #if defined(OS_WIN)
1596 EnsureWinsockInit(); 1596 EnsureWinsockInit();
1597 #endif 1597 #endif
1598 #if defined(OS_POSIX) && !defined(OS_MACOSX) 1598 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1599 if (HaveOnlyLoopbackAddresses()) 1599 if (HaveOnlyLoopbackAddresses())
1600 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 1600 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
1601 #endif 1601 #endif
1602 NetworkChangeNotifier::AddIPAddressObserver(this); 1602 NetworkChangeNotifier::AddIPAddressObserver(this);
1603 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \ 1603 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && \
1604 !defined(OS_ANDROID) 1604 !defined(OS_ANDROID)
1605 NetworkChangeNotifier::AddDNSObserver(this);
1606 EnsureDnsReloaderInit(); 1605 EnsureDnsReloaderInit();
1607 #endif 1606 #endif
1608 1607
1609 if (dns_config_service_.get()) { 1608 if (dns_config_service_.get()) {
1610 dns_config_service_->Watch( 1609 dns_config_service_->Watch(
1611 base::Bind(&HostResolverImpl::OnDnsConfigChanged, 1610 base::Bind(&HostResolverImpl::OnDnsConfigChanged,
1612 base::Unretained(this))); 1611 base::Unretained(this)));
1613 } 1612 }
1614 } 1613 }
1615 1614
1616 HostResolverImpl::~HostResolverImpl() { 1615 HostResolverImpl::~HostResolverImpl() {
1617 DiscardIPv6ProbeJob(); 1616 DiscardIPv6ProbeJob();
1618 1617
1619 // This will also cancel all outstanding requests. 1618 // This will also cancel all outstanding requests.
1620 STLDeleteValues(&jobs_); 1619 STLDeleteValues(&jobs_);
1621 1620
1622 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1621 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1623 NetworkChangeNotifier::RemoveDNSObserver(this);
1624 } 1622 }
1625 1623
1626 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { 1624 void HostResolverImpl::SetMaxQueuedJobs(size_t value) {
1627 DCHECK_EQ(0u, dispatcher_.num_queued_jobs()); 1625 DCHECK_EQ(0u, dispatcher_.num_queued_jobs());
1628 DCHECK_GT(value, 0u); 1626 DCHECK_GT(value, 0u);
1629 max_queued_jobs_ = value; 1627 max_queued_jobs_ = value;
1630 } 1628 }
1631 1629
1632 int HostResolverImpl::Resolve(const RequestInfo& info, 1630 int HostResolverImpl::Resolve(const RequestInfo& info,
1633 AddressList* addresses, 1631 AddressList* addresses,
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 if (HaveOnlyLoopbackAddresses()) { 1974 if (HaveOnlyLoopbackAddresses()) {
1977 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 1975 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
1978 } else { 1976 } else {
1979 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 1977 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
1980 } 1978 }
1981 #endif 1979 #endif
1982 AbortAllInProgressJobs(); 1980 AbortAllInProgressJobs();
1983 // |this| may be deleted inside AbortAllInProgressJobs(). 1981 // |this| may be deleted inside AbortAllInProgressJobs().
1984 } 1982 }
1985 1983
1986 void HostResolverImpl::OnDNSChanged(unsigned detail) {
1987 // Ignore signals about watches.
1988 const unsigned kIgnoredDetail =
1989 NetworkChangeNotifier::CHANGE_DNS_WATCH_STARTED |
1990 NetworkChangeNotifier::CHANGE_DNS_WATCH_FAILED;
1991 if ((detail & ~kIgnoredDetail) == 0)
1992 return;
1993 // If the DNS server has changed, existing cached info could be wrong so we
1994 // have to drop our internal cache :( Note that OS level DNS caches, such
1995 // as NSCD's cache should be dropped automatically by the OS when
1996 // resolv.conf changes so we don't need to do anything to clear that cache.
1997 if (cache_.get())
1998 cache_->clear();
1999 // Existing jobs will have been sent to the original server so they need to
2000 // be aborted.
2001 AbortAllInProgressJobs();
2002 // |this| may be deleted inside AbortAllInProgressJobs().
2003 }
2004
2005 void HostResolverImpl::OnDnsConfigChanged(const DnsConfig& dns_config) { 1984 void HostResolverImpl::OnDnsConfigChanged(const DnsConfig& dns_config) {
2006 if (net_log_) { 1985 if (net_log_) {
2007 net_log_->AddGlobalEntry( 1986 net_log_->AddGlobalEntry(
2008 NetLog::TYPE_DNS_CONFIG_CHANGED, 1987 NetLog::TYPE_DNS_CONFIG_CHANGED,
2009 base::Bind(&NetLogDnsConfigCallback, &dns_config)); 1988 base::Bind(&NetLogDnsConfigCallback, &dns_config));
2010 } 1989 }
2011 1990
2012 // TODO(szym): Remove once http://crbug.com/125599 is resolved. 1991 // TODO(szym): Remove once http://crbug.com/137914 is resolved.
2013 received_dns_config_ = dns_config.IsValid(); 1992 received_dns_config_ = dns_config.IsValid();
2014 1993
2015 // Life check to bail once |this| is deleted. 1994 // Life check to bail once |this| is deleted.
2016 base::WeakPtr<HostResolverImpl> self = AsWeakPtr(); 1995 base::WeakPtr<HostResolverImpl> self = AsWeakPtr();
2017 1996
2018 if (dns_client_.get()) { 1997 // We want a new DnsSession in place, before we Abort running Jobs, so that
2019 // We want a new factory in place, before we Abort running Jobs, so that the 1998 // the newly started jobs use the new config.
2020 // newly started jobs use the new factory. 1999 if (dns_client_.get())
2021 dns_client_->SetConfig(dns_config); 2000 dns_client_->SetConfig(dns_config);
2022 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_SETTINGS); 2001
2023 // |this| may be deleted inside OnDNSChanged(). 2002 // If the DNS server has changed, existing cached info could be wrong so we
2024 if (self) 2003 // have to drop our internal cache :( Note that OS level DNS caches, such
2025 TryServingAllJobsFromHosts(); 2004 // as NSCD's cache should be dropped automatically by the OS when
2026 } 2005 // resolv.conf changes so we don't need to do anything to clear that cache.
2006 if (cache_.get())
2007 cache_->clear();
2008
2009 // Existing jobs will have been sent to the original server so they need to
2010 // be aborted.
2011 AbortAllInProgressJobs();
2012
2013 // |this| may be deleted inside AbortAllInProgressJobs().
2014 if (self)
2015 TryServingAllJobsFromHosts();
2027 } 2016 }
2028 2017
2029 bool HostResolverImpl::HaveDnsConfig() const { 2018 bool HostResolverImpl::HaveDnsConfig() const {
2030 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); 2019 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL);
2031 } 2020 }
2032 2021
2033 } // namespace net 2022 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698