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

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

Issue 2890293004: Add the ability to check the CSD Whitelist asynchronously, for PhishGuard. (Closed)
Patch Set: Respond to vakhs review, fix up tests Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_
7 7
8 // A class that provides the interface between the SafeBrowsing protocol manager 8 // A class that provides the interface between the SafeBrowsing protocol manager
9 // and database that holds the downloaded updates. 9 // and database that holds the downloaded updates.
10 10
(...skipping 25 matching lines...) Expand all
36 36
37 // 37 //
38 // SafeBrowsingDatabaseManager implementation 38 // SafeBrowsingDatabaseManager implementation
39 // 39 //
40 40
41 void CancelCheck(Client* client) override; 41 void CancelCheck(Client* client) override;
42 bool CanCheckResourceType(content::ResourceType resource_type) const override; 42 bool CanCheckResourceType(content::ResourceType resource_type) const override;
43 bool CanCheckUrl(const GURL& url) const override; 43 bool CanCheckUrl(const GURL& url) const override;
44 bool ChecksAreAlwaysAsync() const override; 44 bool ChecksAreAlwaysAsync() const override;
45 bool CheckBrowseUrl(const GURL& url, Client* client) override; 45 bool CheckBrowseUrl(const GURL& url, Client* client) override;
46 AsyncMatch CheckCsdWhitelistUrl(const GURL& url, Client* client) override;
46 bool CheckDownloadUrl(const std::vector<GURL>& url_chain, 47 bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
47 Client* client) override; 48 Client* client) override;
48 // TODO(vakh): |CheckExtensionIDs| in the base class accepts a set of 49 // TODO(vakh): |CheckExtensionIDs| in the base class accepts a set of
49 // std::strings but the overriding method in this class accepts a set of 50 // std::strings but the overriding method in this class accepts a set of
50 // FullHash objects. Since FullHash is currently std::string, it compiles, 51 // FullHash objects. Since FullHash is currently std::string, it compiles,
51 // but this difference should be eliminated. 52 // but this difference should be eliminated.
52 bool CheckExtensionIDs(const std::set<FullHash>& extension_ids, 53 bool CheckExtensionIDs(const std::set<FullHash>& extension_ids,
53 Client* client) override; 54 Client* client) override;
54 bool CheckResourceUrl(const GURL& url, Client* client) override; 55 bool CheckResourceUrl(const GURL& url, Client* client) override;
55 bool CheckUrlForSubresourceFilter(const GURL& url, Client* client) override; 56 bool CheckUrlForSubresourceFilter(const GURL& url, Client* client) override;
(...skipping 25 matching lines...) Expand all
81 ~V4LocalDatabaseManager() override; 82 ~V4LocalDatabaseManager() override;
82 83
83 void SetTaskRunnerForTest( 84 void SetTaskRunnerForTest(
84 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { 85 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
85 task_runner_ = task_runner; 86 task_runner_ = task_runner;
86 } 87 }
87 88
88 enum class ClientCallbackType { 89 enum class ClientCallbackType {
89 // This represents the case when we're trying to determine if a URL is 90 // This represents the case when we're trying to determine if a URL is
90 // unsafe from the following perspectives: Malware, Phishing, UwS. 91 // unsafe from the following perspectives: Malware, Phishing, UwS.
91 CHECK_BROWSE_URL = 0, 92 CHECK_BROWSE_URL,
92 93
93 // This represents the case when we're trying to determine if any of the 94 // This represents the case when we're trying to determine if any of the
94 // URLs in a vector of URLs is unsafe for downloading binaries. 95 // URLs in a vector of URLs is unsafe for downloading binaries.
95 CHECK_DOWNLOAD_URLS = 1, 96 CHECK_DOWNLOAD_URLS,
96 97
97 // This represents the case when we're trying to determine if a URL is an 98 // This represents the case when we're trying to determine if a URL is an
98 // unsafe resource. 99 // unsafe resource.
99 CHECK_RESOURCE_URL = 2, 100 CHECK_RESOURCE_URL,
100 101
101 // This represents the case when we're trying to determine if a Chrome 102 // This represents the case when we're trying to determine if a Chrome
102 // extension is a unsafe. 103 // extension is a unsafe.
103 CHECK_EXTENSION_IDS = 3, 104 CHECK_EXTENSION_IDS,
104 105
105 // This respresents the case when we're trying to determine if a URL belongs 106 // This respresents the case when we're trying to determine if a URL belongs
106 // to the list where subresource filter should be active. 107 // to the list where subresource filter should be active.
107 CHECK_URL_FOR_SUBRESOURCE_FILTER = 4, 108 CHECK_URL_FOR_SUBRESOURCE_FILTER,
109
110 // This respresents the case when we're trying to determine if a URL is
111 // part of the CSD whitelist.
112 CHECK_CSD_WHITELIST,
108 113
109 // This represents the other cases when a check is being performed 114 // This represents the other cases when a check is being performed
110 // synchronously so a client callback isn't required. For instance, when 115 // synchronously so a client callback isn't required. For instance, when
111 // trying to determing if an IP address is unsafe due to hosting Malware. 116 // trying to determing if an IP address is unsafe due to hosting Malware.
112 CHECK_OTHER = 5, 117 CHECK_OTHER,
113 }; 118 };
114 119
115 // The information we need to process a URL safety reputation request and 120 // The information we need to process a URL safety reputation request and
116 // respond to the SafeBrowsing client that asked for it. 121 // respond to the SafeBrowsing client that asked for it.
117 struct PendingCheck { 122 struct PendingCheck {
118 PendingCheck(Client* client, 123 PendingCheck(Client* client,
119 ClientCallbackType client_callback_type, 124 ClientCallbackType client_callback_type,
120 const StoresToCheck& stores_to_check, 125 const StoresToCheck& stores_to_check,
121 const std::vector<GURL>& urls); 126 const std::vector<GURL>& urls);
122 127
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 219
215 // Returns the SBThreatType for a given ListIdentifier. 220 // Returns the SBThreatType for a given ListIdentifier.
216 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); 221 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id);
217 222
218 // Queues the check for async response if the database isn't ready yet. 223 // Queues the check for async response if the database isn't ready yet.
219 // If the database is ready, checks the database for prefix matches and 224 // If the database is ready, checks the database for prefix matches and
220 // returns true immediately if there's no match. If a match is found, it 225 // returns true immediately if there's no match. If a match is found, it
221 // schedules a task to perform full hash check and returns false. 226 // schedules a task to perform full hash check and returns false.
222 bool HandleCheck(std::unique_ptr<PendingCheck> check); 227 bool HandleCheck(std::unique_ptr<PendingCheck> check);
223 228
229 // Like HandleCheck, but for whitelists that have both full-hashes and
230 // partial hashes in the DB. Returns MATCH, NO_MATCH, or ASYNC.
231 AsyncMatch HandleWhitelistCheck(std::unique_ptr<PendingCheck> check);
232
233 // Schedules a full-hash check for a given set of prefixes.
234 void ScheduleFullHashCheck(std::unique_ptr<PendingCheck> check,
235 const FullHashToStoreAndHashPrefixesMap&
236 full_hash_to_store_and_hash_prefixes);
237
224 // Checks |stores_to_check| in database synchronously for hash prefixes 238 // Checks |stores_to_check| in database synchronously for hash prefixes
225 // matching |hash|. Returns true if there's a match; false otherwise. This is 239 // matching |hash|. Returns true if there's a match; false otherwise. This is
226 // used for lists that have full hash information in the database. 240 // used for lists that have full hash information in the database.
227 bool HandleHashSynchronously(const FullHash& hash, 241 bool HandleHashSynchronously(const FullHash& hash,
228 const StoresToCheck& stores_to_check); 242 const StoresToCheck& stores_to_check);
229 243
230 // Checks |stores_to_check| in database synchronously for hash prefixes 244 // Checks |stores_to_check| in database synchronously for hash prefixes
231 // matching the full hashes for |url|. See |HandleHashSynchronously| for 245 // matching the full hashes for |url|. See |HandleHashSynchronously| for
232 // details. 246 // details.
233 bool HandleUrlSynchronously(const GURL& url, 247 bool HandleUrlSynchronously(const GURL& url,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 328
315 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_; 329 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_;
316 330
317 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; 331 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>;
318 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); 332 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager);
319 }; // class V4LocalDatabaseManager 333 }; // class V4LocalDatabaseManager
320 334
321 } // namespace safe_browsing 335 } // namespace safe_browsing
322 336
323 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ 337 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698