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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file.h

Issue 8349018: Safe-browsing SBAddPrefix from vector to deque. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Tweak some naming. Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 virtual ~SafeBrowsingStoreFile(); 109 virtual ~SafeBrowsingStoreFile();
110 110
111 virtual void Init(const FilePath& filename, 111 virtual void Init(const FilePath& filename,
112 const base::Closure& corruption_callback) OVERRIDE; 112 const base::Closure& corruption_callback) OVERRIDE;
113 113
114 // Delete any on-disk files, including the permanent storage. 114 // Delete any on-disk files, including the permanent storage.
115 virtual bool Delete() OVERRIDE; 115 virtual bool Delete() OVERRIDE;
116 116
117 // Get all add hash prefixes and full-length hashes, respectively, from 117 // Get all add hash prefixes and full-length hashes, respectively, from
118 // the store. 118 // the store.
119 virtual bool GetAddPrefixes(std::vector<SBAddPrefix>* add_prefixes) OVERRIDE; 119 virtual bool GetAddPrefixes(SBAddPrefixes* add_prefixes) OVERRIDE;
120 virtual bool GetAddFullHashes( 120 virtual bool GetAddFullHashes(
121 std::vector<SBAddFullHash>* add_full_hashes) OVERRIDE; 121 std::vector<SBAddFullHash>* add_full_hashes) OVERRIDE;
122 122
123 virtual bool BeginChunk() OVERRIDE; 123 virtual bool BeginChunk() OVERRIDE;
124 124
125 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) OVERRIDE; 125 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) OVERRIDE;
126 virtual bool WriteAddHash(int32 chunk_id, 126 virtual bool WriteAddHash(int32 chunk_id,
127 base::Time receive_time, 127 base::Time receive_time,
128 const SBFullHash& full_hash) OVERRIDE; 128 const SBFullHash& full_hash) OVERRIDE;
129 virtual bool WriteSubPrefix(int32 chunk_id, 129 virtual bool WriteSubPrefix(int32 chunk_id,
130 int32 add_chunk_id, SBPrefix prefix); 130 int32 add_chunk_id, SBPrefix prefix);
131 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, 131 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id,
132 const SBFullHash& full_hash) OVERRIDE; 132 const SBFullHash& full_hash) OVERRIDE;
133 virtual bool FinishChunk() OVERRIDE; 133 virtual bool FinishChunk() OVERRIDE;
134 134
135 virtual bool BeginUpdate() OVERRIDE; 135 virtual bool BeginUpdate() OVERRIDE;
136 // Store updates with pending add full hashes in file store and 136 // Store updates with pending add full hashes in file store and
137 // return |add_prefixes_result| and |add_full_hashes_result|. 137 // return |add_prefixes_result| and |add_full_hashes_result|.
138 virtual bool FinishUpdate( 138 virtual bool FinishUpdate(
139 const std::vector<SBAddFullHash>& pending_adds, 139 const std::vector<SBAddFullHash>& pending_adds,
140 const std::set<SBPrefix>& prefix_misses, 140 const std::set<SBPrefix>& prefix_misses,
141 std::vector<SBAddPrefix>* add_prefixes_result, 141 SBAddPrefixes* add_prefixes_result,
142 std::vector<SBAddFullHash>* add_full_hashes_result) OVERRIDE; 142 std::vector<SBAddFullHash>* add_full_hashes_result) OVERRIDE;
143 virtual bool CancelUpdate() OVERRIDE; 143 virtual bool CancelUpdate() OVERRIDE;
144 144
145 virtual void SetAddChunk(int32 chunk_id) OVERRIDE; 145 virtual void SetAddChunk(int32 chunk_id) OVERRIDE;
146 virtual bool CheckAddChunk(int32 chunk_id) OVERRIDE; 146 virtual bool CheckAddChunk(int32 chunk_id) OVERRIDE;
147 virtual void GetAddChunks(std::vector<int32>* out) OVERRIDE; 147 virtual void GetAddChunks(std::vector<int32>* out) OVERRIDE;
148 virtual void SetSubChunk(int32 chunk_id) OVERRIDE; 148 virtual void SetSubChunk(int32 chunk_id) OVERRIDE;
149 virtual bool CheckSubChunk(int32 chunk_id) OVERRIDE; 149 virtual bool CheckSubChunk(int32 chunk_id) OVERRIDE;
150 virtual void GetSubChunks(std::vector<int32>* out) OVERRIDE; 150 virtual void GetSubChunks(std::vector<int32>* out) OVERRIDE;
151 151
152 virtual void DeleteAddChunk(int32 chunk_id) OVERRIDE; 152 virtual void DeleteAddChunk(int32 chunk_id) OVERRIDE;
153 virtual void DeleteSubChunk(int32 chunk_id) OVERRIDE; 153 virtual void DeleteSubChunk(int32 chunk_id) OVERRIDE;
154 154
155 // Returns the name of the temporary file used to buffer data for 155 // Returns the name of the temporary file used to buffer data for
156 // |filename|. Exported for unit tests. 156 // |filename|. Exported for unit tests.
157 static const FilePath TemporaryFileForFilename(const FilePath& filename) { 157 static const FilePath TemporaryFileForFilename(const FilePath& filename) {
158 return FilePath(filename.value() + FILE_PATH_LITERAL("_new")); 158 return FilePath(filename.value() + FILE_PATH_LITERAL("_new"));
159 } 159 }
160 160
161 private: 161 private:
162 // Update store file with pending full hashes. 162 // Update store file with pending full hashes.
163 virtual bool DoUpdate(const std::vector<SBAddFullHash>& pending_adds, 163 virtual bool DoUpdate(const std::vector<SBAddFullHash>& pending_adds,
164 const std::set<SBPrefix>& prefix_misses, 164 const std::set<SBPrefix>& prefix_misses,
165 std::vector<SBAddPrefix>* add_prefixes_result, 165 SBAddPrefixes* add_prefixes_result,
166 std::vector<SBAddFullHash>* add_full_hashes_result); 166 std::vector<SBAddFullHash>* add_full_hashes_result);
167 167
168 // Enumerate different format-change events for histogramming 168 // Enumerate different format-change events for histogramming
169 // purposes. DO NOT CHANGE THE ORDERING OF THESE VALUES. 169 // purposes. DO NOT CHANGE THE ORDERING OF THESE VALUES.
170 // TODO(shess): Remove this once the format change is complete. 170 // TODO(shess): Remove this once the format change is complete.
171 enum FormatEventType { 171 enum FormatEventType {
172 // Corruption detected, broken down by file format. 172 // Corruption detected, broken down by file format.
173 FORMAT_EVENT_FILE_CORRUPT, 173 FORMAT_EVENT_FILE_CORRUPT,
174 FORMAT_EVENT_SQLITE_CORRUPT, // Obsolete 174 FORMAT_EVENT_SQLITE_CORRUPT, // Obsolete
175 175
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // Helper for creating a corruption callback for |old_store_|. 215 // Helper for creating a corruption callback for |old_store_|.
216 // TODO(shess): Remove after migration. 216 // TODO(shess): Remove after migration.
217 void HandleCorruptDatabase(); 217 void HandleCorruptDatabase();
218 218
219 // Clear temporary buffers used to accumulate chunk data. 219 // Clear temporary buffers used to accumulate chunk data.
220 bool ClearChunkBuffers() { 220 bool ClearChunkBuffers() {
221 // NOTE: .clear() doesn't release memory. 221 // NOTE: .clear() doesn't release memory.
222 // TODO(shess): Figure out if this is overkill. Some amount of 222 // TODO(shess): Figure out if this is overkill. Some amount of
223 // pre-reserved space is probably reasonable between each chunk 223 // pre-reserved space is probably reasonable between each chunk
224 // collected. 224 // collected.
225 std::vector<SBAddPrefix>().swap(add_prefixes_); 225 SBAddPrefixes().swap(add_prefixes_);
226 std::vector<SBSubPrefix>().swap(sub_prefixes_); 226 std::vector<SBSubPrefix>().swap(sub_prefixes_);
227 std::vector<SBAddFullHash>().swap(add_hashes_); 227 std::vector<SBAddFullHash>().swap(add_hashes_);
228 std::vector<SBSubFullHash>().swap(sub_hashes_); 228 std::vector<SBSubFullHash>().swap(sub_hashes_);
229 return true; 229 return true;
230 } 230 }
231 231
232 // Clear all buffers used during update. 232 // Clear all buffers used during update.
233 void ClearUpdateBuffers() { 233 void ClearUpdateBuffers() {
234 ClearChunkBuffers(); 234 ClearChunkBuffers();
235 chunks_written_ = 0; 235 chunks_written_ = 0;
236 std::set<int32>().swap(add_chunks_cache_); 236 std::set<int32>().swap(add_chunks_cache_);
237 std::set<int32>().swap(sub_chunks_cache_); 237 std::set<int32>().swap(sub_chunks_cache_);
238 base::hash_set<int32>().swap(add_del_cache_); 238 base::hash_set<int32>().swap(add_del_cache_);
239 base::hash_set<int32>().swap(sub_del_cache_); 239 base::hash_set<int32>().swap(sub_del_cache_);
240 } 240 }
241 241
242 // Buffers for collecting data between BeginChunk() and 242 // Buffers for collecting data between BeginChunk() and
243 // FinishChunk(). 243 // FinishChunk().
244 std::vector<SBAddPrefix> add_prefixes_; 244 SBAddPrefixes add_prefixes_;
245 std::vector<SBSubPrefix> sub_prefixes_; 245 std::vector<SBSubPrefix> sub_prefixes_;
246 std::vector<SBAddFullHash> add_hashes_; 246 std::vector<SBAddFullHash> add_hashes_;
247 std::vector<SBSubFullHash> sub_hashes_; 247 std::vector<SBSubFullHash> sub_hashes_;
248 248
249 // Count of chunks collected in |new_file_|. 249 // Count of chunks collected in |new_file_|.
250 int chunks_written_; 250 int chunks_written_;
251 251
252 // Name of the main database file. 252 // Name of the main database file.
253 FilePath filename_; 253 FilePath filename_;
254 254
255 // Handles to the main and scratch files. |empty_| is true if the 255 // Handles to the main and scratch files. |empty_| is true if the
256 // main file didn't exist when the update was started. 256 // main file didn't exist when the update was started.
257 file_util::ScopedFILE file_; 257 file_util::ScopedFILE file_;
258 file_util::ScopedFILE new_file_; 258 file_util::ScopedFILE new_file_;
259 bool empty_; 259 bool empty_;
260 260
261 // Cache of chunks which have been seen. Loaded from the database 261 // Cache of chunks which have been seen. Loaded from the database
262 // on BeginUpdate() so that it can be queried during the 262 // on BeginUpdate() so that it can be queried during the
263 // transaction. 263 // transaction.
264 std::set<int32> add_chunks_cache_; 264 std::set<int32> add_chunks_cache_;
265 std::set<int32> sub_chunks_cache_; 265 std::set<int32> sub_chunks_cache_;
266 266
267 // Cache the set of deleted chunks during a transaction, applied on 267 // Cache the set of deleted chunks during a transaction, applied on
268 // FinishUpdate(). 268 // FinishUpdate().
269 // TODO(shess): If the set is small enough, hash_set<> might be 269 // TODO(shess): If the set is small enough, hash_set<> might be
270 // slower than plain set<>. 270 // slower than plain set<>.
271 base::hash_set<int32> add_del_cache_; 271 base::hash_set<int32> add_del_cache_;
272 base::hash_set<int32> sub_del_cache_; 272 base::hash_set<int32> sub_del_cache_;
273 273
274 // Count number of add_prefix items added during the course of an
275 // update, for purposes of optimizing vector sizing at commit time.
276 size_t add_prefixes_added_;
277
278 base::Closure corruption_callback_; 274 base::Closure corruption_callback_;
279 275
280 // Tracks whether corruption has already been seen in the current 276 // Tracks whether corruption has already been seen in the current
281 // update, so that only one instance is recorded in the stats. 277 // update, so that only one instance is recorded in the stats.
282 // TODO(shess): Remove with format-migration support. 278 // TODO(shess): Remove with format-migration support.
283 bool corruption_seen_; 279 bool corruption_seen_;
284 280
285 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); 281 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile);
286 }; 282 };
287 283
288 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ 284 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_store.cc ('k') | chrome/browser/safe_browsing/safe_browsing_store_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698