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

Side by Side Diff: components/safe_browsing_db/database_manager.h

Issue 2233103002: Move full hash caching logic to v4_get_hash_protocol_manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bring back the histogram to check if there were any hits in the response from the server Created 4 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The Safe Browsing service is responsible for downloading anti-phishing and 5 // The Safe Browsing service is responsible for downloading anti-phishing and
6 // anti-malware tables and checking urls against them. 6 // anti-malware tables and checking urls against them.
7 7
8 #ifndef COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ 8 #ifndef COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_
9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ 9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_
10 10
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 net::URLRequestContextGetter* request_context_getter, 170 net::URLRequestContextGetter* request_context_getter,
171 const V4ProtocolConfig& config); 171 const V4ProtocolConfig& config);
172 172
173 // Called to stop or shutdown operations on the io_thread. 173 // Called to stop or shutdown operations on the io_thread.
174 virtual void StopOnIOThread(bool shutdown); 174 virtual void StopOnIOThread(bool shutdown);
175 175
176 protected: 176 protected:
177 // Bundled client info for an API abuse hash prefix check. 177 // Bundled client info for an API abuse hash prefix check.
178 class SafeBrowsingApiCheck { 178 class SafeBrowsingApiCheck {
179 public: 179 public:
180 SafeBrowsingApiCheck(const GURL& url, 180 SafeBrowsingApiCheck(const GURL& url, Client* client);
181 const std::vector<SBPrefix>& prefixes,
182 const std::vector<SBFullHash>& full_hashes,
183 const std::vector<SBFullHashResult>& cached_results,
184 Client* client);
185 ~SafeBrowsingApiCheck(); 181 ~SafeBrowsingApiCheck();
186 182
187 const GURL& url() {return url_;} 183 const GURL& url() const { return url_; }
188 const std::vector<SBPrefix>& prefixes() {return prefixes_;} 184 Client* client() const { return client_; }
189 const std::vector<SBFullHash>& full_hashes() {return full_hashes_;}
190 const std::vector<SBFullHashResult>& cached_results() {
191 return cached_results_;
192 }
193 SafeBrowsingDatabaseManager::Client* client() {return client_;}
194 base::TimeTicks start_time() {return start_time_;}
195
196 void set_start_time(base::TimeTicks start) {start_time_ = start;}
197 185
198 private: 186 private:
199 GURL url_; 187 GURL url_;
200 188
201 // Prefixes that were requested in this check.
202 std::vector<SBPrefix> prefixes_;
203
204 // Full hashes for this check.
205 std::vector<SBFullHash> full_hashes_;
206
207 // Cached results for this check.
208 std::vector<SBFullHashResult> cached_results_;
209
210 // Not owned. 189 // Not owned.
211 SafeBrowsingDatabaseManager::Client* client_; 190 Client* client_;
212
213 // When the check was sent to the Safe Browsing service.
214 base::TimeTicks start_time_;
215 191
216 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck); 192 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck);
217 }; 193 };
218 194
219 SafeBrowsingDatabaseManager(); 195 SafeBrowsingDatabaseManager();
220 196
221 virtual ~SafeBrowsingDatabaseManager(); 197 virtual ~SafeBrowsingDatabaseManager();
222 198
223 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; 199 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
224 200
(...skipping 12 matching lines...) Expand all
237 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, 213 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
238 ResultsAreNotCachedOnNull); 214 ResultsAreNotCachedOnNull);
239 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, 215 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
240 GetCachedResults); 216 GetCachedResults);
241 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, 217 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
242 CachedResultsMerged); 218 CachedResultsMerged);
243 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, 219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
244 CachedResultsAreEvicted); 220 CachedResultsAreEvicted);
245 221
246 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet; 222 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet;
247 typedef std::map<SBPrefix, SBCachedFullHashResult> PrefixToFullHashResultsMap;
248 typedef std::map<SBThreatType, PrefixToFullHashResultsMap>
249 ThreatTypeToResultsMap;
250 223
251 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received 224 // Called on the IO thread when the SafeBrowsingProtocolManager has received
252 // the full hash and api results for prefixes of the |url| argument in 225 // the full hash and api results for prefixes of the |url| argument in
253 // CheckApiBlacklistUrl. 226 // CheckApiBlacklistUrl.
254 virtual void HandleGetHashesWithApisResults( 227 virtual void OnThreatMetadataResponse(
255 SafeBrowsingApiCheck* check, 228 std::unique_ptr<SafeBrowsingApiCheck> check,
256 const std::vector<SBFullHashResult>& full_hash_results, 229 const ThreatMetadata& md);
257 const base::Time& negative_cache_expire);
258
259 // Looks up the cached results for |threat_type|. Fills |prefixes| with the
260 // prefixes that need a request. Fills |cached_results| with the cached
261 // results.
262 void GetFullHashCachedResults(const SBThreatType& threat_type,
263 const std::vector<SBFullHash>& full_hashes,
264 base::Time now,
265 std::vector<SBPrefix>* prefixes,
266 std::vector<SBFullHashResult>* cached_results);
267
268 // Populates |md| with permission api metadata from all results that have a
269 // match in |full_hashes|. Returns |true| if any of the results have a match
270 // in |full_hashes|.
271 bool PopulateApiMetadataResult(const std::vector<SBFullHashResult>& results,
272 const std::vector<SBFullHash>& full_hashes,
273 ThreatMetadata* md);
274 230
275 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is 231 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is
276 // responsible for deleting them when removing from the set. 232 // responsible for deleting them when removing from the set.
277 ApiCheckSet api_checks_; 233 ApiCheckSet api_checks_;
278 234
279 // A cache of V4 full hash results for api checks.
280 // TODO(kcarattini): Look into moving all caching logic to
281 // V4GetHashProtocolManager.
282 ThreatTypeToResultsMap v4_full_hash_cache_;
283
284 // Created and destroyed via StartOnIOThread/StopOnIOThread. 235 // Created and destroyed via StartOnIOThread/StopOnIOThread.
285 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; 236 std::unique_ptr<V4GetHashProtocolManager> v4_get_hash_protocol_manager_;
286 237
287 private: 238 private:
288 // Returns an iterator to the pending API check with the given |client|. 239 // Returns an iterator to the pending API check with the given |client|.
289 ApiCheckSet::iterator FindClientApiCheck(Client* client); 240 ApiCheckSet::iterator FindClientApiCheck(Client* client);
290 }; // class SafeBrowsingDatabaseManager 241 }; // class SafeBrowsingDatabaseManager
291 242
292 } // namespace safe_browsing 243 } // namespace safe_browsing
293 244
294 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ 245 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698