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/base/host_resolver_impl.h" | 5 #include "net/base/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 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1565 Job* job = req->job(); | 1565 Job* job = req->job(); |
1566 DCHECK(job); | 1566 DCHECK(job); |
1567 | 1567 |
1568 job->CancelRequest(req); | 1568 job->CancelRequest(req); |
1569 | 1569 |
1570 if (job->num_active_requests() == 0) { | 1570 if (job->num_active_requests() == 0) { |
1571 // If we were called from a Requests' callback within Job::CompleteRequests, | 1571 // If we were called from a Requests' callback within Job::CompleteRequests, |
1572 // that Request could not have been cancelled, so job->num_active_requests() | 1572 // that Request could not have been cancelled, so job->num_active_requests() |
1573 // could not be 0. Therefore, we are not in Job::CompleteRequests(). | 1573 // could not be 0. Therefore, we are not in Job::CompleteRequests(). |
1574 RemoveJob(job); | 1574 RemoveJob(job); |
1575 if (job->is_running()) | 1575 if (job->is_running()) { |
cbentzel
2012/03/02 19:46:49
I asked over email - but is there a chance that a
| |
1576 dispatcher_.OnJobFinished(); | |
1576 job->Abort(); | 1577 job->Abort(); |
cbentzel
2012/03/02 20:02:40
FYI: I don't think the Abort is needed here. ~Job
szym
2012/03/02 20:05:43
The cleaning up is now in a few places: Job::~Job,
| |
1578 } | |
1577 delete job; | 1579 delete job; |
1578 } | 1580 } |
1579 } | 1581 } |
1580 | 1582 |
1581 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { | 1583 void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { |
1582 DCHECK(CalledOnValidThread()); | 1584 DCHECK(CalledOnValidThread()); |
1583 ipv6_probe_monitoring_ = false; | 1585 ipv6_probe_monitoring_ = false; |
1584 DiscardIPv6ProbeJob(); | 1586 DiscardIPv6ProbeJob(); |
1585 default_address_family_ = address_family; | 1587 default_address_family_ = address_family; |
1586 } | 1588 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1702 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && | 1704 if (effective_address_family == ADDRESS_FAMILY_UNSPECIFIED && |
1703 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { | 1705 default_address_family_ != ADDRESS_FAMILY_UNSPECIFIED) { |
1704 effective_address_family = default_address_family_; | 1706 effective_address_family = default_address_family_; |
1705 if (ipv6_probe_monitoring_) | 1707 if (ipv6_probe_monitoring_) |
1706 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; | 1708 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; |
1707 } | 1709 } |
1708 return Key(info.hostname(), effective_address_family, effective_flags); | 1710 return Key(info.hostname(), effective_address_family, effective_flags); |
1709 } | 1711 } |
1710 | 1712 |
1711 void HostResolverImpl::AbortAllInProgressJobs() { | 1713 void HostResolverImpl::AbortAllInProgressJobs() { |
1712 base::WeakPtr<HostResolverImpl> self = AsWeakPtr(); | |
1713 // In Abort, a Request callback could spawn new Jobs with matching keys, so | 1714 // In Abort, a Request callback could spawn new Jobs with matching keys, so |
1714 // first collect and remove all running jobs from |jobs_|. | 1715 // first collect and remove all running jobs from |jobs_|. |
1715 std::vector<Job*> jobs_to_abort; | 1716 std::vector<Job*> jobs_to_abort; |
1716 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { | 1717 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { |
1717 Job* job = it->second; | 1718 Job* job = it->second; |
1718 if (job->is_running()) { | 1719 if (job->is_running()) { |
1719 jobs_to_abort.push_back(job); | 1720 jobs_to_abort.push_back(job); |
1720 jobs_.erase(it++); | 1721 jobs_.erase(it++); |
1721 } else { | 1722 } else { |
1722 DCHECK(job->is_queued()); | 1723 DCHECK(job->is_queued()); |
1723 ++it; | 1724 ++it; |
1724 } | 1725 } |
1725 } | 1726 } |
1726 | 1727 |
1728 // Check if no dispatcher slots leaked out. | |
1729 DCHECK_EQ(dispatcher_.num_running_jobs(), jobs_to_abort.size()); | |
1730 | |
1731 // Life check to bail once |this| is deleted. | |
1732 base::WeakPtr<HostResolverImpl> self = AsWeakPtr(); | |
1733 | |
1727 // Then Abort them and dispatch new Jobs. | 1734 // Then Abort them and dispatch new Jobs. |
1728 for (size_t i = 0; i < jobs_to_abort.size(); ++i) { | 1735 for (size_t i = 0; self && i < jobs_to_abort.size(); ++i) { |
1736 dispatcher_.OnJobFinished(); | |
1729 jobs_to_abort[i]->Abort(); | 1737 jobs_to_abort[i]->Abort(); |
1730 dispatcher_.OnJobFinished(); | |
1731 } | 1738 } |
1732 STLDeleteElements(&jobs_to_abort); | 1739 STLDeleteElements(&jobs_to_abort); |
1733 } | 1740 } |
1734 | 1741 |
1735 void HostResolverImpl::OnIPAddressChanged() { | 1742 void HostResolverImpl::OnIPAddressChanged() { |
1736 if (cache_.get()) | 1743 if (cache_.get()) |
1737 cache_->clear(); | 1744 cache_->clear(); |
1738 if (ipv6_probe_monitoring_) { | 1745 if (ipv6_probe_monitoring_) { |
1739 DiscardIPv6ProbeJob(); | 1746 DiscardIPv6ProbeJob(); |
1740 ipv6_probe_job_ = new IPv6ProbeJob(this); | 1747 ipv6_probe_job_ = new IPv6ProbeJob(this); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1777 } else { | 1784 } else { |
1778 dns_transaction_factory_.reset(); | 1785 dns_transaction_factory_.reset(); |
1779 } | 1786 } |
1780 // Don't Abort running Jobs unless they were running on DnsTransaction. | 1787 // Don't Abort running Jobs unless they were running on DnsTransaction. |
1781 // TODO(szym): This will change once http://crbug.com/114827 is fixed. | 1788 // TODO(szym): This will change once http://crbug.com/114827 is fixed. |
1782 if (had_factory) | 1789 if (had_factory) |
1783 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_SETTINGS); | 1790 OnDNSChanged(NetworkChangeNotifier::CHANGE_DNS_SETTINGS); |
1784 } | 1791 } |
1785 | 1792 |
1786 } // namespace net | 1793 } // namespace net |
OLD | NEW |