Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| 68 // Bundled client info for an API abuse hash prefix check. | |
| 69 struct SafeBrowsingApiCheck { | |
|
Nathan Parker
2016/04/11 16:28:50
This could be a class, since you've got public and
kcarattini
2016/04/12 01:27:02
Done.
| |
| 70 public: | |
| 71 SafeBrowsingApiCheck(const GURL& url, | |
| 72 const std::vector<SBFullHash>& full_hashes, | |
| 73 Client* client); | |
| 74 ~SafeBrowsingApiCheck(); | |
| 75 | |
| 76 private: | |
| 77 GURL url; | |
| 78 std::vector<SBFullHash> full_hashes; | |
| 79 SafeBrowsingDatabaseManager::Client* client; | |
|
Nathan Parker
2016/04/11 16:28:50
// Not owned
kcarattini
2016/04/12 01:27:02
Done.
| |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck); | |
| 82 }; | |
| 66 | 83 |
| 67 // Returns true if URL-checking is supported on this build+device. | 84 // Returns true if URL-checking is supported on this build+device. |
| 68 // If false, calls to CheckBrowseUrl may dcheck-fail. | 85 // If false, calls to CheckBrowseUrl may dcheck-fail. |
| 69 virtual bool IsSupported() const = 0; | 86 virtual bool IsSupported() const = 0; |
| 70 | 87 |
| 71 // Returns the ThreatSource for this implementation. | 88 // Returns the ThreatSource for this implementation. |
| 72 virtual ThreatSource GetThreatSource() const = 0; | 89 virtual ThreatSource GetThreatSource() const = 0; |
| 73 | 90 |
| 74 // Returns true if checks are never done synchronously, and therefore | 91 // Returns true if checks are never done synchronously, and therefore |
| 75 // always have some latency. | 92 // always have some latency. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 virtual bool MatchModuleWhitelistString(const std::string& str) = 0; | 159 virtual bool MatchModuleWhitelistString(const std::string& str) = 0; |
| 143 | 160 |
| 144 // Check if the CSD malware IP matching kill switch is turned on. | 161 // Check if the CSD malware IP matching kill switch is turned on. |
| 145 virtual bool IsMalwareKillSwitchOn() = 0; | 162 virtual bool IsMalwareKillSwitchOn() = 0; |
| 146 | 163 |
| 147 // Check if the CSD whitelist kill switch is turned on. | 164 // Check if the CSD whitelist kill switch is turned on. |
| 148 virtual bool IsCsdWhitelistKillSwitchOn() = 0; | 165 virtual bool IsCsdWhitelistKillSwitchOn() = 0; |
| 149 | 166 |
| 150 // Called on the IO thread to cancel a pending check if the result is no | 167 // 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. | 168 // longer needed. Also called after the result has been handled. |
| 152 virtual void CancelCheck(Client* client) = 0; | 169 virtual void CancelCheck(Client* client) = 0; |
|
Nathan Parker
2016/04/11 16:28:50
Does this apply to CheckAPIBlacklistUrl clients?
kcarattini
2016/04/12 01:27:02
There's no functionality for it at the moment but
Nathan Parker
2016/04/12 04:35:49
What happens if the caller (who owns the Client) n
kcarattini
2016/04/12 07:47:49
I've added a TODO to add a CancelApiCheck method.
| |
| 153 | 170 |
| 154 // Called on the IO thread to check if the given url has blacklisted APIs. | 171 // 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. | 172 // "client" is called asynchronously with the result when it is ready. |
| 156 // This method has the same implementation for both the local and remote | 173 // This method has the same implementation for both the local and remote |
| 157 // database managers since it pings Safe Browsing servers directly without | 174 // database managers since it pings Safe Browsing servers directly without |
| 158 // accessing the database at all. | 175 // accessing the database at all. Returns true if we can synchronously |
| 159 virtual void CheckApiBlacklistUrl(const GURL& url, Client* client); | 176 // determine that the url is safe. Otherwise it returns false, and "client" is |
| 177 // called asynchronously with the result when it is ready. | |
| 178 virtual bool CheckApiBlacklistUrl(const GURL& url, Client* client); | |
| 179 | |
| 180 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received | |
| 181 // the full hash and api results for prefixes of the |url| argument in | |
| 182 // CheckApiBlacklistUrl. | |
| 183 virtual void HandleGetHashesWithApisResults(SafeBrowsingApiCheck* check, | |
| 184 const std::vector<SBFullHashResult>& full_hash_results, | |
| 185 const base::TimeDelta& negative_cache_duration); | |
| 160 | 186 |
| 161 // Called to initialize objects that are used on the io_thread, such as the | 187 // 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 | 188 // v4 protocol manager. This may be called multiple times during the life of |
| 163 // the DatabaseManager. Must be called on IO thread. | 189 // the DatabaseManager. Must be called on IO thread. |
| 164 virtual void StartOnIOThread( | 190 virtual void StartOnIOThread( |
| 165 net::URLRequestContextGetter* request_context_getter, | 191 net::URLRequestContextGetter* request_context_getter, |
| 166 const V4ProtocolConfig& config); | 192 const V4ProtocolConfig& config); |
| 167 | 193 |
| 168 // Called to stop or shutdown operations on the io_thread. | 194 // Called to stop or shutdown operations on the io_thread. |
| 169 virtual void StopOnIOThread(bool shutdown); | 195 virtual void StopOnIOThread(bool shutdown); |
| 170 | 196 |
| 171 protected: | 197 protected: |
| 172 SafeBrowsingDatabaseManager(); | 198 SafeBrowsingDatabaseManager(); |
| 173 | 199 |
| 174 virtual ~SafeBrowsingDatabaseManager(); | 200 virtual ~SafeBrowsingDatabaseManager(); |
| 175 | 201 |
| 176 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; | 202 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; |
| 177 | 203 |
| 178 // Created and destroyed via StartonIOThread/StopOnIOThread. | 204 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 205 CheckApiBlacklistUrlPrefixes); | |
| 206 | |
| 207 // Created and destroyed via StartOnIOThread/StopOnIOThread. | |
| 179 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; | 208 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; |
| 180 }; // class SafeBrowsingDatabaseManager | 209 }; // class SafeBrowsingDatabaseManager |
| 181 | 210 |
| 182 } // namespace safe_browsing | 211 } // namespace safe_browsing |
| 183 | 212 |
| 184 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 213 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
| OLD | NEW |