Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 9572018: [net] Ensure aborted HostResolverImpl::Jobs release slots in the dispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 had_non_speculative_request_(false), 1070 had_non_speculative_request_(false),
1071 net_log_(BoundNetLog::Make(request_net_log.net_log(), 1071 net_log_(BoundNetLog::Make(request_net_log.net_log(),
1072 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { 1072 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) {
1073 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, NULL); 1073 request_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB, NULL);
1074 1074
1075 net_log_.BeginEvent( 1075 net_log_.BeginEvent(
1076 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, 1076 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB,
1077 make_scoped_refptr(new JobCreationParameters( 1077 make_scoped_refptr(new JobCreationParameters(
1078 key_.hostname, request_net_log.source()))); 1078 key_.hostname, request_net_log.source())));
1079 1079
1080 handle_ = resolver_->dispatcher_.Add(this, priority); 1080 handle_ = resolver_->dispatcher_.Add(this, priority);
cbentzel 2012/03/02 19:45:27 One concern is that this could call Job::Dispatch
1081 } 1081 }
1082 1082
1083 virtual ~Job() { 1083 virtual ~Job() {
1084 if (is_running()) { 1084 if (is_running()) {
1085 // |resolver_| was destroyed with this Job still in flight. 1085 // |resolver_| was destroyed with this Job still in flight.
1086 // Clean-up, record in the log, but don't run any callbacks. 1086 // Clean-up, record in the log, but don't run any callbacks.
1087 if (is_proc_running()) { 1087 if (is_proc_running()) {
1088 proc_task_->Cancel(); 1088 proc_task_->Cancel();
1089 proc_task_ = NULL; 1089 proc_task_ = NULL;
1090 } 1090 }
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()) {
1576 dispatcher_.OnJobFinished();
cbentzel 2012/03/02 19:05:02 Does the ordering here matter? It's different in t
szym 2012/03/02 19:09:30 I feel that the preferred order is Abort then disp
1576 job->Abort(); 1577 job->Abort();
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 Job* job = it->second; 1719 Job* job = it->second;
1718 if (job->is_running()) { 1720 if (job->is_running()) {
1719 jobs_to_abort.push_back(job); 1721 jobs_to_abort.push_back(job);
1720 jobs_.erase(it++); 1722 jobs_.erase(it++);
1721 } else { 1723 } else {
1722 DCHECK(job->is_queued()); 1724 DCHECK(job->is_queued());
1723 ++it; 1725 ++it;
1724 } 1726 }
1725 } 1727 }
1726 1728
1729 // Check if no dispatcher slots leaked out.
1730 DCHECK_EQ(dispatcher_.num_running_jobs(), jobs_to_abort.size());
1731
1727 // Then Abort them and dispatch new Jobs. 1732 // Then Abort them and dispatch new Jobs.
1728 for (size_t i = 0; i < jobs_to_abort.size(); ++i) { 1733 for (size_t i = 0; i < jobs_to_abort.size(); ++i) {
1729 jobs_to_abort[i]->Abort(); 1734 jobs_to_abort[i]->Abort();
1735 if (!self)
1736 break; // |this| got destroyed in a request callback.
1730 dispatcher_.OnJobFinished(); 1737 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();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | net/base/host_resolver_impl_unittest.cc » ('j') | net/base/host_resolver_impl_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698