diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:13:57 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:13:57 +0000 |
commit | 790656e31f441404fa57944ca1a69890052a7828 (patch) | |
tree | 37e5c7a8bdc2eea8044c8eda4d5fdd9d253694ae /net/disk_cache | |
parent | e741b941959feba1e0d7317aefad6f948219dc8a (diff) | |
download | chromium_src-790656e31f441404fa57944ca1a69890052a7828.zip chromium_src-790656e31f441404fa57944ca1a69890052a7828.tar.gz chromium_src-790656e31f441404fa57944ca1a69890052a7828.tar.bz2 |
Fixing bugs in sparse cache when dealing with GetAvailableRange queries not aligned
TEST=net_unittests --gtest_filter=DiskCacheEntryTest.PartialSparseEntry
In handling GetAvailableRange() queries, if the start offset is not aligned to 1KB,
there was some strange behaviors:
1. The start offset found is smaller than the input offset
2. Number of continus bytes doesn't take into account offset in a block.
This patch will fix the above problems.
Review URL: http://codereview.chromium.org/186002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25225 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 15 | ||||
-rw-r--r-- | net/disk_cache/sparse_control.cc | 14 |
2 files changed, 24 insertions, 5 deletions
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index f65f593..dbd4f82 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -1256,6 +1256,21 @@ void DiskCacheEntryTest::PartialSparseEntry() { EXPECT_EQ(3616, entry->GetAvailableRange(20 * 1024, 10000, &start)); EXPECT_EQ(20 * 1024, start); + // 1. Query before a filled 1KB block. + // 2. Query within a filled 1KB block. + // 3. Query beyond a filled 1KB block. + if (memory_only_) { + EXPECT_EQ(3496, entry->GetAvailableRange(19400, kSize, &start)); + EXPECT_EQ(20000, start); + } else { + EXPECT_EQ(3016, entry->GetAvailableRange(19400, kSize, &start)); + EXPECT_EQ(20480, start); + } + EXPECT_EQ(1523, entry->GetAvailableRange(3073, kSize, &start)); + EXPECT_EQ(3073, start); + EXPECT_EQ(0, entry->GetAvailableRange(4600, kSize, &start)); + EXPECT_EQ(4600, start); + // Now make another write and verify that there is no hole in between. EXPECT_EQ(kSize, entry->WriteSparseData(500 + kSize, buf1, kSize, NULL)); EXPECT_EQ(7 * 1024 + 500, entry->GetAvailableRange(1024, 10000, &start)); diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc index d2e66d9..7648f4e 100644 --- a/net/disk_cache/sparse_control.cc +++ b/net/disk_cache/sparse_control.cc @@ -620,7 +620,8 @@ int SparseControl::DoGetAvailableRange() { int last_bit = (child_offset_ + child_len_ + 1023) >> 10; int start = child_offset_ >> 10; int partial_start_bytes = PartialBlockLength(start); - int bits_found = child_map_.FindBits(&start, last_bit, true); + int found = start; + int bits_found = child_map_.FindBits(&found, last_bit, true); // We don't care if there is a partial block in the middle of the range. int block_offset = child_offset_ & (kBlockSize - 1); @@ -630,15 +631,18 @@ int SparseControl::DoGetAvailableRange() { // We are done. Just break the loop and reset result_ to our real result. range_found_ = true; - // start now points to the first 1. Lets see if we have zeros before it. - int empty_start = (start << 10) - child_offset_; + // found now points to the first 1. Lets see if we have zeros before it. + int empty_start = std::max((found << 10) - child_offset_, 0); int bytes_found = bits_found << 10; - bytes_found += PartialBlockLength(start + bits_found); + bytes_found += PartialBlockLength(found + bits_found); + + if (start == found) + bytes_found -= block_offset; // If the user is searching past the end of this child, bits_found is the // right result; otherwise, we have some empty space at the start of this - // query that we have to substarct from the range that we searched. + // query that we have to subtract from the range that we searched. result_ = std::min(bytes_found, child_len_ - empty_start); if (!bits_found) { |