Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: net/disk_cache/block_files.cc

Issue 8065015: Disk Cache: Improve handling of dirty entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/disk_cache/block_files.h" 5 #include "net/disk_cache/block_files.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (!zero_buffer_) { 280 if (!zero_buffer_) {
281 zero_buffer_ = new char[Addr::BlockSizeForFileType(BLOCK_4K) * 4]; 281 zero_buffer_ = new char[Addr::BlockSizeForFileType(BLOCK_4K) * 4];
282 memset(zero_buffer_, 0, Addr::BlockSizeForFileType(BLOCK_4K) * 4); 282 memset(zero_buffer_, 0, Addr::BlockSizeForFileType(BLOCK_4K) * 4);
283 } 283 }
284 MappedFile* file = GetFile(address); 284 MappedFile* file = GetFile(address);
285 if (!file) 285 if (!file)
286 return; 286 return;
287 287
288 Trace("DeleteBlock 0x%x", address.value()); 288 Trace("DeleteBlock 0x%x", address.value());
289 289
290 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
291 DeleteMapBlock(address.start_block(), address.num_blocks(), header);
292
293 size_t size = address.BlockSize() * address.num_blocks(); 290 size_t size = address.BlockSize() * address.num_blocks();
294 size_t offset = address.start_block() * address.BlockSize() + 291 size_t offset = address.start_block() * address.BlockSize() +
295 kBlockHeaderSize; 292 kBlockHeaderSize;
296 if (deep) 293 if (deep)
297 file->Write(zero_buffer_, size, offset); 294 file->Write(zero_buffer_, size, offset);
298 295
296 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
297 DeleteMapBlock(address.start_block(), address.num_blocks(), header);
298
299 if (!header->num_entries) { 299 if (!header->num_entries) {
300 // This file is now empty. Let's try to delete it. 300 // This file is now empty. Let's try to delete it.
301 FileType type = Addr::RequiredFileType(header->entry_size); 301 FileType type = Addr::RequiredFileType(header->entry_size);
302 if (Addr::BlockSizeForFileType(RANKINGS) == header->entry_size) 302 if (Addr::BlockSizeForFileType(RANKINGS) == header->entry_size)
303 type = RANKINGS; 303 type = RANKINGS;
304 RemoveEmptyFile(type); 304 RemoveEmptyFile(type);
305 } 305 }
306 } 306 }
307 307
308 void BlockFiles::CloseFiles() { 308 void BlockFiles::CloseFiles() {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 618 }
619 619
620 FilePath BlockFiles::Name(int index) { 620 FilePath BlockFiles::Name(int index) {
621 // The file format allows for 256 files. 621 // The file format allows for 256 files.
622 DCHECK(index < 256 || index >= 0); 622 DCHECK(index < 256 || index >= 0);
623 std::string tmp = base::StringPrintf("%s%d", kBlockName, index); 623 std::string tmp = base::StringPrintf("%s%d", kBlockName, index);
624 return path_.AppendASCII(tmp); 624 return path_.AppendASCII(tmp);
625 } 625 }
626 626
627 } // namespace disk_cache 627 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698