OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 uint32 to_add = ((1 << size) - 1) << index_offset; | 59 uint32 to_add = ((1 << size) - 1) << index_offset; |
60 header->allocation_map[current] |= to_add; | 60 header->allocation_map[current] |= to_add; |
61 | 61 |
62 header->hints[target - 1] = current; | 62 header->hints[target - 1] = current; |
63 header->empty[target - 1]--; | 63 header->empty[target - 1]--; |
64 DCHECK(header->empty[target - 1] >= 0); | 64 DCHECK(header->empty[target - 1] >= 0); |
65 header->num_entries++; | 65 header->num_entries++; |
66 if (target != size) { | 66 if (target != size) { |
67 header->empty[target - size - 1]++; | 67 header->empty[target - size - 1]++; |
68 } | 68 } |
69 HISTOGRAM_TIMES(L"DiskCache.CreateBlock", Time::Now() - start); | 69 HISTOGRAM_TIMES("DiskCache.CreateBlock", Time::Now() - start); |
70 return true; | 70 return true; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 // It is possible to have an undetected corruption (for example when the OS | 74 // It is possible to have an undetected corruption (for example when the OS |
75 // crashes), fix it here. | 75 // crashes), fix it here. |
76 LOG(ERROR) << "Failing CreateMapBlock"; | 76 LOG(ERROR) << "Failing CreateMapBlock"; |
77 FixAllocationCounters(header); | 77 FixAllocationCounters(header); |
78 return false; | 78 return false; |
79 } | 79 } |
(...skipping 27 matching lines...) Expand all Loading... |
107 byte_map[byte_index] &= ~to_clear; | 107 byte_map[byte_index] &= ~to_clear; |
108 | 108 |
109 if (update_counters) { | 109 if (update_counters) { |
110 if (bits_at_end) | 110 if (bits_at_end) |
111 header->empty[bits_at_end - 1]--; | 111 header->empty[bits_at_end - 1]--; |
112 header->empty[new_type - 1]++; | 112 header->empty[new_type - 1]++; |
113 DCHECK(header->empty[bits_at_end - 1] >= 0); | 113 DCHECK(header->empty[bits_at_end - 1] >= 0); |
114 } | 114 } |
115 header->num_entries--; | 115 header->num_entries--; |
116 DCHECK(header->num_entries >= 0); | 116 DCHECK(header->num_entries >= 0); |
117 HISTOGRAM_TIMES(L"DiskCache.DeleteBlock", Time::Now() - start); | 117 HISTOGRAM_TIMES("DiskCache.DeleteBlock", Time::Now() - start); |
118 } | 118 } |
119 | 119 |
120 // Restores the "empty counters" and allocation hints. | 120 // Restores the "empty counters" and allocation hints. |
121 void FixAllocationCounters(disk_cache::BlockFileHeader* header) { | 121 void FixAllocationCounters(disk_cache::BlockFileHeader* header) { |
122 for (int i = 0; i < disk_cache::kMaxNumBlocks; i++) { | 122 for (int i = 0; i < disk_cache::kMaxNumBlocks; i++) { |
123 header->hints[i] = 0; | 123 header->hints[i] = 0; |
124 header->empty[i] = 0; | 124 header->empty[i] = 0; |
125 } | 125 } |
126 | 126 |
127 for (int i = 0; i < header->max_entries / 32; i++) { | 127 for (int i = 0; i < header->max_entries / 32; i++) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if (!file) | 316 if (!file) |
317 return NULL; | 317 return NULL; |
318 header = reinterpret_cast<BlockFileHeader*>(file->buffer()); | 318 header = reinterpret_cast<BlockFileHeader*>(file->buffer()); |
319 continue; | 319 continue; |
320 } | 320 } |
321 | 321 |
322 if (!GrowBlockFile(file, header)) | 322 if (!GrowBlockFile(file, header)) |
323 return NULL; | 323 return NULL; |
324 break; | 324 break; |
325 } | 325 } |
326 HISTOGRAM_TIMES(L"DiskCache.GetFileForNewBlock", Time::Now() - start); | 326 HISTOGRAM_TIMES("DiskCache.GetFileForNewBlock", Time::Now() - start); |
327 return file; | 327 return file; |
328 } | 328 } |
329 | 329 |
330 MappedFile* BlockFiles::NextFile(const MappedFile* file) { | 330 MappedFile* BlockFiles::NextFile(const MappedFile* file) { |
331 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer()); | 331 BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer()); |
332 int new_file = header->next_file; | 332 int new_file = header->next_file; |
333 if (!new_file) { | 333 if (!new_file) { |
334 // RANKINGS is not reported as a type for small entries, but we may be | 334 // RANKINGS is not reported as a type for small entries, but we may be |
335 // extending the rankings block file. | 335 // extending the rankings block file. |
336 FileType type = Addr::RequiredFileType(header->entry_size); | 336 FileType type = Addr::RequiredFileType(header->entry_size); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 int num_entries = (file_size - sizeof(*header)) / header->entry_size; | 430 int num_entries = (file_size - sizeof(*header)) / header->entry_size; |
431 header->max_entries = num_entries; | 431 header->max_entries = num_entries; |
432 } | 432 } |
433 | 433 |
434 FixAllocationCounters(header); | 434 FixAllocationCounters(header); |
435 header->updating = 0; | 435 header->updating = 0; |
436 return true; | 436 return true; |
437 } | 437 } |
438 | 438 |
439 } // namespace disk_cache | 439 } // namespace disk_cache |
OLD | NEW |