summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 23:42:06 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 23:42:06 +0000
commit35ddc28bf53375afe7a537cc5744dd1c354291f6 (patch)
treeaeb1533db062be63010c4738a4f1889bc23c12ed
parent79297e50bc383232cf53c4ac2323db28193c58f4 (diff)
downloadchromium_src-35ddc28bf53375afe7a537cc5744dd1c354291f6.zip
chromium_src-35ddc28bf53375afe7a537cc5744dd1c354291f6.tar.gz
chromium_src-35ddc28bf53375afe7a537cc5744dd1c354291f6.tar.bz2
HostResolver should flush the JobPools on a network change.
BUG=56291 TEST=HostResolverImplTest.ObeyPoolConstraintsAfterIPAddressChange Review URL: http://codereview.chromium.org/3431017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60127 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/host_resolver_impl.cc12
-rw-r--r--net/base/host_resolver_impl.h4
-rw-r--r--net/base/host_resolver_impl_unittest.cc37
-rw-r--r--net/base/mock_host_resolver.h7
4 files changed, 55 insertions, 5 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index 65f0b53..c359ff8 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -759,6 +759,10 @@ class HostResolverImpl::JobPool {
num_outstanding_jobs_ += offset;
}
+ void ResetNumOutstandingJobs() {
+ num_outstanding_jobs_ = 0;
+ }
+
// Returns true if a new job can be created for this pool.
bool CanCreateJob() const {
return num_outstanding_jobs_ + 1u <= max_outstanding_jobs_;
@@ -1223,8 +1227,8 @@ void HostResolverImpl::OnIPAddressChanged() {
additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
}
#endif
- AbortAllJobs();
- // |this| may be deleted inside AbortAllJobs().
+ AbortAllInProgressJobs();
+ // |this| may be deleted inside AbortAllInProgressJobs().
}
void HostResolverImpl::DiscardIPv6ProbeJob() {
@@ -1348,7 +1352,9 @@ void HostResolverImpl::CancelAllJobs() {
it->second->Cancel();
}
-void HostResolverImpl::AbortAllJobs() {
+void HostResolverImpl::AbortAllInProgressJobs() {
+ for (size_t i = 0; i < arraysize(job_pools_); ++i)
+ job_pools_[i]->ResetNumOutstandingJobs();
JobMap jobs;
jobs.swap(jobs_);
for (JobMap::iterator it = jobs.begin(); it != jobs.end(); ++it) {
diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h
index 58d8598..b1002ab 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -222,8 +222,8 @@ class HostResolverImpl : public HostResolver,
// Cancels all jobs.
void CancelAllJobs();
- // Aborts all jobs.
- void AbortAllJobs();
+ // Aborts all in progress jobs (but might start new ones).
+ void AbortAllInProgressJobs();
// Cache of host resolution results.
scoped_ptr<HostCache> cache_;
diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc
index fb5b5dc..233ee21 100644
--- a/net/base/host_resolver_impl_unittest.cc
+++ b/net/base/host_resolver_impl_unittest.cc
@@ -1130,6 +1130,43 @@ TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) {
EXPECT_EQ(0u, cache->size());
}
+// Obey pool constraints after IP address has changed.
+TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) {
+ scoped_refptr<WaitingHostResolverProc> resolver_proc =
+ new WaitingHostResolverProc(NULL);
+ scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver());
+ host_resolver->Reset(resolver_proc);
+
+ const size_t kMaxOutstandingJobs = 1u;
+ const size_t kMaxPendingRequests = 1000000u; // not relevant.
+ host_resolver->SetPoolConstraints(HostResolverImpl::POOL_NORMAL,
+ kMaxOutstandingJobs,
+ kMaxPendingRequests);
+
+ // Resolve "host1".
+ HostResolver::RequestInfo info(HostPortPair("host1", 70));
+ TestCompletionCallback callback;
+ AddressList addrlist;
+ int rv = host_resolver->Resolve(info, &addrlist, &callback, NULL,
+ BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ // Triggering an IP address change.
+ NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
+ MessageLoop::current()->RunAllPending(); // Notification happens async.
+ resolver_proc->Signal();
+
+ EXPECT_EQ(ERR_ABORTED, callback.WaitForResult());
+
+ // Don't bother with WaitingHostResolverProc anymore.
+ host_resolver->Reset(NULL);
+
+ rv = host_resolver->Resolve(info, &addrlist, &callback, NULL,
+ BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+}
+
class ResolveWithinCallback : public CallbackRunner< Tuple1<int> > {
public:
ResolveWithinCallback(
diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h
index 865c918..4b185b2 100644
--- a/net/base/mock_host_resolver.h
+++ b/net/base/mock_host_resolver.h
@@ -59,6 +59,13 @@ class MockHostResolverBase : public HostResolver {
// Resets the mock.
void Reset(HostResolverProc* interceptor);
+ void SetPoolConstraints(HostResolverImpl::JobPoolIndex pool_index,
+ size_t max_outstanding_jobs,
+ size_t max_pending_requests) {
+ impl_->SetPoolConstraints(
+ pool_index, max_outstanding_jobs, max_pending_requests);
+ }
+
protected:
MockHostResolverBase(bool use_caching);
virtual ~MockHostResolverBase() {}