diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-17 00:29:25 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-17 00:29:25 +0000 |
commit | e86e79d31b18a6a32e4bd2bf470c72a20b9815ca (patch) | |
tree | cb5a74589af9a1424bd867f5ab4f93b2c8b2c2b3 /net | |
parent | 731321382230f99f91a9e46917eb64691583f65b (diff) | |
download | chromium_src-e86e79d31b18a6a32e4bd2bf470c72a20b9815ca.zip chromium_src-e86e79d31b18a6a32e4bd2bf470c72a20b9815ca.tar.gz chromium_src-e86e79d31b18a6a32e4bd2bf470c72a20b9815ca.tar.bz2 |
Http Cache: Don't delete the callback that is waiting for
the backend creation when the cache goes away.
BUG=49193
TEST=net_unittests
Review URL: http://codereview.chromium.org/3016006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52776 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_cache.cc | 17 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 31 |
2 files changed, 46 insertions, 2 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index fb89928..552d9c4 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -134,10 +134,15 @@ class HttpCache::BackendCallback : public CallbackRunner<Tuple1<int> > { ~BackendCallback() {} virtual void RunWithParams(const Tuple1<int>& params) { - cache_->OnIOComplete(params.a, pending_op_); + if (cache_) + cache_->OnIOComplete(params.a, pending_op_); delete this; } + void Cancel() { + cache_ = NULL; + } + private: HttpCache* cache_; PendingOp* pending_op_; @@ -283,7 +288,15 @@ HttpCache::~HttpCache() { // though they are waiting for a callback that will never fire. PendingOp* pending_op = pending_it->second; delete pending_op->writer; - delete pending_op->callback; + if (building_backend_) { + // If we don't have a backend, when its construction finishes it will + // deliver the callbacks. + BackendCallback* callback = + static_cast<BackendCallback*>(pending_op->callback); + callback->Cancel(); + } else { + delete pending_op->callback; + } STLDeleteElements(&pending_op->pending_queue); delete pending_op; diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index a6f63d2..c3ee0a0 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -667,6 +667,8 @@ class MockBlockingBackendFactory : public net::HttpCache::BackendFactory { void set_fail(bool fail) { fail_ = fail; } + net::CompletionCallback* callback() { return callback_; } + private: int Result() { return fail_ ? net::ERR_FAILED : net::OK; } @@ -1979,6 +1981,35 @@ TEST(HttpCache, SimpleGET_WaitForBackend_CancelCreate) { delete context_list[2]; } +// Tests that we can delete the cache while creating the backend. +TEST(HttpCache, DeleteCacheWaitingForBackend) { + MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); + scoped_ptr<MockHttpCache> cache(new MockHttpCache(factory)); + + MockHttpRequest request(kSimpleGET_Transaction); + + scoped_ptr<Context> c(new Context()); + c->result = cache->http_cache()->CreateTransaction(&c->trans); + EXPECT_EQ(net::OK, c->result); + + c->trans->Start(&request, &c->callback, net::BoundNetLog()); + + // Just to make sure that everything is still pending. + MessageLoop::current()->RunAllPending(); + + // The request should be creating the disk cache. + EXPECT_FALSE(c->callback.have_result()); + + // We cannot call FinishCreation because the factory itself will go away with + // the cache, so grab the callback and attempt to use it. + net::CompletionCallback* callback = factory->callback(); + + cache.reset(); + MessageLoop::current()->RunAllPending(); + + callback->Run(net::ERR_ABORTED); +} + TEST(HttpCache, TypicalGET_ConditionalRequest) { MockHttpCache cache; |