1
# Description: Store the cache stats to disk immediately when a new cache is
2
# created. As this normally only happens on a clean shutdown or every 5
3
# minutes, the cache stats will never be stored if the application exits
4
# uncleanly within 5 minutes. On a subsequent startup, disk_cache::VerifyStats
5
# will fail the signature check, causing the cache to be recreated
6
# Author: Chris Coulson <chris.coulson@canonical.com>
8
diff --git a/net/disk_cache/blockfile/backend_impl.cc b/net/disk_cache/blockfile/backend_impl.cc
9
--- a/net/disk_cache/blockfile/backend_impl.cc
10
+++ b/net/disk_cache/blockfile/backend_impl.cc
11
@@ -1395,17 +1395,26 @@ bool BackendImpl::InitStats() {
12
FileType file_type = Addr::RequiredFileType(size);
13
DCHECK_NE(file_type, EXTERNAL);
14
int num_blocks = Addr::RequiredBlocks(size, file_type);
16
if (!CreateBlock(file_type, num_blocks, &address))
19
data_->header.stats = address.value();
20
- return stats_.Init(NULL, 0, address);
21
+ if (!stats_.Init(NULL, 0, address))
24
+ // Stats are only saved to disk on shutdown or every 5 minutes. If we don't
25
+ // do this now, then exiting uncleanly within 5 minutes if the cache is
26
+ // newly created will result in it failing to load next time (the signature
27
+ // check in VerifyStats() will fail)
33
if (!address.is_block_file()) {
38
// Load the required data.