diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-08 00:56:01 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-08 00:56:01 +0000 |
commit | a9af7114711a226501ee857ff2726a1af2866d81 (patch) | |
tree | 855636f1ec4fab581ff729dd6059a8d01bc40734 /net | |
parent | 73e3153285771e84abaf5afab329d10078a9b201 (diff) | |
download | chromium_src-a9af7114711a226501ee857ff2726a1af2866d81.zip chromium_src-a9af7114711a226501ee857ff2726a1af2866d81.tar.gz chromium_src-a9af7114711a226501ee857ff2726a1af2866d81.tar.bz2 |
Fix IPv6 probe class to better handle cancellation of the job.
The code did not handle cancellation properly, and DCHECKs
were firing. Recrafted code to avoid checking for runs
"on origin_thread" after a cancellation (which destroys
the record of the orgin_thread_).
BUG=43600
r=willchan
Review URL: http://codereview.chromium.org/2050002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46769 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/host_resolver_impl.cc | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index f901144..1b5eb78 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "net/base/host_resolver_impl.h" -#include "net/base/net_log.h" #include <cmath> #include <deque> @@ -434,9 +433,12 @@ class HostResolverImpl::IPv6ProbeJob explicit IPv6ProbeJob(HostResolverImpl* resolver) : resolver_(resolver), origin_loop_(MessageLoop::current()) { + DCHECK(!was_cancelled()); } void Start() { + if (was_cancelled()) + return; DCHECK(IsOnOriginThread()); const bool kIsSlow = true; WorkerPool::PostTask( @@ -445,26 +447,33 @@ class HostResolverImpl::IPv6ProbeJob // Cancels the current job. void Cancel() { + if (was_cancelled()) + return; DCHECK(IsOnOriginThread()); resolver_ = NULL; // Read/write ONLY on origin thread. { AutoLock locked(origin_loop_lock_); // Origin loop may be destroyed before we can use it! - origin_loop_ = NULL; + origin_loop_ = NULL; // Write ONLY on origin thread. } } - bool was_cancelled() const { - DCHECK(IsOnOriginThread()); - return resolver_ == NULL; - } - private: friend class base::RefCountedThreadSafe<HostResolverImpl::IPv6ProbeJob>; ~IPv6ProbeJob() { } + // Should be run on |orgin_thread_|, but that may not be well defined now. + bool was_cancelled() const { + if (!resolver_ || !origin_loop_) { + DCHECK(!resolver_); + DCHECK(!origin_loop_); + return true; + } + return false; + } + // Run on worker thread. void DoProbe() { // Do actual testing on this thread, as it takes 40-100ms. @@ -490,9 +499,10 @@ class HostResolverImpl::IPv6ProbeJob // Callback for when DoProbe() completes (runs on origin thread). void OnProbeComplete(AddressFamily address_family) { + if (was_cancelled()) + return; DCHECK(IsOnOriginThread()); - if (!was_cancelled()) - resolver_->IPv6ProbeSetDefaultAddressFamily(address_family); + resolver_->IPv6ProbeSetDefaultAddressFamily(address_family); } bool IsOnOriginThread() const { |