OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host_resolver_impl.h" | 5 #include "net/dns/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> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/bind_helpers.h" | 19 #include "base/bind_helpers.h" |
20 #include "base/callback.h" | 20 #include "base/callback.h" |
21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
22 #include "base/debug/debugger.h" | 22 #include "base/debug/debugger.h" |
23 #include "base/debug/stack_trace.h" | 23 #include "base/debug/stack_trace.h" |
24 #include "base/message_loop/message_loop_proxy.h" | 24 #include "base/message_loop/message_loop_proxy.h" |
25 #include "base/metrics/field_trial.h" | 25 #include "base/metrics/field_trial.h" |
26 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
27 #include "base/profiler/scoped_tracker.h" | |
28 #include "base/stl_util.h" | 27 #include "base/stl_util.h" |
29 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
30 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
31 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
32 #include "base/time/time.h" | 31 #include "base/time/time.h" |
33 #include "base/values.h" | 32 #include "base/values.h" |
34 #include "net/base/address_family.h" | 33 #include "net/base/address_family.h" |
35 #include "net/base/address_list.h" | 34 #include "net/base/address_list.h" |
36 #include "net/base/dns_reloader.h" | 35 #include "net/base/dns_reloader.h" |
37 #include "net/base/dns_util.h" | 36 #include "net/base/dns_util.h" |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } | 487 } |
489 | 488 |
490 void set_job(Job* job) { | 489 void set_job(Job* job) { |
491 DCHECK(job); | 490 DCHECK(job); |
492 // Identify which job the request is waiting on. | 491 // Identify which job the request is waiting on. |
493 job_ = job; | 492 job_ = job; |
494 } | 493 } |
495 | 494 |
496 // Prepare final AddressList and call completion callback. | 495 // Prepare final AddressList and call completion callback. |
497 void OnComplete(int error, const AddressList& addr_list) { | 496 void OnComplete(int error, const AddressList& addr_list) { |
498 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
499 tracked_objects::ScopedTracker tracking_profile( | |
500 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
501 "436634 HostResolverImpl::Request::OnComplete")); | |
502 | |
503 DCHECK(!was_canceled()); | 497 DCHECK(!was_canceled()); |
504 if (error == OK) | 498 if (error == OK) |
505 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port()); | 499 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port()); |
506 CompletionCallback callback = callback_; | 500 CompletionCallback callback = callback_; |
507 MarkAsCanceled(); | 501 MarkAsCanceled(); |
508 callback.Run(error); | 502 callback.Run(error); |
509 } | 503 } |
510 | 504 |
511 Job* job() const { | 505 Job* job() const { |
512 return job_; | 506 return job_; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 params_.unresponsive_delay *= params_.retry_factor; | 697 params_.unresponsive_delay *= params_.retry_factor; |
704 StartLookupAttempt(); | 698 StartLookupAttempt(); |
705 } | 699 } |
706 | 700 |
707 // Callback for when DoLookup() completes (runs on origin thread). | 701 // Callback for when DoLookup() completes (runs on origin thread). |
708 void OnLookupComplete(const AddressList& results, | 702 void OnLookupComplete(const AddressList& results, |
709 const base::TimeTicks& start_time, | 703 const base::TimeTicks& start_time, |
710 const uint32 attempt_number, | 704 const uint32 attempt_number, |
711 int error, | 705 int error, |
712 const int os_error) { | 706 const int os_error) { |
713 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
714 tracked_objects::ScopedTracker tracking_profile1( | |
715 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
716 "436634 HostResolverImpl::ProcTask::OnLookupComplete1")); | |
717 | |
718 DCHECK(origin_loop_->BelongsToCurrentThread()); | 707 DCHECK(origin_loop_->BelongsToCurrentThread()); |
719 // If results are empty, we should return an error. | 708 // If results are empty, we should return an error. |
720 bool empty_list_on_ok = (error == OK && results.empty()); | 709 bool empty_list_on_ok = (error == OK && results.empty()); |
721 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); | 710 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); |
722 if (empty_list_on_ok) | 711 if (empty_list_on_ok) |
723 error = ERR_NAME_NOT_RESOLVED; | 712 error = ERR_NAME_NOT_RESOLVED; |
724 | 713 |
725 bool was_retry_attempt = attempt_number > 1; | 714 bool was_retry_attempt = attempt_number > 1; |
726 | 715 |
727 // Ideally the following code would be part of host_resolver_proc.cc, | 716 // Ideally the following code would be part of host_resolver_proc.cc, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 | 758 |
770 if (error != OK) { | 759 if (error != OK) { |
771 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, | 760 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, |
772 0, error, os_error); | 761 0, error, os_error); |
773 } else { | 762 } else { |
774 net_log_callback = results_.CreateNetLogCallback(); | 763 net_log_callback = results_.CreateNetLogCallback(); |
775 } | 764 } |
776 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 765 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, |
777 net_log_callback); | 766 net_log_callback); |
778 | 767 |
779 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
780 tracked_objects::ScopedTracker tracking_profile2( | |
781 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
782 "436634 HostResolverImpl::ProcTask::OnLookupComplete2")); | |
783 | |
784 callback_.Run(error, results_); | 768 callback_.Run(error, results_); |
785 } | 769 } |
786 | 770 |
787 void RecordPerformanceHistograms(const base::TimeTicks& start_time, | 771 void RecordPerformanceHistograms(const base::TimeTicks& start_time, |
788 const int error, | 772 const int error, |
789 const int os_error) const { | 773 const int os_error) const { |
790 DCHECK(origin_loop_->BelongsToCurrentThread()); | 774 DCHECK(origin_loop_->BelongsToCurrentThread()); |
791 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. | 775 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. |
792 RESOLVE_SUCCESS, | 776 RESOLVE_SUCCESS, |
793 RESOLVE_FAIL, | 777 RESOLVE_FAIL, |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 proc_task_->set_had_non_speculative_request(); | 1494 proc_task_->set_had_non_speculative_request(); |
1511 // Start() could be called from within Resolve(), hence it must NOT directly | 1495 // Start() could be called from within Resolve(), hence it must NOT directly |
1512 // call OnProcTaskComplete, for example, on synchronous failure. | 1496 // call OnProcTaskComplete, for example, on synchronous failure. |
1513 proc_task_->Start(); | 1497 proc_task_->Start(); |
1514 } | 1498 } |
1515 | 1499 |
1516 // Called by ProcTask when it completes. | 1500 // Called by ProcTask when it completes. |
1517 void OnProcTaskComplete(base::TimeTicks start_time, | 1501 void OnProcTaskComplete(base::TimeTicks start_time, |
1518 int net_error, | 1502 int net_error, |
1519 const AddressList& addr_list) { | 1503 const AddressList& addr_list) { |
1520 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
1521 tracked_objects::ScopedTracker tracking_profile( | |
1522 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1523 "436634 HostResolverImpl::Job::OnProcTaskComplete")); | |
1524 | |
1525 DCHECK(is_proc_running()); | 1504 DCHECK(is_proc_running()); |
1526 | 1505 |
1527 if (!resolver_->resolved_known_ipv6_hostname_ && | 1506 if (!resolver_->resolved_known_ipv6_hostname_ && |
1528 net_error == OK && | 1507 net_error == OK && |
1529 key_.address_family == ADDRESS_FAMILY_UNSPECIFIED) { | 1508 key_.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
1530 if (key_.hostname == "www.google.com") { | 1509 if (key_.hostname == "www.google.com") { |
1531 resolver_->resolved_known_ipv6_hostname_ = true; | 1510 resolver_->resolved_known_ipv6_hostname_ = true; |
1532 bool got_ipv6_address = false; | 1511 bool got_ipv6_address = false; |
1533 for (size_t i = 0; i < addr_list.size(); ++i) { | 1512 for (size_t i = 0; i < addr_list.size(); ++i) { |
1534 if (addr_list[i].GetFamily() == ADDRESS_FAMILY_IPV6) { | 1513 if (addr_list[i].GetFamily() == ADDRESS_FAMILY_IPV6) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 // We already have a job slot at the dispatcher, so if the second | 1643 // We already have a job slot at the dispatcher, so if the second |
1665 // transaction hasn't started, reuse it now instead of waiting in the queue | 1644 // transaction hasn't started, reuse it now instead of waiting in the queue |
1666 // for the second slot. | 1645 // for the second slot. |
1667 if (dns_task_->needs_another_transaction()) | 1646 if (dns_task_->needs_another_transaction()) |
1668 dns_task_->StartSecondTransaction(); | 1647 dns_task_->StartSecondTransaction(); |
1669 } | 1648 } |
1670 | 1649 |
1671 // Performs Job's last rites. Completes all Requests. Deletes this. | 1650 // Performs Job's last rites. Completes all Requests. Deletes this. |
1672 void CompleteRequests(const HostCache::Entry& entry, | 1651 void CompleteRequests(const HostCache::Entry& entry, |
1673 base::TimeDelta ttl) { | 1652 base::TimeDelta ttl) { |
1674 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
1675 tracked_objects::ScopedTracker tracking_profile1( | |
1676 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1677 "436634 HostResolverImpl::Job::CompleteRequests1")); | |
1678 | |
1679 CHECK(resolver_.get()); | 1653 CHECK(resolver_.get()); |
1680 | 1654 |
1681 // This job must be removed from resolver's |jobs_| now to make room for a | 1655 // This job must be removed from resolver's |jobs_| now to make room for a |
1682 // new job with the same key in case one of the OnComplete callbacks decides | 1656 // new job with the same key in case one of the OnComplete callbacks decides |
1683 // to spawn one. Consequently, the job deletes itself when CompleteRequests | 1657 // to spawn one. Consequently, the job deletes itself when CompleteRequests |
1684 // is done. | 1658 // is done. |
1685 scoped_ptr<Job> self_deleter(this); | 1659 scoped_ptr<Job> self_deleter(this); |
1686 | 1660 |
1687 resolver_->RemoveJob(this); | 1661 resolver_->RemoveJob(this); |
1688 | 1662 |
(...skipping 29 matching lines...) Expand all Loading... |
1718 // configuration. | 1692 // configuration. |
1719 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", | 1693 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", |
1720 resolver_->received_dns_config_); | 1694 resolver_->received_dns_config_); |
1721 } | 1695 } |
1722 | 1696 |
1723 bool did_complete = (entry.error != ERR_NETWORK_CHANGED) && | 1697 bool did_complete = (entry.error != ERR_NETWORK_CHANGED) && |
1724 (entry.error != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); | 1698 (entry.error != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); |
1725 if (did_complete) | 1699 if (did_complete) |
1726 resolver_->CacheResult(key_, entry, ttl); | 1700 resolver_->CacheResult(key_, entry, ttl); |
1727 | 1701 |
1728 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. | |
1729 tracked_objects::ScopedTracker tracking_profile2( | |
1730 FROM_HERE_WITH_EXPLICIT_FUNCTION( | |
1731 "436634 HostResolverImpl::Job::CompleteRequests2")); | |
1732 | |
1733 // Complete all of the requests that were attached to the job. | 1702 // Complete all of the requests that were attached to the job. |
1734 for (RequestsList::const_iterator it = requests_.begin(); | 1703 for (RequestsList::const_iterator it = requests_.begin(); |
1735 it != requests_.end(); ++it) { | 1704 it != requests_.end(); ++it) { |
1736 Request* req = *it; | 1705 Request* req = *it; |
1737 | 1706 |
1738 if (req->was_canceled()) | 1707 if (req->was_canceled()) |
1739 continue; | 1708 continue; |
1740 | 1709 |
1741 DCHECK_EQ(this, req->job()); | 1710 DCHECK_EQ(this, req->job()); |
1742 // Update the net log and notify registered observers. | 1711 // Update the net log and notify registered observers. |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 dns_client_->SetConfig(dns_config); | 2361 dns_client_->SetConfig(dns_config); |
2393 num_dns_failures_ = 0; | 2362 num_dns_failures_ = 0; |
2394 if (dns_client_->GetConfig()) | 2363 if (dns_client_->GetConfig()) |
2395 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2364 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2396 } | 2365 } |
2397 | 2366 |
2398 AbortDnsTasks(); | 2367 AbortDnsTasks(); |
2399 } | 2368 } |
2400 | 2369 |
2401 } // namespace net | 2370 } // namespace net |
OLD | NEW |