| 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/dnsrr_resolver.h" | 5 #include "net/base/dnsrr_resolver.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <resolv.h> | 8 #include <resolv.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include <windns.h> | 12 #include <windns.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/string_piece.h" | 19 #include "base/string_piece.h" |
| 20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "base/task.h" | 21 #include "base/task.h" |
| 22 #include "base/threading/worker_pool.h" | 22 #include "base/threading/worker_pool.h" |
| 23 #include "net/base/dns_reloader.h" | 23 #include "net/base/dns_reload_timer.h" |
| 24 #include "net/base/dns_util.h" | 24 #include "net/base/dns_util.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 | 26 |
| 27 // Life of a query: | 27 // Life of a query: |
| 28 // | 28 // |
| 29 // DnsRRResolver RRResolverJob RRResolverWorker ... Handle | 29 // DnsRRResolver RRResolverJob RRResolverWorker ... Handle |
| 30 // | (origin loop) (worker loop) | 30 // | (origin loop) (worker loop) |
| 31 // | | 31 // | |
| 32 // Resolve() | 32 // Resolve() |
| 33 // |---->-------------------<creates> | 33 // |---->-------------------<creates> |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 void Run() { | 178 void Run() { |
| 179 // Runs on a worker thread. | 179 // Runs on a worker thread. |
| 180 | 180 |
| 181 if (HandleTestCases()) { | 181 if (HandleTestCases()) { |
| 182 Finish(); | 182 Finish(); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool r = true; | 186 bool r = true; |
| 187 #if defined(OS_MACOSX) || defined(OS_OPENBSD) | |
| 188 if ((_res.options & RES_INIT) == 0) { | 187 if ((_res.options & RES_INIT) == 0) { |
| 189 if (res_ninit(&_res) != 0) | 188 if (res_ninit(&_res) != 0) |
| 190 r = false; | 189 r = false; |
| 191 } | 190 } |
| 192 #else | |
| 193 DnsReloaderMaybeReload(); | |
| 194 #endif | |
| 195 | 191 |
| 196 if (r) { | 192 if (r) { |
| 197 unsigned long saved_options = _res.options; | 193 unsigned long saved_options = _res.options; |
| 198 r = Do(); | 194 r = Do(); |
| 195 |
| 196 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 197 if (!r && DnsReloadTimerHasExpired()) { |
| 198 // When there's no network connection, _res may not be initialized by |
| 199 // getaddrinfo. Therefore, we call res_nclose only when there are ns |
| 200 // entries. |
| 201 if (_res.nscount > 0) |
| 202 res_nclose(&_res); |
| 203 if (res_ninit(&_res) == 0) |
| 204 r = Do(); |
| 205 } |
| 206 #endif |
| 199 _res.options = saved_options; | 207 _res.options = saved_options; |
| 200 } | 208 } |
| 201 | 209 |
| 202 response_.fetch_time = base::Time::Now(); | 210 response_.fetch_time = base::Time::Now(); |
| 203 | 211 |
| 204 if (r) { | 212 if (r) { |
| 205 result_ = OK; | 213 result_ = OK; |
| 206 } else { | 214 } else { |
| 207 result_ = ERR_NAME_NOT_RESOLVED; | 215 result_ = ERR_NAME_NOT_RESOLVED; |
| 208 response_.negative = true; | 216 response_.negative = true; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 inflight_.erase(j); | 673 inflight_.erase(j); |
| 666 | 674 |
| 667 job->HandleResult(result, response); | 675 job->HandleResult(result, response); |
| 668 delete job; | 676 delete job; |
| 669 } | 677 } |
| 670 | 678 |
| 671 } // namespace net | 679 } // namespace net |
| 672 | 680 |
| 673 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::RRResolverHandle); | 681 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::RRResolverHandle); |
| 674 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::RRResolverWorker); | 682 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::RRResolverWorker); |
| OLD | NEW |