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 class SafeBrowsingApiCheck { | |
|
Nathan Parker
2016/04/15 23:14:29
Does this class need to be public in SBDbMgr? Exte
kcarattini
2016/04/18 06:56:56
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 // Not owned. | |
| 80 SafeBrowsingDatabaseManager::Client* client_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck); | |
| 83 }; | |
| 66 | 84 |
| 67 // Returns true if URL-checking is supported on this build+device. | 85 // Returns true if URL-checking is supported on this build+device. |
| 68 // If false, calls to CheckBrowseUrl may dcheck-fail. | 86 // If false, calls to CheckBrowseUrl may dcheck-fail. |
| 69 virtual bool IsSupported() const = 0; | 87 virtual bool IsSupported() const = 0; |
| 70 | 88 |
| 71 // Returns the ThreatSource for this implementation. | 89 // Returns the ThreatSource for this implementation. |
| 72 virtual ThreatSource GetThreatSource() const = 0; | 90 virtual ThreatSource GetThreatSource() const = 0; |
| 73 | 91 |
| 74 // Returns true if checks are never done synchronously, and therefore | 92 // Returns true if checks are never done synchronously, and therefore |
| 75 // always have some latency. | 93 // always have some latency. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 // an error occurs. This method must be called on the IO thread. | 159 // an error occurs. This method must be called on the IO thread. |
| 142 virtual bool MatchModuleWhitelistString(const std::string& str) = 0; | 160 virtual bool MatchModuleWhitelistString(const std::string& str) = 0; |
| 143 | 161 |
| 144 // Check if the CSD malware IP matching kill switch is turned on. | 162 // Check if the CSD malware IP matching kill switch is turned on. |
| 145 virtual bool IsMalwareKillSwitchOn() = 0; | 163 virtual bool IsMalwareKillSwitchOn() = 0; |
| 146 | 164 |
| 147 // Check if the CSD whitelist kill switch is turned on. | 165 // Check if the CSD whitelist kill switch is turned on. |
| 148 virtual bool IsCsdWhitelistKillSwitchOn() = 0; | 166 virtual bool IsCsdWhitelistKillSwitchOn() = 0; |
| 149 | 167 |
| 150 // Called on the IO thread to cancel a pending check if the result is no | 168 // 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. | 169 // longer needed. Also called after the result has been handled. Api checks |
| 170 // are handled separately. To cancel an API check use CancelApiCheck. | |
| 152 virtual void CancelCheck(Client* client) = 0; | 171 virtual void CancelCheck(Client* client) = 0; |
| 153 | 172 |
| 173 // TODO(kcarattini): Add a CancelApiCheck method. | |
| 174 | |
| 154 // Called on the IO thread to check if the given url has blacklisted APIs. | 175 // 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. | 176 // "client" is called asynchronously with the result when it is ready. |
| 156 // This method has the same implementation for both the local and remote | 177 // This method has the same implementation for both the local and remote |
| 157 // database managers since it pings Safe Browsing servers directly without | 178 // database managers since it pings Safe Browsing servers directly without |
| 158 // accessing the database at all. | 179 // accessing the database at all. Returns true if we can synchronously |
| 159 virtual void CheckApiBlacklistUrl(const GURL& url, Client* client); | 180 // determine that the url is safe. Otherwise it returns false, and "client" is |
| 181 // called asynchronously with the result when it is ready. | |
| 182 virtual bool CheckApiBlacklistUrl(const GURL& url, Client* client); | |
| 183 | |
| 184 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received | |
| 185 // the full hash and api results for prefixes of the |url| argument in | |
| 186 // CheckApiBlacklistUrl. | |
| 187 virtual void HandleGetHashesWithApisResults( | |
|
Nathan Parker
2016/04/15 23:14:29
protected?
kcarattini
2016/04/18 06:56:56
Done.
| |
| 188 std::shared_ptr<SafeBrowsingApiCheck> check, | |
| 189 const std::vector<SBFullHashResult>& full_hash_results, | |
| 190 const base::TimeDelta& negative_cache_duration); | |
| 160 | 191 |
| 161 // Called to initialize objects that are used on the io_thread, such as the | 192 // 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 | 193 // v4 protocol manager. This may be called multiple times during the life of |
| 163 // the DatabaseManager. Must be called on IO thread. | 194 // the DatabaseManager. Must be called on IO thread. |
| 164 virtual void StartOnIOThread( | 195 virtual void StartOnIOThread( |
| 165 net::URLRequestContextGetter* request_context_getter, | 196 net::URLRequestContextGetter* request_context_getter, |
| 166 const V4ProtocolConfig& config); | 197 const V4ProtocolConfig& config); |
| 167 | 198 |
| 168 // Called to stop or shutdown operations on the io_thread. | 199 // Called to stop or shutdown operations on the io_thread. |
| 169 virtual void StopOnIOThread(bool shutdown); | 200 virtual void StopOnIOThread(bool shutdown); |
| 170 | 201 |
| 171 protected: | 202 protected: |
| 172 SafeBrowsingDatabaseManager(); | 203 SafeBrowsingDatabaseManager(); |
| 173 | 204 |
| 174 virtual ~SafeBrowsingDatabaseManager(); | 205 virtual ~SafeBrowsingDatabaseManager(); |
| 175 | 206 |
| 176 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; | 207 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; |
| 177 | 208 |
| 178 // Created and destroyed via StartonIOThread/StopOnIOThread. | 209 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 210 CheckApiBlacklistUrlPrefixes); | |
| 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_ |
| OLD | NEW |