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

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

Issue 8429034: Upstream: Build net_unittests for Android. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix build Created 9 years, 1 month 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/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) && \
8 !defined(OS_ANDROID)
8 9
9 #include <resolv.h> 10 #include <resolv.h>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/message_loop.h" 15 #include "base/message_loop.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/threading/thread_local_storage.h" 17 #include "base/threading/thread_local_storage.h"
17 #include "net/base/network_change_notifier.h" 18 #include "net/base/network_change_notifier.h"
18 19
19 namespace { 20 namespace {
20 21
21 // On Linux/BSD, changes to /etc/resolv.conf can go unnoticed thus resulting 22 // 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 23 // 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 24 // 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 25 // 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 26 // 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 27 // universal and even patched systems such as Jaunty appear to need calls
27 // to res_ninit to reload the nameserver information in different threads. 28 // to res_ninit to reload the nameserver information in different threads.
28 // 29 //
29 // To fix this, on systems with FilePathWatcher support, we use 30 // To fix this, on systems with FilePathWatcher support, we use
30 // NetworkChangeNotifier::DNSObserver to monitor /etc/resolv.conf to 31 // NetworkChangeNotifier::DNSObserver to monitor /etc/resolv.conf to
31 // enable us to respond to DNS changes and reload the resolver state. 32 // enable us to respond to DNS changes and reload the resolver state.
32 // 33 //
33 // OpenBSD does not have thread-safe res_ninit/res_nclose so we can't do 34 // 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 35 // 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 36 // FilePathWatcher (but perhaps the new kqueue mac code just needs to be
36 // ported to *BSD to support that). 37 // ported to *BSD to support that).
38 //
39 // Android does not have /etc/resolv.conf. The system takes care of nameserver
40 // changes, so none of this is needed.
37 41
38 class DnsReloader : public net::NetworkChangeNotifier::DNSObserver { 42 class DnsReloader : public net::NetworkChangeNotifier::DNSObserver {
39 public: 43 public:
40 struct ReloadState { 44 struct ReloadState {
41 int resolver_generation; 45 int resolver_generation;
42 }; 46 };
43 47
44 // NetworkChangeNotifier::OnDNSChanged methods: 48 // NetworkChangeNotifier::OnDNSChanged methods:
45 virtual void OnDNSChanged() OVERRIDE { 49 virtual void OnDNSChanged() OVERRIDE {
46 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_IO); 50 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_IO);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 116 }
113 117
114 void DnsReloaderMaybeReload() { 118 void DnsReloaderMaybeReload() {
115 // This routine can be called by any of the DNS worker threads. 119 // This routine can be called by any of the DNS worker threads.
116 DnsReloader* dns_reloader = g_dns_reloader.Pointer(); 120 DnsReloader* dns_reloader = g_dns_reloader.Pointer();
117 dns_reloader->MaybeReload(); 121 dns_reloader->MaybeReload();
118 } 122 }
119 123
120 } // namespace net 124 } // namespace net
121 125
122 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 126 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) &&
127 // !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698