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

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

Issue 8349018: Safe-browsing SBAddPrefix from vector to deque. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 int32 chunk_id; 44 int32 chunk_id;
45 SBPrefix prefix; 45 SBPrefix prefix;
46 46
47 SBAddPrefix(int32 id, SBPrefix p) : chunk_id(id), prefix(p) {} 47 SBAddPrefix(int32 id, SBPrefix p) : chunk_id(id), prefix(p) {}
48 SBAddPrefix() : chunk_id(), prefix() {} 48 SBAddPrefix() : chunk_id(), prefix() {}
49 49
50 int32 GetAddChunkId() const { return chunk_id; } 50 int32 GetAddChunkId() const { return chunk_id; }
51 SBPrefix GetAddPrefix() const { return prefix; } 51 SBPrefix GetAddPrefix() const { return prefix; }
52 }; 52 };
53 53
54 typedef std::deque<SBAddPrefix> SBAddPrefixContainer;
55
54 struct SBSubPrefix { 56 struct SBSubPrefix {
55 int32 chunk_id; 57 int32 chunk_id;
56 int32 add_chunk_id; 58 int32 add_chunk_id;
57 SBPrefix add_prefix; 59 SBPrefix add_prefix;
58 60
59 SBSubPrefix(int32 id, int32 add_id, int prefix) 61 SBSubPrefix(int32 id, int32 add_id, int prefix)
60 : chunk_id(id), add_chunk_id(add_id), add_prefix(prefix) {} 62 : chunk_id(id), add_chunk_id(add_id), add_prefix(prefix) {}
61 SBSubPrefix() : chunk_id(), add_chunk_id(), add_prefix() {} 63 SBSubPrefix() : chunk_id(), add_chunk_id(), add_prefix() {}
62 64
63 int32 GetAddChunkId() const { return add_chunk_id; } 65 int32 GetAddChunkId() const { return add_chunk_id; }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // TODO(shess): Since the prefixes are uniformly-distributed hashes, 133 // TODO(shess): Since the prefixes are uniformly-distributed hashes,
132 // there aren't many ways to organize the inputs for efficient 134 // there aren't many ways to organize the inputs for efficient
133 // processing. For this reason, the vectors are sorted and processed 135 // processing. For this reason, the vectors are sorted and processed
134 // in parallel. At this time this code does the sorting internally, 136 // in parallel. At this time this code does the sorting internally,
135 // but it might make sense to make sorting an API requirement so that 137 // but it might make sense to make sorting an API requirement so that
136 // the storage can optimize for it. 138 // the storage can optimize for it.
137 // 139 //
138 // TODO(shess): The original code did not process |sub_full_hashes| 140 // TODO(shess): The original code did not process |sub_full_hashes|
139 // for matches in |add_full_hashes|, so this code doesn't, either. I 141 // for matches in |add_full_hashes|, so this code doesn't, either. I
140 // think this is probably a bug. 142 // think this is probably a bug.
141 void SBProcessSubs(std::vector<SBAddPrefix>* add_prefixes, 143 void SBProcessSubs(SBAddPrefixContainer* add_prefixes,
142 std::vector<SBSubPrefix>* sub_prefixes, 144 std::vector<SBSubPrefix>* sub_prefixes,
143 std::vector<SBAddFullHash>* add_full_hashes, 145 std::vector<SBAddFullHash>* add_full_hashes,
144 std::vector<SBSubFullHash>* sub_full_hashes, 146 std::vector<SBSubFullHash>* sub_full_hashes,
145 const base::hash_set<int32>& add_chunks_deleted, 147 const base::hash_set<int32>& add_chunks_deleted,
146 const base::hash_set<int32>& sub_chunks_deleted); 148 const base::hash_set<int32>& sub_chunks_deleted);
147 149
148 // Records a histogram of the number of items in |prefix_misses| which 150 // Records a histogram of the number of items in |prefix_misses| which
149 // are not in |add_prefixes|. 151 // are not in |add_prefixes|.
150 void SBCheckPrefixMisses(const std::vector<SBAddPrefix>& add_prefixes, 152 void SBCheckPrefixMisses(const SBAddPrefixContainer& add_prefixes,
151 const std::set<SBPrefix>& prefix_misses); 153 const std::set<SBPrefix>& prefix_misses);
152 154
153 // TODO(shess): This uses int32 rather than int because it's writing 155 // TODO(shess): This uses int32 rather than int because it's writing
154 // specifically-sized items to files. SBPrefix should likewise be 156 // specifically-sized items to files. SBPrefix should likewise be
155 // explicitly sized. 157 // explicitly sized.
156 158
157 // Abstract interface for storing data. 159 // Abstract interface for storing data.
158 class SafeBrowsingStore { 160 class SafeBrowsingStore {
159 public: 161 public:
160 SafeBrowsingStore() {} 162 SafeBrowsingStore() {}
161 virtual ~SafeBrowsingStore() {} 163 virtual ~SafeBrowsingStore() {}
162 164
163 // Sets up the information for later use, but does not necessarily 165 // Sets up the information for later use, but does not necessarily
164 // check whether the underlying file exists, or is valid. If 166 // check whether the underlying file exists, or is valid. If
165 // |curruption_callback| is non-NULL it will be called if corruption 167 // |curruption_callback| is non-NULL it will be called if corruption
166 // is detected, which could happen as part of any call other than 168 // is detected, which could happen as part of any call other than
167 // Delete(). The appropriate action is to use Delete() to clear the 169 // Delete(). The appropriate action is to use Delete() to clear the
168 // store. 170 // store.
169 virtual void Init(const FilePath& filename, 171 virtual void Init(const FilePath& filename,
170 const base::Closure& corruption_callback) = 0; 172 const base::Closure& corruption_callback) = 0;
171 173
172 // Deletes the files which back the store, returning true if 174 // Deletes the files which back the store, returning true if
173 // successful. 175 // successful.
174 virtual bool Delete() = 0; 176 virtual bool Delete() = 0;
175 177
176 // Get all Add prefixes out from the store. 178 // Get all Add prefixes out from the store.
177 virtual bool GetAddPrefixes(std::vector<SBAddPrefix>* add_prefixes) = 0; 179 virtual bool GetAddPrefixes(SBAddPrefixContainer* add_prefixes) = 0;
178 180
179 // Get all add full-length hashes. 181 // Get all add full-length hashes.
180 virtual bool GetAddFullHashes( 182 virtual bool GetAddFullHashes(
181 std::vector<SBAddFullHash>* add_full_hashes) = 0; 183 std::vector<SBAddFullHash>* add_full_hashes) = 0;
182 184
183 // Start an update. None of the following methods should be called 185 // Start an update. None of the following methods should be called
184 // unless this returns true. If this returns true, the update 186 // unless this returns true. If this returns true, the update
185 // should be terminated by FinishUpdate() or CancelUpdate(). 187 // should be terminated by FinishUpdate() or CancelUpdate().
186 virtual bool BeginUpdate() = 0; 188 virtual bool BeginUpdate() = 0;
187 189
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // stored in |add_prefixes_result| and |add_full_hashes_result|. 225 // stored in |add_prefixes_result| and |add_full_hashes_result|.
224 // |pending_adds| is the set of full hashes which have been received 226 // |pending_adds| is the set of full hashes which have been received
225 // since the previous update, and is provided as a convenience 227 // since the previous update, and is provided as a convenience
226 // (could be written via WriteAddHash(), but that would flush the 228 // (could be written via WriteAddHash(), but that would flush the
227 // chunk to disk). |prefix_misses| is the set of prefixes where the 229 // chunk to disk). |prefix_misses| is the set of prefixes where the
228 // |GetHash()| request returned no full hashes, used for diagnostic 230 // |GetHash()| request returned no full hashes, used for diagnostic
229 // purposes. 231 // purposes.
230 virtual bool FinishUpdate( 232 virtual bool FinishUpdate(
231 const std::vector<SBAddFullHash>& pending_adds, 233 const std::vector<SBAddFullHash>& pending_adds,
232 const std::set<SBPrefix>& prefix_misses, 234 const std::set<SBPrefix>& prefix_misses,
233 std::vector<SBAddPrefix>* add_prefixes_result, 235 SBAddPrefixContainer* add_prefixes_result,
234 std::vector<SBAddFullHash>* add_full_hashes_result) = 0; 236 std::vector<SBAddFullHash>* add_full_hashes_result) = 0;
235 237
236 // Cancel the update in process and remove any temporary disk 238 // Cancel the update in process and remove any temporary disk
237 // storage, leaving the original data unmodified. 239 // storage, leaving the original data unmodified.
238 virtual bool CancelUpdate() = 0; 240 virtual bool CancelUpdate() = 0;
239 241
240 private: 242 private:
241 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStore); 243 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStore);
242 }; 244 };
243 245
244 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_H_ 246 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698