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

Side by Side Diff: net/dns/dns_config_service_posix.cc

Issue 8429034: Upstream: Build net_unittests for Android. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix llog -- it's not for all targets 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
« no previous file with comments | « net/base/x509_certificate_openssl_android.cc ('k') | net/net.gyp » ('j') | 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) 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/dns/dns_config_service_posix.h" 5 #include "net/dns/dns_config_service_posix.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 12 matching lines...) Expand all
23 23
24 // A SerialWorker that uses ResolverLib to initialize res_state and converts 24 // A SerialWorker that uses ResolverLib to initialize res_state and converts
25 // it to DnsConfig. 25 // it to DnsConfig.
26 class DnsConfigServicePosix::ConfigReader : public SerialWorker { 26 class DnsConfigServicePosix::ConfigReader : public SerialWorker {
27 public: 27 public:
28 explicit ConfigReader(DnsConfigServicePosix* service) 28 explicit ConfigReader(DnsConfigServicePosix* service)
29 : service_(service), 29 : service_(service),
30 success_(false) {} 30 success_(false) {}
31 31
32 void DoWork() OVERRIDE { 32 void DoWork() OVERRIDE {
33 // Note: res_ninit in glibc always returns 0 and sets RES_INIT.
34 // res_init behaves the same way.
35 success_ = false;
joth 2011/11/03 19:45:02 I like this tidy up in terms of un-interleaving th
Jing Zhao 2011/11/04 08:01:43 Done.
33 #if defined(OS_OPENBSD) 36 #if defined(OS_OPENBSD)
34 if ((res_init() == 0) && (_res.options & RES_INIT)) { 37 if ((res_init() == 0) && (_res.options & RES_INIT)) {
35 success_ = ConvertResToConfig(_res, &dns_config_); 38 success_ = ConvertResToConfig(_res, &dns_config_);
36 #else 39 }
40 #elif !defined(OS_ANDROID)
37 struct __res_state res; 41 struct __res_state res;
38 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) { 42 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) {
39 success_ = ConvertResToConfig(res, &dns_config_); 43 success_ = ConvertResToConfig(res, &dns_config_);
44 }
40 #endif 45 #endif
41 } else {
42 // Note: res_ninit in glibc always returns 0 and sets RES_INIT.
43 // res_init behaves the same way.
44 success_ = false;
45 }
46 #if defined(OS_MACOSX) 46 #if defined(OS_MACOSX)
47 res_ndestroy(&res); 47 res_ndestroy(&res);
48 #elif !defined(OS_OPENBSD) 48 #elif !defined(OS_OPENBSD) && !defined(ANDROID)
49 res_nclose(&res); 49 res_nclose(&res);
50 #endif 50 #endif
51 } 51 }
52 52
53 void OnWorkFinished() OVERRIDE { 53 void OnWorkFinished() OVERRIDE {
54 DCHECK(!IsCancelled()); 54 DCHECK(!IsCancelled());
55 if (success_) 55 if (success_)
56 service_->OnConfigRead(dns_config_); 56 service_->OnConfigRead(dns_config_);
57 } 57 }
58 58
(...skipping 18 matching lines...) Expand all
77 new ConfigReader(this)); 77 new ConfigReader(this));
78 FilePath hosts_path(FILE_PATH_LITERAL("/etc/hosts")); 78 FilePath hosts_path(FILE_PATH_LITERAL("/etc/hosts"));
79 hosts_watcher_->StartWatch(hosts_path, new DnsHostsReader(hosts_path, this)); 79 hosts_watcher_->StartWatch(hosts_path, new DnsHostsReader(hosts_path, this));
80 } 80 }
81 81
82 // static 82 // static
83 DnsConfigService* DnsConfigService::CreateSystemService() { 83 DnsConfigService* DnsConfigService::CreateSystemService() {
84 return new DnsConfigServicePosix(); 84 return new DnsConfigServicePosix();
85 } 85 }
86 86
87 #if !defined(OS_ANDROID)
87 bool ConvertResToConfig(const struct __res_state& res, DnsConfig* dns_config) { 88 bool ConvertResToConfig(const struct __res_state& res, DnsConfig* dns_config) {
88 CHECK(dns_config != NULL); 89 CHECK(dns_config != NULL);
89 DCHECK(res.options & RES_INIT); 90 DCHECK(res.options & RES_INIT);
90 91
91 dns_config->nameservers.clear(); 92 dns_config->nameservers.clear();
92 93
93 #if defined(OS_LINUX) 94 #if defined(OS_LINUX)
94 // Initially, glibc stores IPv6 in _ext.nsaddrs and IPv4 in nsaddr_list. 95 // Initially, glibc stores IPv6 in _ext.nsaddrs and IPv4 in nsaddr_list.
95 // Next (res_send.c::__libc_res_nsend), it copies nsaddr_list after nsaddrs. 96 // Next (res_send.c::__libc_res_nsend), it copies nsaddr_list after nsaddrs.
96 // If RES_ROTATE is enabled, the list is shifted left after each res_send. 97 // If RES_ROTATE is enabled, the list is shifted left after each res_send.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 dns_config->ndots = res.ndots; 130 dns_config->ndots = res.ndots;
130 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); 131 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans);
131 dns_config->attempts = res.retry; 132 dns_config->attempts = res.retry;
132 #if defined(RES_ROTATE) 133 #if defined(RES_ROTATE)
133 dns_config->rotate = res.options & RES_ROTATE; 134 dns_config->rotate = res.options & RES_ROTATE;
134 #endif 135 #endif
135 dns_config->edns0 = res.options & RES_USE_EDNS0; 136 dns_config->edns0 = res.options & RES_USE_EDNS0;
136 137
137 return true; 138 return true;
138 } 139 }
140 #endif
139 141
140 } // namespace net 142 } // namespace net
OLDNEW
« no previous file with comments | « net/base/x509_certificate_openssl_android.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698