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

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: Remove uses of vector::data() which is C++11 only 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
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/platform_file.h"
gavinp 2013/08/21 11:49:47 Pourquoi? Just forward declare base::PlatformFileI
Philippe 2013/08/21 12:41:38 Yeah my bad. I used to have GetPlatformFileInfo()
18 #include "base/port.h" 19 #include "base/port.h"
19 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
20 #include "net/disk_cache/simple/simple_index.h" 21 #include "net/disk_cache/simple/simple_index.h"
21 22
22 namespace base { 23 namespace base {
23 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
24 class TaskRunner; 25 class TaskRunner;
25 } 26 }
26 27
27 namespace disk_cache { 28 namespace disk_cache {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool app_on_background); 91 bool app_on_background);
91 92
92 // Doom the entries specified in |entry_hashes|, calling |reply_callback| 93 // Doom the entries specified in |entry_hashes|, calling |reply_callback|
93 // with the result on the current thread when done. 94 // with the result on the current thread when done.
94 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes, 95 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes,
95 const base::Callback<void(int)>& reply_callback); 96 const base::Callback<void(int)>& reply_callback);
96 97
97 private: 98 private:
98 friend class WrappedSimpleIndexFile; 99 friend class WrappedSimpleIndexFile;
99 100
101 // Used for cache directory traversal.
102 typedef base::Callback<void (const char* file_name)> EntryFileCallback;
103
100 // When loading the entries from disk, add this many extra hash buckets to 104 // 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. 105 // prevent reallocation on the IO thread when merging in new live entries.
102 static const int kExtraSizeForMerge = 512; 106 static const int kExtraSizeForMerge = 512;
103 107
104 // Synchronous (IO performing) implementation of LoadIndexEntries. 108 // Synchronous (IO performing) implementation of LoadIndexEntries.
105 static void SyncLoadIndexEntries(base::Time cache_last_modified, 109 static void SyncLoadIndexEntries(base::Time cache_last_modified,
106 const base::FilePath& cache_directory, 110 const base::FilePath& cache_directory,
107 const base::FilePath& index_file_path, 111 const base::FilePath& index_file_path,
108 SimpleIndexLoadResult* out_result); 112 SimpleIndexLoadResult* out_result);
109 113
110 // Load the index file from disk returning an EntrySet. Upon failure, returns 114 // Load the index file from disk returning an EntrySet. Upon failure, returns
111 // NULL. 115 // NULL.
112 static void SyncLoadFromDisk(const base::FilePath& index_filename, 116 static void SyncLoadFromDisk(const base::FilePath& index_filename,
113 SimpleIndexLoadResult* out_result); 117 SimpleIndexLoadResult* out_result);
114 118
115 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized 119 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized
116 // data to be written to a file. 120 // data to be written to a file.
117 static scoped_ptr<Pickle> Serialize( 121 static scoped_ptr<Pickle> Serialize(
118 const SimpleIndexFile::IndexMetadata& index_metadata, 122 const SimpleIndexFile::IndexMetadata& index_metadata,
119 const SimpleIndex::EntrySet& entries); 123 const SimpleIndex::EntrySet& entries);
120 124
121 // Given the contents of an index file |data| of length |data_len|, returns 125 // Given the contents of an index file |data| of length |data_len|, returns
122 // the corresponding EntrySet. Returns NULL on error. 126 // the corresponding EntrySet. Returns NULL on error.
123 static void Deserialize(const char* data, int data_len, 127 static void Deserialize(const char* data,
128 int data_len,
124 SimpleIndexLoadResult* out_result); 129 SimpleIndexLoadResult* out_result);
125 130
131 // Implemented either in simple_index_file_posix.cc or
132 // simple_index_file_win.cc. base::FileEnumerator turned out to be very
133 // expensive in terms of memory usage therefore it's used only on non-POSIX
134 // environments for convenience (for now). Note that this function is
135 // synchronous although its signature could suggest otherwise. Returns
136 // whether the traversal succeeded.
137 static bool TraverseCacheDirectory(
138 const std::string& cache_path,
139 const EntryFileCallback& entry_file_callback);
140
141 // Returns whether file info was successfully retrieved.
142 static bool GetPlatformFileInfo(const char* path,
143 base::PlatformFileInfo* info);
144
145 // Called for each cache directory traversal iteration. The provided
146 // non-cleared |buffer| can be used accross iterations to avoid doing too many
147 // heap allocations given that cache directories can be very large.
148 static void ProcessEntryFile(const std::string& cache_path,
gavinp 2013/08/21 11:49:47 Can this method be moved into an anonymous namespa
Philippe 2013/08/21 12:41:38 Yeah good point.
149 std::vector<char>* buffer,
gavinp 2013/08/21 11:49:47 char*! Let your inner C programmer out.
Philippe 2013/08/21 12:41:38 Ahaha :) I got rid of the buffer.
150 SimpleIndex::EntrySet* entries,
151 const char* file_name);
152
126 // Scan the index directory for entries, returning an EntrySet of all entries 153 // Scan the index directory for entries, returning an EntrySet of all entries
127 // found. 154 // found.
128 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, 155 static void SyncRestoreFromDisk(const base::FilePath& cache_directory,
129 const base::FilePath& index_file_path, 156 const base::FilePath& index_file_path,
130 SimpleIndexLoadResult* out_result); 157 SimpleIndexLoadResult* out_result);
131 158
132 // Determines if an index file is stale relative to the time of last 159 // Determines if an index file is stale relative to the time of last
133 // modification of the cache directory. 160 // modification of the cache directory.
134 static bool IsIndexFileStale(base::Time cache_last_modified, 161 static bool IsIndexFileStale(base::Time cache_last_modified,
135 const base::FilePath& index_file_path); 162 const base::FilePath& index_file_path);
(...skipping 11 matching lines...) Expand all
147 static const char kIndexFileName[]; 174 static const char kIndexFileName[];
148 static const char kTempIndexFileName[]; 175 static const char kTempIndexFileName[];
149 176
150 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); 177 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile);
151 }; 178 };
152 179
153 180
154 } // namespace disk_cache 181 } // namespace disk_cache
155 182
156 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 183 #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') | net/disk_cache/simple/simple_index_file.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698