| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // Returns the name of the temporary file used to buffer data for | 195 // Returns the name of the temporary file used to buffer data for |
| 196 // |filename|. Exported for unit tests. | 196 // |filename|. Exported for unit tests. |
| 197 static const FilePath TemporaryFileForFilename(const FilePath& filename) { | 197 static const FilePath TemporaryFileForFilename(const FilePath& filename) { |
| 198 return FilePath(filename.value() + FILE_PATH_LITERAL("_new")); | 198 return FilePath(filename.value() + FILE_PATH_LITERAL("_new")); |
| 199 } | 199 } |
| 200 | 200 |
| 201 private: | 201 private: |
| 202 // Close all files and clear all buffers. | 202 // Close all files and clear all buffers. |
| 203 bool Close(); | 203 bool Close(); |
| 204 | 204 |
| 205 // Helpers to read/write the various data sets. Excepting | |
| 206 // ReadChunksToSet(), which is called too early, the readers skip | |
| 207 // items from deleted chunks (listed in add_del_cache_ and | |
| 208 // sub_del_cache_). | |
| 209 bool ReadChunksToSet(FILE* fp, std::set<int32>* chunks, int count); | |
| 210 bool WriteChunksFromSet(const std::set<int32>& chunks); | |
| 211 bool ReadAddPrefixes(FILE* fp, | |
| 212 std::vector<SBAddPrefix>* add_prefixes, int count); | |
| 213 bool WriteAddPrefixes(const std::vector<SBAddPrefix>& add_prefixes); | |
| 214 bool ReadSubPrefixes(FILE* fp, | |
| 215 std::vector<SBSubPrefix>* sub_prefixes, int count); | |
| 216 bool WriteSubPrefixes(std::vector<SBSubPrefix>& sub_prefixes); | |
| 217 bool ReadAddHashes(FILE* fp, | |
| 218 std::vector<SBAddFullHash>* add_hashes, int count); | |
| 219 bool WriteAddHashes(const std::vector<SBAddFullHash>& add_hashes); | |
| 220 bool ReadSubHashes(FILE* fp, | |
| 221 std::vector<SBSubFullHash>* sub_hashes, int count); | |
| 222 bool WriteSubHashes(std::vector<SBSubFullHash>& sub_hashes); | |
| 223 | |
| 224 // Calls |corruption_callback_| if non-NULL, always returns false as | 205 // Calls |corruption_callback_| if non-NULL, always returns false as |
| 225 // a convenience to the caller. | 206 // a convenience to the caller. |
| 226 bool OnCorruptDatabase(); | 207 bool OnCorruptDatabase(); |
| 227 | 208 |
| 228 // Clear temporary buffers used to accumulate chunk data. | 209 // Clear temporary buffers used to accumulate chunk data. |
| 229 bool ClearChunkBuffers() { | 210 bool ClearChunkBuffers() { |
| 230 // NOTE: .clear() doesn't release memory. | 211 // NOTE: .clear() doesn't release memory. |
| 231 // TODO(shess): Figure out if this is overkill. Some amount of | 212 // TODO(shess): Figure out if this is overkill. Some amount of |
| 232 // pre-reserved space is probably reasonable between each chunk | 213 // pre-reserved space is probably reasonable between each chunk |
| 233 // collected. | 214 // collected. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // slower than plain set<>. | 260 // slower than plain set<>. |
| 280 base::hash_set<int32> add_del_cache_; | 261 base::hash_set<int32> add_del_cache_; |
| 281 base::hash_set<int32> sub_del_cache_; | 262 base::hash_set<int32> sub_del_cache_; |
| 282 | 263 |
| 283 scoped_ptr<Callback0::Type> corruption_callback_; | 264 scoped_ptr<Callback0::Type> corruption_callback_; |
| 284 | 265 |
| 285 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); | 266 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); |
| 286 }; | 267 }; |
| 287 | 268 |
| 288 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 269 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
| OLD | NEW |