diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-13 18:00:56 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-13 18:00:56 +0000 |
commit | fb2622f6816ed20ffd8a35994f7372b67613ba92 (patch) | |
tree | 2aa33016e72361032264904916c4374e4784fd11 /net/http | |
parent | ea9a4ee67732b90e834def1cf98be1d047a93063 (diff) | |
download | chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.zip chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.gz chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.bz2 |
Disk cache: Switch the disk cache to use the cache_thread.
Add an InFlightBackendIO class that handles posting of
cacheoperations back and forth between the IO thread and
the cachethread.
BUG=26730
TEST=unit tests
Review URL: http://codereview.chromium.org/2945002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 1 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 34 |
2 files changed, 32 insertions, 3 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 7e73d94..3758a51 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -902,6 +902,7 @@ void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { if (op == WI_CREATE_ENTRY) pending_op->disk_entry->Doom(); pending_op->disk_entry->Close(); + pending_op->disk_entry = NULL; fail_requests = true; } } diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index f48899c..dc114da 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -369,9 +369,7 @@ class MockDiskCache : public disk_cache::Backend { } ~MockDiskCache() { - EntryMap::iterator it = entries_.begin(); - for (; it != entries_.end(); ++it) - it->second->Release(); + ReleaseAll(); } virtual int32 GetEntryCount() const { @@ -496,6 +494,13 @@ class MockDiskCache : public disk_cache::Backend { // Return entries that fail some of their requests. void set_soft_failures(bool value) { soft_failures_ = value; } + void ReleaseAll() { + EntryMap::iterator it = entries_.begin(); + for (; it != entries_.end(); ++it) + it->second->Release(); + entries_.clear(); + } + private: typedef base::hash_map<std::string, MockDiskEntry*> EntryMap; @@ -1720,6 +1725,29 @@ TEST(HttpCache, SimpleGET_ManyWriters_CancelCreate) { } } +// Tests that we can cancel a single request to open a disk cache entry. +TEST(HttpCache, SimpleGET_CancelCreate) { + MockHttpCache cache; + + MockHttpRequest request(kSimpleGET_Transaction); + + Context* c = new Context(); + + c->result = cache.http_cache()->CreateTransaction(&c->trans); + EXPECT_EQ(net::OK, c->result); + + c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); + EXPECT_EQ(net::ERR_IO_PENDING, c->result); + + // Release the reference that the mock disk cache keeps for this entry, so + // that we test that the http cache handles the cancelation correctly. + cache.disk_cache()->ReleaseAll(); + delete c; + + MessageLoop::current()->RunAllPending(); + EXPECT_EQ(1, cache.disk_cache()->create_count()); +} + // Tests that we delete/create entries even if multiple requests are queued. TEST(HttpCache, SimpleGET_ManyWriters_BypassCache) { MockHttpCache cache; |