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> |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 //----------------------------------------------------------------------------- | 1145 //----------------------------------------------------------------------------- |
1146 | 1146 |
1147 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. | 1147 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. |
1148 class HostResolverImpl::Job : public PrioritizedDispatcher::Job { | 1148 class HostResolverImpl::Job : public PrioritizedDispatcher::Job { |
1149 public: | 1149 public: |
1150 // Creates new job for |key| where |request_net_log| is bound to the | 1150 // Creates new job for |key| where |request_net_log| is bound to the |
1151 // request that spawned it. | 1151 // request that spawned it. |
1152 Job(const base::WeakPtr<HostResolverImpl>& resolver, | 1152 Job(const base::WeakPtr<HostResolverImpl>& resolver, |
1153 const Key& key, | 1153 const Key& key, |
1154 RequestPriority priority, | 1154 RequestPriority priority, |
1155 const BoundNetLog& request_net_log) | 1155 const BoundNetLog& request_net_log, |
1156 const RequestInfo& info) | |
szym
2013/09/16 21:50:32
No need for this. The flags are available in |key.
Elly Fong-Jones
2013/09/16 22:10:11
Done.
| |
1156 : resolver_(resolver), | 1157 : resolver_(resolver), |
1157 key_(key), | 1158 key_(key), |
1158 priority_tracker_(priority), | 1159 priority_tracker_(priority), |
1159 had_non_speculative_request_(false), | 1160 had_non_speculative_request_(false), |
1160 had_dns_config_(false), | 1161 had_dns_config_(false), |
1161 dns_task_error_(OK), | 1162 dns_task_error_(OK), |
1162 creation_time_(base::TimeTicks::Now()), | 1163 creation_time_(base::TimeTicks::Now()), |
1163 priority_change_time_(creation_time_), | 1164 priority_change_time_(creation_time_), |
1164 net_log_(BoundNetLog::Make(request_net_log.net_log(), | 1165 net_log_(BoundNetLog::Make(request_net_log.net_log(), |
1165 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { | 1166 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)), |
1167 info_(info) { | |
1166 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); | 1168 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); |
1167 | 1169 |
1168 net_log_.BeginEvent( | 1170 net_log_.BeginEvent( |
1169 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1171 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, |
1170 base::Bind(&NetLogJobCreationCallback, | 1172 base::Bind(&NetLogJobCreationCallback, |
1171 request_net_log.source(), | 1173 request_net_log.source(), |
1172 &key_.hostname)); | 1174 &key_.hostname)); |
1173 } | 1175 } |
1174 | 1176 |
1175 virtual ~Job() { | 1177 virtual ~Job() { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTime", priority(), | 1356 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTime", priority(), |
1355 queue_time); | 1357 queue_time); |
1356 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTimeAfterChange", priority(), | 1358 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTimeAfterChange", priority(), |
1357 queue_time_after_change); | 1359 queue_time_after_change); |
1358 } else { | 1360 } else { |
1359 DNS_HISTOGRAM_BY_PRIORITY("DNS.JobQueueTime", priority(), queue_time); | 1361 DNS_HISTOGRAM_BY_PRIORITY("DNS.JobQueueTime", priority(), queue_time); |
1360 DNS_HISTOGRAM_BY_PRIORITY("DNS.JobQueueTimeAfterChange", priority(), | 1362 DNS_HISTOGRAM_BY_PRIORITY("DNS.JobQueueTimeAfterChange", priority(), |
1361 queue_time_after_change); | 1363 queue_time_after_change); |
1362 } | 1364 } |
1363 | 1365 |
1366 HostResolverFlags resolver_flags = info_.host_resolver_flags(); | |
1367 bool native_only = resolver_flags & HOST_RESOLVER_NATIVE_ONLY; | |
1368 | |
1364 // Caution: Job::Start must not complete synchronously. | 1369 // Caution: Job::Start must not complete synchronously. |
1365 if (had_dns_config_ && !ResemblesMulticastDNSName(key_.hostname)) { | 1370 if (!native_only && had_dns_config_ && |
1371 !ResemblesMulticastDNSName(key_.hostname)) { | |
1366 StartDnsTask(); | 1372 StartDnsTask(); |
1367 } else { | 1373 } else { |
1368 StartProcTask(); | 1374 StartProcTask(); |
1369 } | 1375 } |
1370 } | 1376 } |
1371 | 1377 |
1372 // TODO(szym): Since DnsTransaction does not consume threads, we can increase | 1378 // TODO(szym): Since DnsTransaction does not consume threads, we can increase |
1373 // the limits on |dispatcher_|. But in order to keep the number of WorkerPool | 1379 // the limits on |dispatcher_|. But in order to keep the number of WorkerPool |
1374 // threads low, we will need to use an "inner" PrioritizedDispatcher with | 1380 // threads low, we will need to use an "inner" PrioritizedDispatcher with |
1375 // tighter limits. | 1381 // tighter limits. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1645 scoped_refptr<ProcTask> proc_task_; | 1651 scoped_refptr<ProcTask> proc_task_; |
1646 | 1652 |
1647 // Resolves the host using a DnsTransaction. | 1653 // Resolves the host using a DnsTransaction. |
1648 scoped_ptr<DnsTask> dns_task_; | 1654 scoped_ptr<DnsTask> dns_task_; |
1649 | 1655 |
1650 // All Requests waiting for the result of this Job. Some can be canceled. | 1656 // All Requests waiting for the result of this Job. Some can be canceled. |
1651 RequestsList requests_; | 1657 RequestsList requests_; |
1652 | 1658 |
1653 // A handle used in |HostResolverImpl::dispatcher_|. | 1659 // A handle used in |HostResolverImpl::dispatcher_|. |
1654 PrioritizedDispatcher::Handle handle_; | 1660 PrioritizedDispatcher::Handle handle_; |
1661 | |
1662 RequestInfo info_; | |
1655 }; | 1663 }; |
1656 | 1664 |
1657 //----------------------------------------------------------------------------- | 1665 //----------------------------------------------------------------------------- |
1658 | 1666 |
1659 HostResolverImpl::ProcTaskParams::ProcTaskParams( | 1667 HostResolverImpl::ProcTaskParams::ProcTaskParams( |
1660 HostResolverProc* resolver_proc, | 1668 HostResolverProc* resolver_proc, |
1661 size_t max_retry_attempts) | 1669 size_t max_retry_attempts) |
1662 : resolver_proc(resolver_proc), | 1670 : resolver_proc(resolver_proc), |
1663 max_retry_attempts(max_retry_attempts), | 1671 max_retry_attempts(max_retry_attempts), |
1664 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), | 1672 unresponsive_delay(base::TimeDelta::FromMilliseconds(6000)), |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 return rv; | 1773 return rv; |
1766 } | 1774 } |
1767 | 1775 |
1768 // Next we need to attach our request to a "job". This job is responsible for | 1776 // Next we need to attach our request to a "job". This job is responsible for |
1769 // calling "getaddrinfo(hostname)" on a worker thread. | 1777 // calling "getaddrinfo(hostname)" on a worker thread. |
1770 | 1778 |
1771 JobMap::iterator jobit = jobs_.find(key); | 1779 JobMap::iterator jobit = jobs_.find(key); |
1772 Job* job; | 1780 Job* job; |
1773 if (jobit == jobs_.end()) { | 1781 if (jobit == jobs_.end()) { |
1774 job = | 1782 job = |
1775 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, request_net_log); | 1783 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, request_net_log, |
1784 info); | |
1776 job->Schedule(); | 1785 job->Schedule(); |
1777 | 1786 |
1778 // Check for queue overflow. | 1787 // Check for queue overflow. |
1779 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { | 1788 if (dispatcher_.num_queued_jobs() > max_queued_jobs_) { |
1780 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); | 1789 Job* evicted = static_cast<Job*>(dispatcher_.EvictOldestLowest()); |
1781 DCHECK(evicted); | 1790 DCHECK(evicted); |
1782 evicted->OnEvicted(); // Deletes |evicted|. | 1791 evicted->OnEvicted(); // Deletes |evicted|. |
1783 if (evicted == job) { | 1792 if (evicted == job) { |
1784 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1793 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
1785 LogFinishRequest(source_net_log, request_net_log, info, rv); | 1794 LogFinishRequest(source_net_log, request_net_log, info, rv); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2197 } | 2206 } |
2198 DnsConfig dns_config; | 2207 DnsConfig dns_config; |
2199 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2208 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
2200 dns_client_->SetConfig(dns_config); | 2209 dns_client_->SetConfig(dns_config); |
2201 num_dns_failures_ = 0; | 2210 num_dns_failures_ = 0; |
2202 if (dns_client_->GetConfig()) | 2211 if (dns_client_->GetConfig()) |
2203 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2212 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2204 } | 2213 } |
2205 | 2214 |
2206 } // namespace net | 2215 } // namespace net |
OLD | NEW |