summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/http/http_cache.cc17
-rw-r--r--net/http/http_cache_unittest.cc31
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;