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

Side by Side Diff: components/safe_browsing_db/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 (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
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <unordered_set> 13 #include <unordered_set>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "components/safe_browsing_db/hit_report.h" 19 #include "components/safe_browsing_db/hit_report.h"
20 #include "components/safe_browsing_db/util.h" 20 #include "components/safe_browsing_db/util.h"
21 #include "content/public/common/resource_type.h" 21 #include "content/public/common/resource_type.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace net { 24 namespace net {
25 class URLRequestContextGetter; 25 class URLRequestContextGetter;
26 } // namespace net 26 } // namespace net
27 27
28 namespace safe_browsing { 28 namespace safe_browsing {
29 29
30 // Value returned by some Check*Whitelist() calls that may or may not have an
31 // immediate answer.
32 enum class AsyncMatch {
33 ASYNC, // No answer yet -- Client will get a callback
34 MATCH, // URL matches the list. No callback.
35 NO_MATCH, // URL doesn't match. No callback.
36 };
37
30 struct V4ProtocolConfig; 38 struct V4ProtocolConfig;
31 class V4GetHashProtocolManager; 39 class V4GetHashProtocolManager;
32 40
33 // Base class to either the locally-managed or a remotely-managed database. 41 // Base class to either the locally-managed or a remotely-managed database.
34 class SafeBrowsingDatabaseManager 42 class SafeBrowsingDatabaseManager
35 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager> { 43 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager> {
36 public: 44 public:
37 // Callers requesting a result should derive from this class. 45 // Callers requesting a result should derive from this class.
38 // The destructor should call db_manager->CancelCheck(client) if a 46 // The destructor should call db_manager->CancelCheck(client) if a
39 // request is still pending. 47 // request is still pending.
(...skipping 17 matching lines...) Expand all
57 SBThreatType threat_type) {} 65 SBThreatType threat_type) {}
58 66
59 // Called when the result of checking a set of extensions is known. 67 // Called when the result of checking a set of extensions is known.
60 virtual void OnCheckExtensionsResult( 68 virtual void OnCheckExtensionsResult(
61 const std::set<std::string>& threats) {} 69 const std::set<std::string>& threats) {}
62 70
63 // Called when the result of checking the resource blacklist is known. 71 // Called when the result of checking the resource blacklist is known.
64 virtual void OnCheckResourceUrlResult(const GURL& url, 72 virtual void OnCheckResourceUrlResult(const GURL& url,
65 SBThreatType threat_type, 73 SBThreatType threat_type,
66 const std::string& threat_hash) {} 74 const std::string& threat_hash) {}
75
76 // Called when the result of checking a whitelist is known.
77 // Currently only used for CSD whitelist.
78 virtual void OnCheckWhitelistUrlResult(bool is_whitelisted) {}
67 }; 79 };
68 80
69 // 81 //
70 // Methods called by the client to cancel pending checks. 82 // Methods called by the client to cancel pending checks.
71 // 83 //
72 84
73 // Called on the IO thread to cancel a pending API check if the result is no 85 // Called on the IO thread to cancel a pending API check if the result is no
74 // longer needed. Returns true if the client was found and the check 86 // longer needed. Returns true if the client was found and the check
75 // successfully cancelled. 87 // successfully cancelled.
76 virtual bool CancelApiCheck(Client* client); 88 virtual bool CancelApiCheck(Client* client);
(...skipping 28 matching lines...) Expand all
105 // Called on the IO thread to check if the given url has blacklisted APIs. 117 // Called on the IO thread to check if the given url has blacklisted APIs.
106 // "client" is called asynchronously with the result when it is ready. Callers 118 // "client" is called asynchronously with the result when it is ready. Callers
107 // should wait for results before calling this method a second time with the 119 // should wait for results before calling this method a second time with the
108 // same client. This method has the same implementation for both the local and 120 // same client. This method has the same implementation for both the local and
109 // remote database managers since it pings Safe Browsing servers directly 121 // remote database managers since it pings Safe Browsing servers directly
110 // without accessing the database at all. Returns true if we can 122 // without accessing the database at all. Returns true if we can
111 // synchronously determine that the url is safe. Otherwise it returns false, 123 // synchronously determine that the url is safe. Otherwise it returns false,
112 // and "client" is called asynchronously with the result when it is ready. 124 // and "client" is called asynchronously with the result when it is ready.
113 virtual bool CheckApiBlacklistUrl(const GURL& url, Client* client); 125 virtual bool CheckApiBlacklistUrl(const GURL& url, Client* client);
114 126
127 // Check if the |url| matches any of the full-length hashes from the client-
128 // side phishing detection whitelist. The 3-state return value indicates
129 // the result or that the Client will get a callback later with the result.
130 virtual AsyncMatch CheckCsdWhitelistUrl(const GURL& url, Client* client) = 0;
131
115 // Called on the IO thread to check if the given url is safe or not. If we 132 // Called on the IO thread to check if the given url is safe or not. If we
116 // can synchronously determine that the url is safe, CheckUrl returns true. 133 // can synchronously determine that the url is safe, CheckUrl returns true.
117 // Otherwise it returns false, and "client" is called asynchronously with the 134 // Otherwise it returns false, and "client" is called asynchronously with the
118 // result when it is ready. 135 // result when it is ready.
119 virtual bool CheckBrowseUrl(const GURL& url, Client* client) = 0; 136 virtual bool CheckBrowseUrl(const GURL& url, Client* client) = 0;
120 137
121 // Called on the IO thread to check if the given url belongs to the
122 // subresource filter list. If the url doesn't belong to the list, the check
123 // happens synchronously, otherwise it returns false, and "client" is called
124 // asynchronously with the result when it is ready.
125 // Currently supported only on desktop. Returns TRUE if the list is not yet
126 // available.
127 virtual bool CheckUrlForSubresourceFilter(const GURL& url,
128 Client* client) = 0;
129 138
130 // Check if the prefix for |url| is in safebrowsing download add lists. 139 // Check if the prefix for |url| is in safebrowsing download add lists.
131 // Result will be passed to callback in |client|. 140 // Result will be passed to callback in |client|.
132 virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain, 141 virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
133 Client* client) = 0; 142 Client* client) = 0;
134 143
135 // Check which prefixes in |extension_ids| are in the safebrowsing blacklist. 144 // Check which prefixes in |extension_ids| are in the safebrowsing blacklist.
136 // Returns true if not, false if further checks need to be made in which case 145 // Returns true if not, false if further checks need to be made in which case
137 // the result will be passed to |client|. 146 // the result will be passed to |client|.
138 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids, 147 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
139 Client* client) = 0; 148 Client* client) = 0;
140 149
141 // Check if |url| is in the resources blacklist. Returns true if not, false 150 // Check if |url| is in the resources blacklist. Returns true if not, false
142 // if further checks need to be made in which case the result will be passed 151 // if further checks need to be made in which case the result will be passed
143 // to callback in |client|. 152 // to callback in |client|.
144 virtual bool CheckResourceUrl(const GURL& url, Client* client) = 0; 153 virtual bool CheckResourceUrl(const GURL& url, Client* client) = 0;
145 154
155 // Called on the IO thread to check if the given url belongs to the
156 // subresource filter list. If the url doesn't belong to the list, the check
157 // happens synchronously, otherwise it returns false, and "client" is called
158 // asynchronously with the result when it is ready.
159 // Currently supported only on desktop. Returns TRUE if the list is not yet
160 // available.
161 virtual bool CheckUrlForSubresourceFilter(const GURL& url,
162 Client* client) = 0;
163
146 // 164 //
147 // Methods to synchronously check whether a URL, or full hash, or IP address 165 // Match*(): Methods to synchronously check if various types are safe.
148 // or a DLL file is safe.
149 // 166 //
150 167
151 // Check if the |url| matches any of the full-length hashes from the client- 168 // Check if the |url| matches any of the full-length hashes from the client-
152 // side phishing detection whitelist. Returns true if there was a match and 169 // side phishing detection whitelist. Returns true if there was a match and
153 // false otherwise. To make sure we are conservative we will return true if 170 // false otherwise. To make sure we are conservative we will return true if
154 // an error occurs. This method must be called on the IO thread. 171 // an error occurs. This method must be called on the IO thread.
172 //
173 // DEPRECATED. ref: http://crbug.com/714300
155 virtual bool MatchCsdWhitelistUrl(const GURL& url) = 0; 174 virtual bool MatchCsdWhitelistUrl(const GURL& url) = 0;
156 175
157 // Check if |str| matches any of the full-length hashes from the download 176 // Check if |str| matches any of the full-length hashes from the download
158 // whitelist. Returns true if there was a match and false otherwise. To make 177 // whitelist. Returns true if there was a match and false otherwise. To make
159 // sure we are conservative we will return true if an error occurs. This 178 // sure we are conservative we will return true if an error occurs. This
160 // method must be called on the IO thread. 179 // method must be called on the IO thread.
161 virtual bool MatchDownloadWhitelistString(const std::string& str) = 0; 180 virtual bool MatchDownloadWhitelistString(const std::string& str) = 0;
162 181
163 // Check if the |url| matches any of the full-length hashes from the download 182 // Check if the |url| matches any of the full-length hashes from the download
164 // whitelist. Returns true if there was a match and false otherwise. To make 183 // whitelist. Returns true if there was a match and false otherwise. To make
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 std::unique_ptr<V4GetHashProtocolManager> v4_get_hash_protocol_manager_; 303 std::unique_ptr<V4GetHashProtocolManager> v4_get_hash_protocol_manager_;
285 304
286 private: 305 private:
287 // Returns an iterator to the pending API check with the given |client|. 306 // Returns an iterator to the pending API check with the given |client|.
288 ApiCheckSet::iterator FindClientApiCheck(Client* client); 307 ApiCheckSet::iterator FindClientApiCheck(Client* client);
289 }; // class SafeBrowsingDatabaseManager 308 }; // class SafeBrowsingDatabaseManager
290 309
291 } // namespace safe_browsing 310 } // namespace safe_browsing
292 311
293 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ 312 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698