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

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

Issue 337723004: [Safe browsing] Clean up code to scan hash results for threats. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/database_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
10 10
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 // protected for tests. 208 // protected for tests.
209 void NotifyDatabaseUpdateFinished(bool update_succeeded); 209 void NotifyDatabaseUpdateFinished(bool update_succeeded);
210 210
211 private: 211 private:
212 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; 212 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
213 friend class SafeBrowsingServerTest; 213 friend class SafeBrowsingServerTest;
214 friend class SafeBrowsingServiceTest; 214 friend class SafeBrowsingServiceTest;
215 friend class SafeBrowsingServiceTestHelper; 215 friend class SafeBrowsingServiceTestHelper;
216 friend class SafeBrowsingDatabaseManagerTest; 216 friend class SafeBrowsingDatabaseManagerTest;
217 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, GetUrlThreatType);
217 218
218 typedef std::set<SafeBrowsingCheck*> CurrentChecks; 219 typedef std::set<SafeBrowsingCheck*> CurrentChecks;
219 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; 220 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors;
220 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; 221 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests;
221 222
222 // Clients that we've queued up for checking later once the database is ready. 223 // Clients that we've queued up for checking later once the database is ready.
223 struct QueuedCheck { 224 struct QueuedCheck {
224 QueuedCheck(const safe_browsing_util::ListType check_type, 225 QueuedCheck(const safe_browsing_util::ListType check_type,
225 Client* client, 226 Client* client,
226 const GURL& url, 227 const GURL& url,
227 const std::vector<SBThreatType>& expected_threats, 228 const std::vector<SBThreatType>& expected_threats,
228 const base::TimeTicks& start); 229 const base::TimeTicks& start);
229 ~QueuedCheck(); 230 ~QueuedCheck();
230 safe_browsing_util::ListType check_type; 231 safe_browsing_util::ListType check_type;
231 Client* client; 232 Client* client;
232 GURL url; 233 GURL url;
233 std::vector<SBThreatType> expected_threats; 234 std::vector<SBThreatType> expected_threats;
234 base::TimeTicks start; // When check was queued. 235 base::TimeTicks start; // When check was queued.
235 }; 236 };
236 237
238 // Return the threat type from the first result in |full_hashes| which matches
239 // |hash|, or SAFE if none match.
240 static SBThreatType GetHashThreatType(
241 const SBFullHash& hash,
242 const std::vector<SBFullHashResult>& full_hashes);
243
244 // Given a URL, compare all the possible host + path full hashes to the set of
245 // provided full hashes. Returns the threat type of the matching result from
246 // |full_hashes|, or SAFE if none match.
247 static SBThreatType GetUrlThreatType(
248 const GURL& url,
249 const std::vector<SBFullHashResult>& full_hashes);
250
237 // Called to stop operations on the io_thread. This may be called multiple 251 // Called to stop operations on the io_thread. This may be called multiple
238 // times during the life of the DatabaseManager. Should be called on IO 252 // times during the life of the DatabaseManager. Should be called on IO
239 // thread. 253 // thread.
240 void DoStopOnIOThread(); 254 void DoStopOnIOThread();
241 255
242 // Returns whether |database_| exists and is accessible. 256 // Returns whether |database_| exists and is accessible.
243 bool DatabaseAvailable() const; 257 bool DatabaseAvailable() const;
244 258
245 // Called on the IO thread. If the database does not exist, queues up a call 259 // Called on the IO thread. If the database does not exist, queues up a call
246 // on the db thread to create it. Returns whether the database is available. 260 // on the db thread to create it. Returns whether the database is available.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 406
393 std::deque<QueuedCheck> queued_checks_; 407 std::deque<QueuedCheck> queued_checks_;
394 408
395 // Timeout to use for safe browsing checks. 409 // Timeout to use for safe browsing checks.
396 base::TimeDelta check_timeout_; 410 base::TimeDelta check_timeout_;
397 411
398 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); 412 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager);
399 }; 413 };
400 414
401 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 415 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/database_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698