Chromium Code Reviews| Index: net/disk_cache/block_files.cc |
| =================================================================== |
| --- net/disk_cache/block_files.cc (revision 208996) |
| +++ net/disk_cache/block_files.cc (working copy) |
| @@ -177,7 +177,7 @@ |
| } |
| } |
| -bool BlockHeader::NeedToGrowBlockFile(int block_count) { |
| +bool BlockHeader::NeedToGrowBlockFile(int block_count) const { |
| bool have_space = false; |
| int empty_blocks = 0; |
| for (int i = 0; i < kMaxNumBlocks; i++) { |
| @@ -195,6 +195,18 @@ |
| return !have_space; |
| } |
| +bool BlockHeader::CanAllocate(int block_count) const { |
| + bool have_space = false; |
| + int empty_blocks = 0; |
| + for (int i = 0; i < kMaxNumBlocks; i++) { |
| + empty_blocks += header_->empty[i] * (i + 1); |
| + if (i >= (block_count - 1) && header_->empty[i]) |
| + have_space = true; |
| + } |
| + |
| + return have_space; |
| +} |
| + |
| int BlockHeader::EmptyBlocks() const { |
| int empty_blocks = 0; |
| for (int i = 0; i < disk_cache::kMaxNumBlocks; i++) { |
| @@ -260,7 +272,7 @@ |
| MappedFile* BlockFiles::GetFile(Addr address) { |
| DCHECK(thread_checker_->CalledOnValidThread()); |
| - DCHECK(block_files_.size() >= 4); |
| + DCHECK(block_files_.size() >= kFirstAdditionalBlockFile); |
|
gavinp
2013/06/28 21:47:45
Nit: Consider using the DCHECK_LE macro here, and
rvargas (doing something else)
2013/07/11 19:54:55
Already changed
|
| DCHECK(address.is_block_file() || !address.is_initialized()); |
| if (!address.is_initialized()) |
| return NULL; |
| @@ -280,8 +292,9 @@ |
| Addr* block_address) { |
| DCHECK(thread_checker_->CalledOnValidThread()); |
| if (block_type < RANKINGS || block_type > BLOCK_4K || |
| - block_count < 1 || block_count > 4) |
| + block_count < 1 || block_count > kMaxNumBlocks) { |
| return false; |
| + } |
| if (!init_) |
| return false; |
| @@ -293,7 +306,7 @@ |
| BlockHeader header(file); |
| int target_size = 0; |
| - for (int i = block_count; i <= 4; i++) { |
| + for (int i = block_count; i <= kMaxNumBlocks; i++) { |
| if (header->empty[i - 1]) { |
| target_size = i; |
| break; |
| @@ -671,7 +684,7 @@ |
| max_blocks += header->max_entries; |
| int used = header->max_entries; |
| - for (int i = 0; i < 4; i++) { |
| + for (int i = 0; i < kMaxNumBlocks; i++) { |
| used -= header->empty[i] * (i + 1); |
| DCHECK_GE(used, 0); |
| } |