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

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

Issue 1673733002: Support new Safe Browsing list "goog-badresource-shavar" in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Post-merge test fix Created 4 years, 10 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_DATABASE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // 168 //
169 // This function can ONLY be accessed from the creation thread. 169 // This function can ONLY be accessed from the creation thread.
170 virtual bool ContainsExtensionPrefixes( 170 virtual bool ContainsExtensionPrefixes(
171 const std::vector<SBPrefix>& prefixes, 171 const std::vector<SBPrefix>& prefixes,
172 std::vector<SBPrefix>* prefix_hits) = 0; 172 std::vector<SBPrefix>* prefix_hits) = 0;
173 173
174 // Returns true iff the given IP is currently on the csd malware IP blacklist. 174 // Returns true iff the given IP is currently on the csd malware IP blacklist.
175 // This function is safe to call from any thread. 175 // This function is safe to call from any thread.
176 virtual bool ContainsMalwareIP(const std::string& ip_address) = 0; 176 virtual bool ContainsMalwareIP(const std::string& ip_address) = 0;
177 177
178 // Populates |prefix_hits| with any prefixes in |prefixes| that have matches
179 // in the database. Returns true iff there were any matches.
180 //
181 // This function can ONLY by accessed from the creation thread.
182 virtual bool ContainsResourceUrlPrefixes(
183 const std::vector<SBPrefix>& prefixes,
184 std::vector<SBPrefix>* prefix_hits) = 0;
185
178 // A database transaction should look like: 186 // A database transaction should look like:
179 // 187 //
180 // std::vector<SBListChunkRanges> lists; 188 // std::vector<SBListChunkRanges> lists;
181 // if (db.UpdateStarted(&lists)) { 189 // if (db.UpdateStarted(&lists)) {
182 // // Do something with |lists|. 190 // // Do something with |lists|.
183 // 191 //
184 // // Process add/sub commands. 192 // // Process add/sub commands.
185 // db.InsertChunks(list_name, chunks); 193 // db.InsertChunks(list_name, chunks);
186 // 194 //
187 // // Process adddel/subdel commands. 195 // // Process adddel/subdel commands.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 const base::FilePath& ip_blacklist_base_filename); 271 const base::FilePath& ip_blacklist_base_filename);
264 272
265 // Filename for the unwanted software blacklist database. 273 // Filename for the unwanted software blacklist database.
266 static base::FilePath UnwantedSoftwareDBFilename( 274 static base::FilePath UnwantedSoftwareDBFilename(
267 const base::FilePath& db_filename); 275 const base::FilePath& db_filename);
268 276
269 // Filename for the module whitelist database. 277 // Filename for the module whitelist database.
270 static base::FilePath ModuleWhitelistDBFilename( 278 static base::FilePath ModuleWhitelistDBFilename(
271 const base::FilePath& db_filename); 279 const base::FilePath& db_filename);
272 280
281 static base::FilePath ResourceBlacklistDBFilename(
282 const base::FilePath& db_filename);
283
273 // Get the prefixes matching the download |urls|. 284 // Get the prefixes matching the download |urls|.
274 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, 285 static void GetDownloadUrlPrefixes(const std::vector<GURL>& urls,
275 std::vector<SBPrefix>* prefixes); 286 std::vector<SBPrefix>* prefixes);
276 287
277 // SafeBrowsing Database failure types for histogramming purposes. Explicitly 288 // SafeBrowsing Database failure types for histogramming purposes. Explicitly
278 // label new values and do not re-use old values. Also make sure to reflect 289 // label new values and do not re-use old values. Also make sure to reflect
279 // modifications made below in the SB2DatabaseFailure histogram enum. 290 // modifications made below in the SB2DatabaseFailure histogram enum.
280 enum FailureType { 291 enum FailureType {
281 FAILURE_DATABASE_CORRUPT = 0, 292 FAILURE_DATABASE_CORRUPT = 0,
282 FAILURE_DATABASE_CORRUPT_HANDLER = 1, 293 FAILURE_DATABASE_CORRUPT_HANDLER = 1,
(...skipping 23 matching lines...) Expand all
306 // Obsolete: FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE = 25, 317 // Obsolete: FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE = 25,
307 FAILURE_IP_BLACKLIST_UPDATE_BEGIN = 26, 318 FAILURE_IP_BLACKLIST_UPDATE_BEGIN = 26,
308 FAILURE_IP_BLACKLIST_UPDATE_FINISH = 27, 319 FAILURE_IP_BLACKLIST_UPDATE_FINISH = 27,
309 FAILURE_IP_BLACKLIST_UPDATE_INVALID = 28, 320 FAILURE_IP_BLACKLIST_UPDATE_INVALID = 28,
310 FAILURE_IP_BLACKLIST_DELETE = 29, 321 FAILURE_IP_BLACKLIST_DELETE = 29,
311 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN = 30, 322 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN = 30,
312 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH = 31, 323 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH = 31,
313 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ = 32, 324 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ = 32,
314 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE = 33, 325 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE = 33,
315 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE = 34, 326 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE = 34,
327 FAILURE_RESOURCE_BLACKLIST_UPDATE_BEGIN = 35,
328 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH = 36,
329 FAILURE_RESOURCE_BLACKLIST_DELETE = 37,
316 330
317 // Memory space for histograms is determined by the max. ALWAYS 331 // Memory space for histograms is determined by the max. ALWAYS
318 // ADD NEW VALUES BEFORE THIS ONE. 332 // ADD NEW VALUES BEFORE THIS ONE.
319 FAILURE_DATABASE_MAX 333 FAILURE_DATABASE_MAX
320 }; 334 };
321 335
322 static void RecordFailure(FailureType failure_type); 336 static void RecordFailure(FailureType failure_type);
323 337
324 private: 338 private:
325 // The factory used to instantiate a SafeBrowsingDatabase object. 339 // The factory used to instantiate a SafeBrowsingDatabase object.
(...skipping 10 matching lines...) Expand all
336 SafeBrowsingDatabaseNew( 350 SafeBrowsingDatabaseNew(
337 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 351 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
338 SafeBrowsingStore* browse_store, 352 SafeBrowsingStore* browse_store,
339 SafeBrowsingStore* download_store, 353 SafeBrowsingStore* download_store,
340 SafeBrowsingStore* csd_whitelist_store, 354 SafeBrowsingStore* csd_whitelist_store,
341 SafeBrowsingStore* download_whitelist_store, 355 SafeBrowsingStore* download_whitelist_store,
342 SafeBrowsingStore* inclusion_whitelist_store, 356 SafeBrowsingStore* inclusion_whitelist_store,
343 SafeBrowsingStore* extension_blacklist_store, 357 SafeBrowsingStore* extension_blacklist_store,
344 SafeBrowsingStore* ip_blacklist_store, 358 SafeBrowsingStore* ip_blacklist_store,
345 SafeBrowsingStore* unwanted_software_store, 359 SafeBrowsingStore* unwanted_software_store,
346 SafeBrowsingStore* module_whitelist_store); 360 SafeBrowsingStore* module_whitelist_store,
361 SafeBrowsingStore* resource_blacklist_store);
347 362
348 ~SafeBrowsingDatabaseNew() override; 363 ~SafeBrowsingDatabaseNew() override;
349 364
350 // Implement SafeBrowsingDatabase interface. 365 // Implement SafeBrowsingDatabase interface.
351 void Init(const base::FilePath& filename) override; 366 void Init(const base::FilePath& filename) override;
352 bool ResetDatabase() override; 367 bool ResetDatabase() override;
353 bool ContainsBrowseUrl(const GURL& url, 368 bool ContainsBrowseUrl(const GURL& url,
354 std::vector<SBPrefix>* prefix_hits, 369 std::vector<SBPrefix>* prefix_hits,
355 std::vector<SBFullHashResult>* cache_hits) override; 370 std::vector<SBFullHashResult>* cache_hits) override;
356 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes, 371 bool ContainsBrowseHashes(const std::vector<SBFullHash>& full_hashes,
(...skipping 10 matching lines...) Expand all
367 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes, 382 bool ContainsDownloadUrlPrefixes(const std::vector<SBPrefix>& prefixes,
368 std::vector<SBPrefix>* prefix_hits) override; 383 std::vector<SBPrefix>* prefix_hits) override;
369 bool ContainsCsdWhitelistedUrl(const GURL& url) override; 384 bool ContainsCsdWhitelistedUrl(const GURL& url) override;
370 bool ContainsDownloadWhitelistedUrl(const GURL& url) override; 385 bool ContainsDownloadWhitelistedUrl(const GURL& url) override;
371 bool ContainsDownloadWhitelistedString(const std::string& str) override; 386 bool ContainsDownloadWhitelistedString(const std::string& str) override;
372 bool ContainsInclusionWhitelistedUrl(const GURL& url) override; 387 bool ContainsInclusionWhitelistedUrl(const GURL& url) override;
373 bool ContainsModuleWhitelistedString(const std::string& str) override; 388 bool ContainsModuleWhitelistedString(const std::string& str) override;
374 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes, 389 bool ContainsExtensionPrefixes(const std::vector<SBPrefix>& prefixes,
375 std::vector<SBPrefix>* prefix_hits) override; 390 std::vector<SBPrefix>* prefix_hits) override;
376 bool ContainsMalwareIP(const std::string& ip_address) override; 391 bool ContainsMalwareIP(const std::string& ip_address) override;
392 bool ContainsResourceUrlPrefixes(const std::vector<SBPrefix>& prefixes,
393 std::vector<SBPrefix>* prefix_hits) override;
394
377 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override; 395 bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override;
378 void InsertChunks( 396 void InsertChunks(
379 const std::string& list_name, 397 const std::string& list_name,
380 const std::vector<scoped_ptr<SBChunkData>>& chunks) override; 398 const std::vector<scoped_ptr<SBChunkData>>& chunks) override;
381 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override; 399 void DeleteChunks(const std::vector<SBChunkDelete>& chunk_deletes) override;
382 void UpdateFinished(bool update_succeeded) override; 400 void UpdateFinished(bool update_succeeded) override;
383 void CacheHashResults(const std::vector<SBPrefix>& prefixes, 401 void CacheHashResults(const std::vector<SBPrefix>& prefixes,
384 const std::vector<SBFullHashResult>& full_hits, 402 const std::vector<SBFullHashResult>& full_hits,
385 const base::TimeDelta& cache_lifetime) override; 403 const base::TimeDelta& cache_lifetime) override;
386 404
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 // - |download_whitelist_store_|: For the download whitelist chunks and 707 // - |download_whitelist_store_|: For the download whitelist chunks and
690 // full-length hashes. This list only contains 256 bit hashes. 708 // full-length hashes. This list only contains 256 bit hashes.
691 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format 709 // - |inclusion_whitelist_store_|: For the inclusion whitelist. Same format
692 // as |download_whitelist_store_|. 710 // as |download_whitelist_store_|.
693 // - |extension_blacklist_store_|: For extension IDs. 711 // - |extension_blacklist_store_|: For extension IDs.
694 // - |ip_blacklist_store_|: For IP blacklist. 712 // - |ip_blacklist_store_|: For IP blacklist.
695 // - |unwanted_software_store_|: For unwanted software list (format 713 // - |unwanted_software_store_|: For unwanted software list (format
696 // identical to browsing lists). 714 // identical to browsing lists).
697 // - |module_whitelist_store_|: For module whitelist. This list only 715 // - |module_whitelist_store_|: For module whitelist. This list only
698 // contains 256 bit hashes. 716 // contains 256 bit hashes.
717 // - |resource_blacklist_store_|: For script resource list (format identical
718 // to browsing lists).
699 // 719 //
700 // The stores themselves will be modified throughout the existence of this 720 // The stores themselves will be modified throughout the existence of this
701 // database, but shouldn't ever be swapped out (hence the const scoped_ptr -- 721 // database, but shouldn't ever be swapped out (hence the const scoped_ptr --
702 // which could be swapped for C++11's std::optional when that's available). 722 // which could be swapped for C++11's std::optional when that's available).
703 // They are NonThreadSafe and should thus only be accessed on the database's 723 // They are NonThreadSafe and should thus only be accessed on the database's
704 // main thread as enforced by SafeBrowsingStoreFile's implementation. 724 // main thread as enforced by SafeBrowsingStoreFile's implementation.
705 const scoped_ptr<SafeBrowsingStore> browse_store_; 725 const scoped_ptr<SafeBrowsingStore> browse_store_;
706 const scoped_ptr<SafeBrowsingStore> download_store_; 726 const scoped_ptr<SafeBrowsingStore> download_store_;
707 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_; 727 const scoped_ptr<SafeBrowsingStore> csd_whitelist_store_;
708 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_; 728 const scoped_ptr<SafeBrowsingStore> download_whitelist_store_;
709 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_; 729 const scoped_ptr<SafeBrowsingStore> inclusion_whitelist_store_;
710 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_; 730 const scoped_ptr<SafeBrowsingStore> extension_blacklist_store_;
711 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_; 731 const scoped_ptr<SafeBrowsingStore> ip_blacklist_store_;
712 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_; 732 const scoped_ptr<SafeBrowsingStore> unwanted_software_store_;
713 const scoped_ptr<SafeBrowsingStore> module_whitelist_store_; 733 const scoped_ptr<SafeBrowsingStore> module_whitelist_store_;
734 const scoped_ptr<SafeBrowsingStore> resource_blacklist_store_;
714 735
715 // Used to schedule resetting the database because of corruption. This factory 736 // Used to schedule resetting the database because of corruption. This factory
716 // and the WeakPtrs it issues should only be used on the database's main 737 // and the WeakPtrs it issues should only be used on the database's main
717 // thread. 738 // thread.
718 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_; 739 base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;
719 }; 740 };
720 741
721 } // namespace safe_browsing 742 } // namespace safe_browsing
722 743
723 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 744 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698