~abreu-alexandre/oxide/add-ua-to-downloadrequested

« back to all changes in this revision

Viewing changes to patches/store-cache-stats-at-startup.patch

  • Committer: Chris Coulson
  • Date: 2014-09-23 21:36:22 UTC
  • Revision ID: chris.coulson@canonical.com-20140923213622-9pc96fe9d2pz74ko
Store the cache stats to disk as soon as a fresh cache is created

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
7
 
 
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);
 
15
 
 
16
     if (!CreateBlock(file_type, num_blocks, &address))
 
17
       return false;
 
18
 
 
19
     data_->header.stats = address.value();
 
20
-    return stats_.Init(NULL, 0, address);
 
21
+    if (!stats_.Init(NULL, 0, address))
 
22
+      return false;
 
23
+
 
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)
 
28
+    StoreStats();
 
29
+
 
30
+    return true;
 
31
   }
 
32
 
 
33
   if (!address.is_block_file()) {
 
34
     NOTREACHED();
 
35
     return false;
 
36
   }
 
37
 
 
38
   // Load the required data.