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

Side by Side Diff: net/disk_cache/simple/simple_index_file.h

Issue 22927018: Avoid fragmenting the heap too much while reconstructing the index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build (part 2) Created 7 years, 4 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
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_index_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool app_on_background); 90 bool app_on_background);
91 91
92 // Doom the entries specified in |entry_hashes|, calling |reply_callback| 92 // Doom the entries specified in |entry_hashes|, calling |reply_callback|
93 // with the result on the current thread when done. 93 // with the result on the current thread when done.
94 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes, 94 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes,
95 const base::Callback<void(int)>& reply_callback); 95 const base::Callback<void(int)>& reply_callback);
96 96
97 private: 97 private:
98 friend class WrappedSimpleIndexFile; 98 friend class WrappedSimpleIndexFile;
99 99
100 // Used for cache directory traversal.
101 typedef base::Callback<void (const base::FilePath&)> EntryFileCallback;
102
100 // When loading the entries from disk, add this many extra hash buckets to 103 // When loading the entries from disk, add this many extra hash buckets to
101 // prevent reallocation on the IO thread when merging in new live entries. 104 // prevent reallocation on the IO thread when merging in new live entries.
102 static const int kExtraSizeForMerge = 512; 105 static const int kExtraSizeForMerge = 512;
103 106
104 // Synchronous (IO performing) implementation of LoadIndexEntries. 107 // Synchronous (IO performing) implementation of LoadIndexEntries.
105 static void SyncLoadIndexEntries(base::Time cache_last_modified, 108 static void SyncLoadIndexEntries(base::Time cache_last_modified,
106 const base::FilePath& cache_directory, 109 const base::FilePath& cache_directory,
107 const base::FilePath& index_file_path, 110 const base::FilePath& index_file_path,
108 SimpleIndexLoadResult* out_result); 111 SimpleIndexLoadResult* out_result);
109 112
110 // Load the index file from disk returning an EntrySet. Upon failure, returns 113 // Load the index file from disk returning an EntrySet. Upon failure, returns
111 // NULL. 114 // NULL.
112 static void SyncLoadFromDisk(const base::FilePath& index_filename, 115 static void SyncLoadFromDisk(const base::FilePath& index_filename,
113 SimpleIndexLoadResult* out_result); 116 SimpleIndexLoadResult* out_result);
114 117
115 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized 118 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized
116 // data to be written to a file. 119 // data to be written to a file.
117 static scoped_ptr<Pickle> Serialize( 120 static scoped_ptr<Pickle> Serialize(
118 const SimpleIndexFile::IndexMetadata& index_metadata, 121 const SimpleIndexFile::IndexMetadata& index_metadata,
119 const SimpleIndex::EntrySet& entries); 122 const SimpleIndex::EntrySet& entries);
120 123
121 // Given the contents of an index file |data| of length |data_len|, returns 124 // Given the contents of an index file |data| of length |data_len|, returns
122 // the corresponding EntrySet. Returns NULL on error. 125 // the corresponding EntrySet. Returns NULL on error.
123 static void Deserialize(const char* data, int data_len, 126 static void Deserialize(const char* data, int data_len,
124 SimpleIndexLoadResult* out_result); 127 SimpleIndexLoadResult* out_result);
125 128
129 // Implemented either in simple_index_file_posix.cc or
130 // simple_index_file_win.cc. base::FileEnumerator turned out to be very
131 // expensive in terms of memory usage therefore it's used only on non-POSIX
132 // environments for convenience (for now). Returns whether the traversal
133 // succeeded.
134 static bool TraverseCacheDirectory(
135 const base::FilePath& cache_path,
136 const EntryFileCallback& entry_file_callback);
137
126 // Scan the index directory for entries, returning an EntrySet of all entries 138 // Scan the index directory for entries, returning an EntrySet of all entries
127 // found. 139 // found.
128 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, 140 static void SyncRestoreFromDisk(const base::FilePath& cache_directory,
129 const base::FilePath& index_file_path, 141 const base::FilePath& index_file_path,
130 SimpleIndexLoadResult* out_result); 142 SimpleIndexLoadResult* out_result);
131 143
132 // Determines if an index file is stale relative to the time of last 144 // Determines if an index file is stale relative to the time of last
133 // modification of the cache directory. 145 // modification of the cache directory.
134 static bool IsIndexFileStale(base::Time cache_last_modified, 146 static bool IsIndexFileStale(base::Time cache_last_modified,
135 const base::FilePath& index_file_path); 147 const base::FilePath& index_file_path);
136 148
137 struct PickleHeader : public Pickle::Header { 149 struct PickleHeader : public Pickle::Header {
138 uint32 crc; 150 uint32 crc;
139 }; 151 };
140 152
141 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; 153 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_;
142 const scoped_refptr<base::TaskRunner> worker_pool_; 154 const scoped_refptr<base::TaskRunner> worker_pool_;
143 const base::FilePath cache_directory_; 155 const base::FilePath cache_directory_;
144 const base::FilePath index_file_; 156 const base::FilePath index_file_;
145 const base::FilePath temp_index_file_; 157 const base::FilePath temp_index_file_;
146 158
147 static const char kIndexFileName[];
148 static const char kTempIndexFileName[];
149
150 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); 159 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile);
151 }; 160 };
152 161
153 162
154 } // namespace disk_cache 163 } // namespace disk_cache
155 164
156 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 165 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_index_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698