OLD | NEW |
---|---|
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/dns_reloader.h" | 5 #include "net/base/dns_reloader.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && !defined (OS_ANDROID) |
joth
2011/11/02 18:57:05
uh! I wonder why this isn't using a .gyp rule to e
Jing Zhao
2011/11/03 17:49:08
Done.
| |
8 | 8 |
9 #include <resolv.h> | 9 #include <resolv.h> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_local_storage.h" | 16 #include "base/threading/thread_local_storage.h" |
17 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // On Linux/BSD, changes to /etc/resolv.conf can go unnoticed thus resulting | 21 // On Linux/BSD, changes to /etc/resolv.conf can go unnoticed thus resulting |
22 // in DNS queries failing either because nameservers are unknown on startup | 22 // in DNS queries failing either because nameservers are unknown on startup |
23 // or because nameserver info has changed as a result of e.g. connecting to | 23 // or because nameserver info has changed as a result of e.g. connecting to |
24 // a new network. Some distributions patch glibc to stat /etc/resolv.conf | 24 // a new network. Some distributions patch glibc to stat /etc/resolv.conf |
25 // to try to automatically detect such changes but these patches are not | 25 // to try to automatically detect such changes but these patches are not |
26 // universal and even patched systems such as Jaunty appear to need calls | 26 // universal and even patched systems such as Jaunty appear to need calls |
27 // to res_ninit to reload the nameserver information in different threads. | 27 // to res_ninit to reload the nameserver information in different threads. |
28 // | 28 // |
29 // To fix this, on systems with FilePathWatcher support, we use | 29 // To fix this, on systems with FilePathWatcher support, we use |
30 // NetworkChangeNotifier::DNSObserver to monitor /etc/resolv.conf to | 30 // NetworkChangeNotifier::DNSObserver to monitor /etc/resolv.conf to |
31 // enable us to respond to DNS changes and reload the resolver state. | 31 // enable us to respond to DNS changes and reload the resolver state. |
32 // | 32 // |
33 // OpenBSD does not have thread-safe res_ninit/res_nclose so we can't do | 33 // OpenBSD does not have thread-safe res_ninit/res_nclose so we can't do |
34 // the same trick there and most *BSD's don't yet have support for | 34 // the same trick there and most *BSD's don't yet have support for |
35 // FilePathWatcher (but perhaps the new kqueue mac code just needs to be | 35 // FilePathWatcher (but perhaps the new kqueue mac code just needs to be |
36 // ported to *BSD to support that). | 36 // ported to *BSD to support that). |
37 | 37 |
joth
2011/11/02 18:57:05
sounds like there should be an additional comment
Jing Zhao
2011/11/03 17:49:08
I don't know either.. What I know is Android doesn
joth
2011/11/03 19:45:02
actually, looking at it again, I think it's pretty
Jing Zhao
2011/11/04 08:01:43
Added. Thanks for helping me out.
| |
38 class DnsReloader : public net::NetworkChangeNotifier::DNSObserver { | 38 class DnsReloader : public net::NetworkChangeNotifier::DNSObserver { |
39 public: | 39 public: |
40 struct ReloadState { | 40 struct ReloadState { |
41 int resolver_generation; | 41 int resolver_generation; |
42 }; | 42 }; |
43 | 43 |
44 // NetworkChangeNotifier::OnDNSChanged methods: | 44 // NetworkChangeNotifier::OnDNSChanged methods: |
45 virtual void OnDNSChanged() OVERRIDE { | 45 virtual void OnDNSChanged() OVERRIDE { |
46 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_IO); | 46 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_IO); |
47 base::AutoLock l(lock_); | 47 base::AutoLock l(lock_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 } | 112 } |
113 | 113 |
114 void DnsReloaderMaybeReload() { | 114 void DnsReloaderMaybeReload() { |
115 // This routine can be called by any of the DNS worker threads. | 115 // This routine can be called by any of the DNS worker threads. |
116 DnsReloader* dns_reloader = g_dns_reloader.Pointer(); | 116 DnsReloader* dns_reloader = g_dns_reloader.Pointer(); |
117 dns_reloader->MaybeReload(); | 117 dns_reloader->MaybeReload(); |
118 } | 118 } |
119 | 119 |
120 } // namespace net | 120 } // namespace net |
121 | 121 |
122 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 122 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) && ! defined(OS_ANDROID) |
OLD | NEW |