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

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

Issue 1843383002: Safe Browsing: CheckApiBlacklist request implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review Comments Created 4 years, 8 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
« no previous file with comments | « components/safe_browsing_db/DEPS ('k') | components/safe_browsing_db/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 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 <deque> 11 #include <deque>
12 #include <map> 12 #include <map>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
18 #include "components/safe_browsing_db/hit_report.h" 20 #include "components/safe_browsing_db/hit_report.h"
19 #include "components/safe_browsing_db/util.h" 21 #include "components/safe_browsing_db/util.h"
20 #include "content/public/common/resource_type.h" 22 #include "content/public/common/resource_type.h"
21 #include "url/gurl.h" 23 #include "url/gurl.h"
22 24
23 namespace net { 25 namespace net {
24 class URLRequestContextGetter; 26 class URLRequestContextGetter;
25 } // namespace net 27 } // namespace net
26 28
(...skipping 29 matching lines...) Expand all
56 // Called when the result of checking the API blacklist is known. 58 // Called when the result of checking the API blacklist is known.
57 virtual void OnCheckApiBlacklistUrlResult(const GURL& url, 59 virtual void OnCheckApiBlacklistUrlResult(const GURL& url,
58 const ThreatMetadata& metadata) {} 60 const ThreatMetadata& metadata) {}
59 61
60 // Called when the result of checking the resource blacklist is known. 62 // Called when the result of checking the resource blacklist is known.
61 virtual void OnCheckResourceUrlResult(const GURL& url, 63 virtual void OnCheckResourceUrlResult(const GURL& url,
62 SBThreatType threat_type, 64 SBThreatType threat_type,
63 const std::string& threat_hash) {} 65 const std::string& threat_hash) {}
64 }; 66 };
65 67
66
67 // Returns true if URL-checking is supported on this build+device. 68 // Returns true if URL-checking is supported on this build+device.
68 // If false, calls to CheckBrowseUrl may dcheck-fail. 69 // If false, calls to CheckBrowseUrl may dcheck-fail.
69 virtual bool IsSupported() const = 0; 70 virtual bool IsSupported() const = 0;
70 71
71 // Returns the ThreatSource for this implementation. 72 // Returns the ThreatSource for this implementation.
72 virtual ThreatSource GetThreatSource() const = 0; 73 virtual ThreatSource GetThreatSource() const = 0;
73 74
74 // Returns true if checks are never done synchronously, and therefore 75 // Returns true if checks are never done synchronously, and therefore
75 // always have some latency. 76 // always have some latency.
76 virtual bool ChecksAreAlwaysAsync() const = 0; 77 virtual bool ChecksAreAlwaysAsync() const = 0;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // an error occurs. This method must be called on the IO thread. 142 // an error occurs. This method must be called on the IO thread.
142 virtual bool MatchModuleWhitelistString(const std::string& str) = 0; 143 virtual bool MatchModuleWhitelistString(const std::string& str) = 0;
143 144
144 // Check if the CSD malware IP matching kill switch is turned on. 145 // Check if the CSD malware IP matching kill switch is turned on.
145 virtual bool IsMalwareKillSwitchOn() = 0; 146 virtual bool IsMalwareKillSwitchOn() = 0;
146 147
147 // Check if the CSD whitelist kill switch is turned on. 148 // Check if the CSD whitelist kill switch is turned on.
148 virtual bool IsCsdWhitelistKillSwitchOn() = 0; 149 virtual bool IsCsdWhitelistKillSwitchOn() = 0;
149 150
150 // Called on the IO thread to cancel a pending check if the result is no 151 // Called on the IO thread to cancel a pending check if the result is no
151 // longer needed. Also called after the result has been handled. 152 // longer needed. Also called after the result has been handled. Api checks
153 // are handled separately. To cancel an API check use CancelApiCheck.
152 virtual void CancelCheck(Client* client) = 0; 154 virtual void CancelCheck(Client* client) = 0;
153 155
156 // TODO(kcarattini): Add a CancelApiCheck method.
157
154 // Called on the IO thread to check if the given url has blacklisted APIs. 158 // Called on the IO thread to check if the given url has blacklisted APIs.
155 // "client" is called asynchronously with the result when it is ready. 159 // "client" is called asynchronously with the result when it is ready.
156 // This method has the same implementation for both the local and remote 160 // This method has the same implementation for both the local and remote
157 // database managers since it pings Safe Browsing servers directly without 161 // database managers since it pings Safe Browsing servers directly without
158 // accessing the database at all. 162 // accessing the database at all. Returns true if we can synchronously
159 virtual void CheckApiBlacklistUrl(const GURL& url, Client* client); 163 // determine that the url is safe. Otherwise it returns false, and "client" is
164 // called asynchronously with the result when it is ready.
165 virtual bool CheckApiBlacklistUrl(const GURL& url, Client* client);
160 166
161 // Called to initialize objects that are used on the io_thread, such as the 167 // Called to initialize objects that are used on the io_thread, such as the
162 // v4 protocol manager. This may be called multiple times during the life of 168 // v4 protocol manager. This may be called multiple times during the life of
163 // the DatabaseManager. Must be called on IO thread. 169 // the DatabaseManager. Must be called on IO thread.
164 virtual void StartOnIOThread( 170 virtual void StartOnIOThread(
165 net::URLRequestContextGetter* request_context_getter, 171 net::URLRequestContextGetter* request_context_getter,
166 const V4ProtocolConfig& config); 172 const V4ProtocolConfig& config);
167 173
168 // Called to stop or shutdown operations on the io_thread. 174 // Called to stop or shutdown operations on the io_thread.
169 virtual void StopOnIOThread(bool shutdown); 175 virtual void StopOnIOThread(bool shutdown);
170 176
171 protected: 177 protected:
172 SafeBrowsingDatabaseManager(); 178 SafeBrowsingDatabaseManager();
173 179
174 virtual ~SafeBrowsingDatabaseManager(); 180 virtual ~SafeBrowsingDatabaseManager();
175 181
176 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; 182 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
177 183
178 // Created and destroyed via StartonIOThread/StopOnIOThread. 184 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
185 CheckApiBlacklistUrlPrefixes);
186
187 // Bundled client info for an API abuse hash prefix check.
188 class SafeBrowsingApiCheck {
189 public:
190 SafeBrowsingApiCheck(const GURL& url,
191 const std::vector<SBFullHash>& full_hashes,
192 Client* client);
193 ~SafeBrowsingApiCheck();
194
195 private:
196 GURL url_;
197 std::vector<SBFullHash> full_hashes_;
198 // Not owned.
199 SafeBrowsingDatabaseManager::Client* client_;
200
201 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck);
202 };
203
204 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received
205 // the full hash and api results for prefixes of the |url| argument in
206 // CheckApiBlacklistUrl.
207 virtual void HandleGetHashesWithApisResults(
208 std::shared_ptr<SafeBrowsingApiCheck> check,
209 const std::vector<SBFullHashResult>& full_hash_results,
210 const base::TimeDelta& negative_cache_duration);
211
212 // Created and destroyed via StartOnIOThread/StopOnIOThread.
179 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; 213 V4GetHashProtocolManager* v4_get_hash_protocol_manager_;
180 }; // class SafeBrowsingDatabaseManager 214 }; // class SafeBrowsingDatabaseManager
181 215
182 } // namespace safe_browsing 216 } // namespace safe_browsing
183 217
184 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ 218 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/safe_browsing_db/DEPS ('k') | components/safe_browsing_db/database_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698