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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_database.h

Issue 781613002: Make SafeBrowsingDatabase's PrefixSets only updatable by swapping a new one in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a2_threadchecks
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_database.h
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.h b/chrome/browser/safe_browsing/safe_browsing_database.h
index 7de801b65658a6ebef56139c1278d540633fa7f2..6efa2e34649cfd3240a2e5793679a4555adc5d7e 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database.h
@@ -367,7 +367,7 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
bool PrefixSetContainsUrl(
const GURL& url,
- scoped_ptr<safe_browsing::PrefixSet>* prefix_set_getter,
+ scoped_ptr<const safe_browsing::PrefixSet>* prefix_set_getter,
std::vector<SBPrefix>* prefix_hits,
std::vector<SBFullHashResult>* cache_hits);
@@ -380,7 +380,7 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
bool PrefixSetContainsUrlHashes(
const std::vector<SBFullHash>& full_hashes,
- scoped_ptr<safe_browsing::PrefixSet>* prefix_set_getter,
+ scoped_ptr<const safe_browsing::PrefixSet>* prefix_set_getter,
std::vector<SBPrefix>* prefix_hits,
std::vector<SBFullHashResult>* cache_hits);
@@ -400,14 +400,14 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// and stores it in |prefix_set|. |read_failure_type| provides a
// caller-specific error code to be used on failure.
void LoadPrefixSet(const base::FilePath& db_filename,
- scoped_ptr<safe_browsing::PrefixSet>* prefix_set,
+ scoped_ptr<const safe_browsing::PrefixSet>* prefix_set,
FailureType read_failure_type);
// Writes the current prefix set "|db_filename| Prefix Set" on disk.
// |write_failure_type| provides a caller-specific error code to be used on
// failure.
void WritePrefixSet(const base::FilePath& db_filename,
- safe_browsing::PrefixSet* prefix_set,
+ const safe_browsing::PrefixSet* prefix_set,
FailureType write_failure_type);
// Loads the given full-length hashes to the given whitelist. If the number
@@ -449,14 +449,15 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// Updates a PrefixStore store for URLs (|url_store|) which is backed on disk
// by a "|db_filename| Prefix Set" file. Specific failure types are provided
// to highlight the specific store who made the initial request on failure.
- void UpdatePrefixSetUrlStore(const base::FilePath& db_filename,
- SafeBrowsingStore* url_store,
- scoped_ptr<safe_browsing::PrefixSet>* prefix_set,
- FailureType finish_failure_type,
- FailureType write_failure_type);
+ void UpdatePrefixSetUrlStore(
+ const base::FilePath& db_filename,
+ SafeBrowsingStore* url_store,
+ scoped_ptr<const safe_browsing::PrefixSet>* prefix_set,
+ FailureType finish_failure_type,
+ FailureType write_failure_type);
void UpdateUrlStore(SafeBrowsingStore* url_store,
- scoped_ptr<safe_browsing::PrefixSet>* prefix_set,
+ scoped_ptr<const safe_browsing::PrefixSet>* prefix_set,
FailureType failure_type);
void UpdateSideEffectFreeWhitelistStore();
@@ -526,14 +527,16 @@ class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
// Used to optimize away database update.
bool change_detected_;
- // Used to check if a prefix was in the browse database.
- scoped_ptr<safe_browsing::PrefixSet> browse_prefix_set_;
-
- // Used to check if a prefix was in the side-effect free whitelist database.
- scoped_ptr<safe_browsing::PrefixSet> side_effect_free_whitelist_prefix_set_;
-
- // Used to check if a prexfix was in the unwanted software database.
- scoped_ptr<safe_browsing::PrefixSet> unwanted_software_prefix_set_;
+ // PrefixSets to speed up lookups for particularly large lists. The PrefixSet
+ // themselves are never modified, instead a new one is swapped in on update
+ // while holding |lookup_lock_|. Any thread other than this class' main thread
+ // (which handles updates) must hold |lookup_lock_| before reading from these
+ // sets.
+ // TODO(gab): Enforce this by design.
+ scoped_ptr<const safe_browsing::PrefixSet> browse_prefix_set_;
+ scoped_ptr<const safe_browsing::PrefixSet>
+ side_effect_free_whitelist_prefix_set_;
+ scoped_ptr<const safe_browsing::PrefixSet> unwanted_software_prefix_set_;
// Used to schedule resetting the database because of corruption.
base::WeakPtrFactory<SafeBrowsingDatabaseNew> reset_factory_;

Powered by Google App Engine
This is Rietveld 408576698