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" |
27 #include "base/stl_util.h" | 28 #include "base/stl_util.h" |
28 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
29 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
30 #include "base/threading/worker_pool.h" | 31 #include "base/threading/worker_pool.h" |
31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
32 #include "base/values.h" | 33 #include "base/values.h" |
33 #include "net/base/address_family.h" | 34 #include "net/base/address_family.h" |
34 #include "net/base/address_list.h" | 35 #include "net/base/address_list.h" |
35 #include "net/base/dns_reloader.h" | 36 #include "net/base/dns_reloader.h" |
36 #include "net/base/dns_util.h" | 37 #include "net/base/dns_util.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 } | 474 } |
474 | 475 |
475 void set_job(Job* job) { | 476 void set_job(Job* job) { |
476 DCHECK(job); | 477 DCHECK(job); |
477 // Identify which job the request is waiting on. | 478 // Identify which job the request is waiting on. |
478 job_ = job; | 479 job_ = job; |
479 } | 480 } |
480 | 481 |
481 // Prepare final AddressList and call completion callback. | 482 // Prepare final AddressList and call completion callback. |
482 void OnComplete(int error, const AddressList& addr_list) { | 483 void OnComplete(int error, const AddressList& addr_list) { |
| 484 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 485 tracked_objects::ScopedTracker tracking_profile( |
| 486 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 487 "436634 HostResolverImpl::Request::OnComplete")); |
| 488 |
483 DCHECK(!was_canceled()); | 489 DCHECK(!was_canceled()); |
484 if (error == OK) | 490 if (error == OK) |
485 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port()); | 491 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port()); |
486 CompletionCallback callback = callback_; | 492 CompletionCallback callback = callback_; |
487 MarkAsCanceled(); | 493 MarkAsCanceled(); |
488 callback.Run(error); | 494 callback.Run(error); |
489 } | 495 } |
490 | 496 |
491 Job* job() const { | 497 Job* job() const { |
492 return job_; | 498 return job_; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 params_.unresponsive_delay *= params_.retry_factor; | 678 params_.unresponsive_delay *= params_.retry_factor; |
673 StartLookupAttempt(); | 679 StartLookupAttempt(); |
674 } | 680 } |
675 | 681 |
676 // Callback for when DoLookup() completes (runs on origin thread). | 682 // Callback for when DoLookup() completes (runs on origin thread). |
677 void OnLookupComplete(const AddressList& results, | 683 void OnLookupComplete(const AddressList& results, |
678 const base::TimeTicks& start_time, | 684 const base::TimeTicks& start_time, |
679 const uint32 attempt_number, | 685 const uint32 attempt_number, |
680 int error, | 686 int error, |
681 const int os_error) { | 687 const int os_error) { |
| 688 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 689 tracked_objects::ScopedTracker tracking_profile1( |
| 690 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 691 "436634 HostResolverImpl::ProcTask::OnLookupComplete1")); |
| 692 |
682 DCHECK(origin_loop_->BelongsToCurrentThread()); | 693 DCHECK(origin_loop_->BelongsToCurrentThread()); |
683 // If results are empty, we should return an error. | 694 // If results are empty, we should return an error. |
684 bool empty_list_on_ok = (error == OK && results.empty()); | 695 bool empty_list_on_ok = (error == OK && results.empty()); |
685 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); | 696 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); |
686 if (empty_list_on_ok) | 697 if (empty_list_on_ok) |
687 error = ERR_NAME_NOT_RESOLVED; | 698 error = ERR_NAME_NOT_RESOLVED; |
688 | 699 |
689 bool was_retry_attempt = attempt_number > 1; | 700 bool was_retry_attempt = attempt_number > 1; |
690 | 701 |
691 // Ideally the following code would be part of host_resolver_proc.cc, | 702 // 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... |
733 | 744 |
734 if (error != OK) { | 745 if (error != OK) { |
735 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, | 746 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, |
736 0, error, os_error); | 747 0, error, os_error); |
737 } else { | 748 } else { |
738 net_log_callback = results_.CreateNetLogCallback(); | 749 net_log_callback = results_.CreateNetLogCallback(); |
739 } | 750 } |
740 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 751 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, |
741 net_log_callback); | 752 net_log_callback); |
742 | 753 |
| 754 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 755 tracked_objects::ScopedTracker tracking_profile2( |
| 756 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 757 "436634 HostResolverImpl::ProcTask::OnLookupComplete2")); |
| 758 |
743 callback_.Run(error, results_); | 759 callback_.Run(error, results_); |
744 } | 760 } |
745 | 761 |
746 void RecordPerformanceHistograms(const base::TimeTicks& start_time, | 762 void RecordPerformanceHistograms(const base::TimeTicks& start_time, |
747 const int error, | 763 const int error, |
748 const int os_error) const { | 764 const int os_error) const { |
749 DCHECK(origin_loop_->BelongsToCurrentThread()); | 765 DCHECK(origin_loop_->BelongsToCurrentThread()); |
750 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. | 766 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. |
751 RESOLVE_SUCCESS, | 767 RESOLVE_SUCCESS, |
752 RESOLVE_FAIL, | 768 RESOLVE_FAIL, |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 proc_task_->set_had_non_speculative_request(); | 1479 proc_task_->set_had_non_speculative_request(); |
1464 // Start() could be called from within Resolve(), hence it must NOT directly | 1480 // Start() could be called from within Resolve(), hence it must NOT directly |
1465 // call OnProcTaskComplete, for example, on synchronous failure. | 1481 // call OnProcTaskComplete, for example, on synchronous failure. |
1466 proc_task_->Start(); | 1482 proc_task_->Start(); |
1467 } | 1483 } |
1468 | 1484 |
1469 // Called by ProcTask when it completes. | 1485 // Called by ProcTask when it completes. |
1470 void OnProcTaskComplete(base::TimeTicks start_time, | 1486 void OnProcTaskComplete(base::TimeTicks start_time, |
1471 int net_error, | 1487 int net_error, |
1472 const AddressList& addr_list) { | 1488 const AddressList& addr_list) { |
| 1489 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 1490 tracked_objects::ScopedTracker tracking_profile( |
| 1491 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1492 "436634 HostResolverImpl::Job::OnProcTaskComplete")); |
| 1493 |
1473 DCHECK(is_proc_running()); | 1494 DCHECK(is_proc_running()); |
1474 | 1495 |
1475 if (!resolver_->resolved_known_ipv6_hostname_ && | 1496 if (!resolver_->resolved_known_ipv6_hostname_ && |
1476 net_error == OK && | 1497 net_error == OK && |
1477 key_.address_family == ADDRESS_FAMILY_UNSPECIFIED) { | 1498 key_.address_family == ADDRESS_FAMILY_UNSPECIFIED) { |
1478 if (key_.hostname == "www.google.com") { | 1499 if (key_.hostname == "www.google.com") { |
1479 resolver_->resolved_known_ipv6_hostname_ = true; | 1500 resolver_->resolved_known_ipv6_hostname_ = true; |
1480 bool got_ipv6_address = false; | 1501 bool got_ipv6_address = false; |
1481 for (size_t i = 0; i < addr_list.size(); ++i) { | 1502 for (size_t i = 0; i < addr_list.size(); ++i) { |
1482 if (addr_list[i].GetFamily() == ADDRESS_FAMILY_IPV6) { | 1503 if (addr_list[i].GetFamily() == ADDRESS_FAMILY_IPV6) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 // We already have a job slot at the dispatcher, so if the second | 1633 // We already have a job slot at the dispatcher, so if the second |
1613 // transaction hasn't started, reuse it now instead of waiting in the queue | 1634 // transaction hasn't started, reuse it now instead of waiting in the queue |
1614 // for the second slot. | 1635 // for the second slot. |
1615 if (dns_task_->needs_another_transaction()) | 1636 if (dns_task_->needs_another_transaction()) |
1616 dns_task_->StartSecondTransaction(); | 1637 dns_task_->StartSecondTransaction(); |
1617 } | 1638 } |
1618 | 1639 |
1619 // Performs Job's last rites. Completes all Requests. Deletes this. | 1640 // Performs Job's last rites. Completes all Requests. Deletes this. |
1620 void CompleteRequests(const HostCache::Entry& entry, | 1641 void CompleteRequests(const HostCache::Entry& entry, |
1621 base::TimeDelta ttl) { | 1642 base::TimeDelta ttl) { |
| 1643 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 1644 tracked_objects::ScopedTracker tracking_profile1( |
| 1645 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1646 "436634 HostResolverImpl::Job::CompleteRequests1")); |
| 1647 |
1622 CHECK(resolver_.get()); | 1648 CHECK(resolver_.get()); |
1623 | 1649 |
1624 // This job must be removed from resolver's |jobs_| now to make room for a | 1650 // This job must be removed from resolver's |jobs_| now to make room for a |
1625 // new job with the same key in case one of the OnComplete callbacks decides | 1651 // new job with the same key in case one of the OnComplete callbacks decides |
1626 // to spawn one. Consequently, the job deletes itself when CompleteRequests | 1652 // to spawn one. Consequently, the job deletes itself when CompleteRequests |
1627 // is done. | 1653 // is done. |
1628 scoped_ptr<Job> self_deleter(this); | 1654 scoped_ptr<Job> self_deleter(this); |
1629 | 1655 |
1630 resolver_->RemoveJob(this); | 1656 resolver_->RemoveJob(this); |
1631 | 1657 |
(...skipping 29 matching lines...) Expand all Loading... |
1661 // configuration. | 1687 // configuration. |
1662 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", | 1688 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", |
1663 resolver_->received_dns_config_); | 1689 resolver_->received_dns_config_); |
1664 } | 1690 } |
1665 | 1691 |
1666 bool did_complete = (entry.error != ERR_NETWORK_CHANGED) && | 1692 bool did_complete = (entry.error != ERR_NETWORK_CHANGED) && |
1667 (entry.error != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); | 1693 (entry.error != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); |
1668 if (did_complete) | 1694 if (did_complete) |
1669 resolver_->CacheResult(key_, entry, ttl); | 1695 resolver_->CacheResult(key_, entry, ttl); |
1670 | 1696 |
| 1697 // TODO(vadimt): Remove ScopedTracker below once crbug.com/436634 is fixed. |
| 1698 tracked_objects::ScopedTracker tracking_profile2( |
| 1699 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1700 "436634 HostResolverImpl::Job::CompleteRequests2")); |
| 1701 |
1671 // Complete all of the requests that were attached to the job. | 1702 // Complete all of the requests that were attached to the job. |
1672 for (RequestsList::const_iterator it = requests_.begin(); | 1703 for (RequestsList::const_iterator it = requests_.begin(); |
1673 it != requests_.end(); ++it) { | 1704 it != requests_.end(); ++it) { |
1674 Request* req = *it; | 1705 Request* req = *it; |
1675 | 1706 |
1676 if (req->was_canceled()) | 1707 if (req->was_canceled()) |
1677 continue; | 1708 continue; |
1678 | 1709 |
1679 DCHECK_EQ(this, req->job()); | 1710 DCHECK_EQ(this, req->job()); |
1680 // Update the net log and notify registered observers. | 1711 // Update the net log and notify registered observers. |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 dns_client_->SetConfig(dns_config); | 2359 dns_client_->SetConfig(dns_config); |
2329 num_dns_failures_ = 0; | 2360 num_dns_failures_ = 0; |
2330 if (dns_client_->GetConfig()) | 2361 if (dns_client_->GetConfig()) |
2331 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2362 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2332 } | 2363 } |
2333 | 2364 |
2334 AbortDnsTasks(); | 2365 AbortDnsTasks(); |
2335 } | 2366 } |
2336 | 2367 |
2337 } // namespace net | 2368 } // namespace net |
OLD | NEW |