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

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

Issue 6903061: Linux: Monitor resolv.conf for changes and use that to reload resolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixups etc. Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 12 matching lines...) Expand all
23 #include "base/metrics/histogram.h" 23 #include "base/metrics/histogram.h"
24 #include "base/stl_util.h" 24 #include "base/stl_util.h"
25 #include "base/string_util.h" 25 #include "base/string_util.h"
26 #include "base/task.h" 26 #include "base/task.h"
27 #include "base/threading/worker_pool.h" 27 #include "base/threading/worker_pool.h"
28 #include "base/time.h" 28 #include "base/time.h"
29 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
30 #include "base/values.h" 30 #include "base/values.h"
31 #include "net/base/address_list.h" 31 #include "net/base/address_list.h"
32 #include "net/base/address_list_net_log_param.h" 32 #include "net/base/address_list_net_log_param.h"
33 #include "net/base/dns_reloader.h"
33 #include "net/base/host_port_pair.h" 34 #include "net/base/host_port_pair.h"
34 #include "net/base/host_resolver_proc.h" 35 #include "net/base/host_resolver_proc.h"
35 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
36 #include "net/base/net_log.h" 37 #include "net/base/net_log.h"
37 #include "net/base/net_util.h" 38 #include "net/base/net_util.h"
38 39
39 #if defined(OS_WIN) 40 #if defined(OS_WIN)
40 #include "net/base/winsock_init.h" 41 #include "net/base/winsock_init.h"
41 #endif 42 #endif
42 43
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs); 1086 job_pools_[POOL_NORMAL] = new JobPool(max_jobs, 100u * max_jobs);
1086 1087
1087 #if defined(OS_WIN) 1088 #if defined(OS_WIN)
1088 EnsureWinsockInit(); 1089 EnsureWinsockInit();
1089 #endif 1090 #endif
1090 #if defined(OS_POSIX) && !defined(OS_MACOSX) 1091 #if defined(OS_POSIX) && !defined(OS_MACOSX)
1091 if (HaveOnlyLoopbackAddresses()) 1092 if (HaveOnlyLoopbackAddresses())
1092 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 1093 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
1093 #endif 1094 #endif
1094 NetworkChangeNotifier::AddIPAddressObserver(this); 1095 NetworkChangeNotifier::AddIPAddressObserver(this);
1096 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
1097 EnsureDnsReloaderInit();
1098 NetworkChangeNotifier::AddDNSObserver(this);
1099 #endif
1095 } 1100 }
1096 1101
1097 HostResolverImpl::~HostResolverImpl() { 1102 HostResolverImpl::~HostResolverImpl() {
1098 // Cancel the outstanding jobs. Those jobs may contain several attached 1103 // Cancel the outstanding jobs. Those jobs may contain several attached
1099 // requests, which will also be cancelled. 1104 // requests, which will also be cancelled.
1100 DiscardIPv6ProbeJob(); 1105 DiscardIPv6ProbeJob();
1101 1106
1102 CancelAllJobs(); 1107 CancelAllJobs();
1103 1108
1104 // In case we are being deleted during the processing of a callback. 1109 // In case we are being deleted during the processing of a callback.
1105 if (cur_completing_job_) 1110 if (cur_completing_job_)
1106 cur_completing_job_->Cancel(); 1111 cur_completing_job_->Cancel();
1107 1112
1108 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1113 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1114 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
1115 NetworkChangeNotifier::RemoveDNSObserver(this);
1116 #endif
1109 1117
1110 // Delete the job pools. 1118 // Delete the job pools.
1111 for (size_t i = 0u; i < arraysize(job_pools_); ++i) 1119 for (size_t i = 0u; i < arraysize(job_pools_); ++i)
1112 delete job_pools_[i]; 1120 delete job_pools_[i];
1113 } 1121 }
1114 1122
1115 void HostResolverImpl::ProbeIPv6Support() { 1123 void HostResolverImpl::ProbeIPv6Support() {
1116 DCHECK(CalledOnValidThread()); 1124 DCHECK(CalledOnValidThread());
1117 DCHECK(!ipv6_probe_monitoring_); 1125 DCHECK(!ipv6_probe_monitoring_);
1118 ipv6_probe_monitoring_ = true; 1126 ipv6_probe_monitoring_ = true;
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 if (HaveOnlyLoopbackAddresses()) { 1612 if (HaveOnlyLoopbackAddresses()) {
1605 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY; 1613 additional_resolver_flags_ |= HOST_RESOLVER_LOOPBACK_ONLY;
1606 } else { 1614 } else {
1607 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 1615 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
1608 } 1616 }
1609 #endif 1617 #endif
1610 AbortAllInProgressJobs(); 1618 AbortAllInProgressJobs();
1611 // |this| may be deleted inside AbortAllInProgressJobs(). 1619 // |this| may be deleted inside AbortAllInProgressJobs().
1612 } 1620 }
1613 1621
1622 void HostResolverImpl::OnDNSChanged() {
1623 // If the DNS server has changed, existing cached info could be wrong so we
1624 // have to drop our internal cache :( Note that OS level DNS caches, such
1625 // as NSCD's cache should be dropped automatically by the OS when
1626 // resolv.conf changes so we don't need to do anything to clear that cache.
1627 if (cache_.get())
1628 cache_->clear();
1629 // Existing jobs will have been sent to the original server so they need to
1630 // be aborted. TODO(Craig): Should these jobs be restarted?
1631 AbortAllInProgressJobs();
1632 // |this| may be deleted inside AbortAllInProgressJobs().
1633 }
1634
1614 } // namespace net 1635 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698