OLD | NEW |
---|---|
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 Loading... | |
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 std::string& file_name)> 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). Note that this function is | |
133 // synchronous although its signature could suggest otherwise. Returns | |
134 // whether the traversal succeeded. | |
135 static bool TraverseCacheDirectory( | |
136 const std::string& cache_path, | |
137 const EntryFileCallback& entry_file_callback); | |
138 | |
139 // Called for each cache directory traversal iteration. The provided | |
140 // non-cleared |buffer| can be used accross iterations to avoid doing too many | |
141 // heap allocations given that cache directories can be very large. | |
142 static void ProcessEntryFile(const std::string& cache_path, | |
gavinp
2013/08/20 20:13:45
I suggest you want:
static void ProcessEntryFile(
Philippe
2013/08/21 09:37:33
I want to keep the hash extraction in this method
| |
143 std::string* buffer, | |
gavinp
2013/08/20 18:53:23
I'm a bit confused at this buffer being a std::str
Philippe
2013/08/21 09:37:33
I replaced it with a vector that does now a single
| |
144 SimpleIndex::EntrySet* entries, | |
145 const std::string& file_name); | |
146 | |
126 // Scan the index directory for entries, returning an EntrySet of all entries | 147 // Scan the index directory for entries, returning an EntrySet of all entries |
127 // found. | 148 // found. |
128 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, | 149 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, |
129 const base::FilePath& index_file_path, | 150 const base::FilePath& index_file_path, |
130 SimpleIndexLoadResult* out_result); | 151 SimpleIndexLoadResult* out_result); |
131 | 152 |
132 // Determines if an index file is stale relative to the time of last | 153 // Determines if an index file is stale relative to the time of last |
133 // modification of the cache directory. | 154 // modification of the cache directory. |
134 static bool IsIndexFileStale(base::Time cache_last_modified, | 155 static bool IsIndexFileStale(base::Time cache_last_modified, |
135 const base::FilePath& index_file_path); | 156 const base::FilePath& index_file_path); |
(...skipping 11 matching lines...) Expand all Loading... | |
147 static const char kIndexFileName[]; | 168 static const char kIndexFileName[]; |
148 static const char kTempIndexFileName[]; | 169 static const char kTempIndexFileName[]; |
149 | 170 |
150 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); | 171 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); |
151 }; | 172 }; |
152 | 173 |
153 | 174 |
154 } // namespace disk_cache | 175 } // namespace disk_cache |
155 | 176 |
156 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | 177 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
OLD | NEW |