| Index: net/disk_cache/v3/block_bitmaps.cc
|
| ===================================================================
|
| --- net/disk_cache/v3/block_bitmaps.cc (revision 232523)
|
| +++ net/disk_cache/v3/block_bitmaps.cc (working copy)
|
| @@ -5,15 +5,21 @@
|
| #include "net/disk_cache/v3/block_bitmaps.h"
|
|
|
| #include "base/metrics/histogram.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/threading/thread_checker.h"
|
| #include "base/time/time.h"
|
| +#include "net/disk_cache/cache_util.h"
|
| #include "net/disk_cache/disk_format_base.h"
|
| +#include "net/disk_cache/file_lock.h"
|
| #include "net/disk_cache/trace.h"
|
| +#include "net/disk_cache/v3/backend_impl_v3.h"
|
|
|
| using base::TimeTicks;
|
|
|
| namespace disk_cache {
|
|
|
| -BlockBitmaps::BlockBitmaps() {
|
| +BlockBitmaps::BlockBitmaps(BackendImplV3* backend) : backend_(backend) {
|
| }
|
|
|
| BlockBitmaps::~BlockBitmaps() {
|
| @@ -21,6 +27,8 @@
|
|
|
| void BlockBitmaps::Init(const BlockFilesBitmaps& bitmaps) {
|
| bitmaps_ = bitmaps;
|
| + for (int i = 0; i < kFirstAdditionalBlockFileV3; i++)
|
| + empty_counts_[i] = EmptyBlocksForType(i);
|
| }
|
|
|
| bool BlockBitmaps::CreateBlock(FileType block_type,
|
| @@ -35,6 +43,8 @@
|
| if (header_num < 0)
|
| return false;
|
|
|
| + int old_num_allocations = bitmaps_[header_num].MinimumAllocations();
|
| +
|
| int index;
|
| if (!bitmaps_[header_num].CreateMapBlock(block_count, &index))
|
| return false;
|
| @@ -45,6 +55,13 @@
|
| return false;
|
| }
|
|
|
| + // Yes, the count may be off by 1 when we start.
|
| + if (old_num_allocations != bitmaps_[header_num].MinimumAllocations())
|
| + empty_counts_[block_type]--;
|
| +
|
| + if (empty_counts_[block_type] < (kNumExtraBlocks / kMaxNumBlocks) / 2)
|
| + backend_->GrowBlockFiles();
|
| +
|
| Addr address(block_type, block_count, bitmaps_[header_num].FileId(), index);
|
| block_address->set_value(address.value());
|
| Trace("CreateBlock 0x%x", address.value());
|
| @@ -62,6 +79,14 @@
|
| Trace("DeleteBlock 0x%x", address.value());
|
| bitmaps_[header_num].DeleteMapBlock(address.start_block(),
|
| address.num_blocks());
|
| +
|
| + //if (!bitmaps_[header_num].Header()->num_entries) {
|
| + // This file is now empty. Let's try to delete it.
|
| + //FileType type = Addr::RequiredFileType(header->entry_size);
|
| + //if (Addr::BlockSizeForFileType(RANKINGS) == header->entry_size)
|
| + // type = RANKINGS;
|
| + //RemoveEmptyFile(type); // Ignore failures.
|
| + //}
|
| }
|
|
|
| void BlockBitmaps::Clear() {
|
| @@ -116,6 +141,15 @@
|
| return file_index;
|
| }
|
|
|
| +int BlockBitmaps::EmptyBlocksForType(int next_file) {
|
| + int empty_blocks = 0;
|
| + do {
|
| + empty_blocks += bitmaps_[next_file].MinimumAllocations();
|
| + next_file = bitmaps_[next_file].NextFileId();
|
| + } while (next_file);
|
| + return empty_blocks;
|
| +}
|
| +
|
| int BlockBitmaps::HeaderNumberForNewBlock(FileType block_type,
|
| int block_count) {
|
| DCHECK_GT(block_type, 0);
|
| @@ -144,8 +178,10 @@
|
| header_num = bitmaps_[header_num].NextFileId();
|
| } while (header_num);
|
|
|
| - if (!found)
|
| + if (!found) {
|
| + NOTREACHED();
|
| header_num = -1;
|
| + }
|
| }
|
|
|
| HISTOGRAM_TIMES("DiskCache.GetFileForNewBlock", TimeTicks::Now() - start);
|
|
|