| 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 CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 virtual ~Client() {} | 99 virtual ~Client() {} |
| 100 | 100 |
| 101 // Called when the result of checking a browse URL is known. | 101 // Called when the result of checking a browse URL is known. |
| 102 virtual void OnCheckBrowseUrlResult(const GURL& url, | 102 virtual void OnCheckBrowseUrlResult(const GURL& url, |
| 103 SBThreatType threat_type) {} | 103 SBThreatType threat_type) {} |
| 104 | 104 |
| 105 // Called when the result of checking a download URL is known. | 105 // Called when the result of checking a download URL is known. |
| 106 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, | 106 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, |
| 107 SBThreatType threat_type) {} | 107 SBThreatType threat_type) {} |
| 108 | 108 |
| 109 // Called when the result of checking a download binary hash is known. | |
| 110 virtual void OnCheckDownloadHashResult(const std::string& hash, | |
| 111 SBThreatType threat_type) {} | |
| 112 | |
| 113 // Called when the result of checking a set of extensions is known. | 109 // Called when the result of checking a set of extensions is known. |
| 114 virtual void OnCheckExtensionsResult( | 110 virtual void OnCheckExtensionsResult( |
| 115 const std::set<std::string>& threats) {} | 111 const std::set<std::string>& threats) {} |
| 116 }; | 112 }; |
| 117 | 113 |
| 118 // Creates the safe browsing service. Need to initialize before using. | 114 // Creates the safe browsing service. Need to initialize before using. |
| 119 explicit SafeBrowsingDatabaseManager( | 115 explicit SafeBrowsingDatabaseManager( |
| 120 const scoped_refptr<SafeBrowsingService>& service); | 116 const scoped_refptr<SafeBrowsingService>& service); |
| 121 | 117 |
| 122 // Returns true if the url's scheme can be checked. | 118 // Returns true if the url's scheme can be checked. |
| 123 bool CanCheckUrl(const GURL& url) const; | 119 bool CanCheckUrl(const GURL& url) const; |
| 124 | 120 |
| 125 // Returns whether download protection is enabled. | 121 // Returns whether download protection is enabled. |
| 126 bool download_protection_enabled() const { | 122 bool download_protection_enabled() const { |
| 127 return enable_download_protection_; | 123 return enable_download_protection_; |
| 128 } | 124 } |
| 129 | 125 |
| 130 // Called on the IO thread to check if the given url is safe or not. If we | 126 // Called on the IO thread to check if the given url is safe or not. If we |
| 131 // can synchronously determine that the url is safe, CheckUrl returns true. | 127 // can synchronously determine that the url is safe, CheckUrl returns true. |
| 132 // Otherwise it returns false, and "client" is called asynchronously with the | 128 // Otherwise it returns false, and "client" is called asynchronously with the |
| 133 // result when it is ready. | 129 // result when it is ready. |
| 134 virtual bool CheckBrowseUrl(const GURL& url, Client* client); | 130 virtual bool CheckBrowseUrl(const GURL& url, Client* client); |
| 135 | 131 |
| 136 // Check if the prefix for |url| is in safebrowsing download add lists. | 132 // Check if the prefix for |url| is in safebrowsing download add lists. |
| 137 // Result will be passed to callback in |client|. | 133 // Result will be passed to callback in |client|. |
| 138 virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain, | 134 virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain, |
| 139 Client* client); | 135 Client* client); |
| 140 | 136 |
| 141 // Check if the prefix for |full_hash| is in safebrowsing binhash add lists. | |
| 142 // Result will be passed to callback in |client|. | |
| 143 virtual bool CheckDownloadHash(const std::string& full_hash, Client* client); | |
| 144 | |
| 145 // Check which prefixes in |extension_ids| are in the safebrowsing blacklist. | 137 // Check which prefixes in |extension_ids| are in the safebrowsing blacklist. |
| 146 // Returns true if not, false if further checks need to be made in which case | 138 // Returns true if not, false if further checks need to be made in which case |
| 147 // the result will be passed to |client|. | 139 // the result will be passed to |client|. |
| 148 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | 140 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids, |
| 149 Client* client); | 141 Client* client); |
| 150 | 142 |
| 151 // Check if the given url is on the side-effect free whitelist. | 143 // Check if the given url is on the side-effect free whitelist. |
| 152 // Can be called on any thread. Returns false if the check cannot be performed | 144 // Can be called on any thread. Returns false if the check cannot be performed |
| 153 // (e.g. because we are disabled or because of an invalid scheme in the URL). | 145 // (e.g. because we are disabled or because of an invalid scheme in the URL). |
| 154 // Otherwise, returns true if the URL is on the whitelist based on matching | 146 // Otherwise, returns true if the URL is on the whitelist based on matching |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 307 |
| 316 // Internal worker function for processing full hashes. | 308 // Internal worker function for processing full hashes. |
| 317 void OnHandleGetHashResults(SafeBrowsingCheck* check, | 309 void OnHandleGetHashResults(SafeBrowsingCheck* check, |
| 318 const std::vector<SBFullHashResult>& full_hashes); | 310 const std::vector<SBFullHashResult>& full_hashes); |
| 319 | 311 |
| 320 // Run one check against |full_hashes|. Returns |true| if the check | 312 // Run one check against |full_hashes|. Returns |true| if the check |
| 321 // finds a match in |full_hashes|. | 313 // finds a match in |full_hashes|. |
| 322 bool HandleOneCheck(SafeBrowsingCheck* check, | 314 bool HandleOneCheck(SafeBrowsingCheck* check, |
| 323 const std::vector<SBFullHashResult>& full_hashes); | 315 const std::vector<SBFullHashResult>& full_hashes); |
| 324 | 316 |
| 325 // Checks the download hash on safe_browsing_thread_. | |
| 326 void CheckDownloadHashOnSBThread(SafeBrowsingCheck* check); | |
| 327 | |
| 328 // Invoked by CheckDownloadUrl. It checks the download URL on | 317 // Invoked by CheckDownloadUrl. It checks the download URL on |
| 329 // safe_browsing_thread_. | 318 // safe_browsing_thread_. |
| 330 void CheckDownloadUrlOnSBThread(SafeBrowsingCheck* check); | 319 void CheckDownloadUrlOnSBThread(SafeBrowsingCheck* check); |
| 331 | 320 |
| 332 // The callback function when a safebrowsing check is timed out. Client will | 321 // The callback function when a safebrowsing check is timed out. Client will |
| 333 // be notified that the safebrowsing check is SAFE when this happens. | 322 // be notified that the safebrowsing check is SAFE when this happens. |
| 334 void TimeoutCallback(SafeBrowsingCheck* check); | 323 void TimeoutCallback(SafeBrowsingCheck* check); |
| 335 | 324 |
| 336 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes. | 325 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes. |
| 337 void CheckDownloadUrlDone(SafeBrowsingCheck* check); | 326 void CheckDownloadUrlDone(SafeBrowsingCheck* check); |
| 338 | 327 |
| 339 // Calls the Client's callback on IO thread after CheckDownloadHash finishes. | |
| 340 void CheckDownloadHashDone(SafeBrowsingCheck* check); | |
| 341 | |
| 342 // Checks all extension ID hashes on safe_browsing_thread_. | 328 // Checks all extension ID hashes on safe_browsing_thread_. |
| 343 void CheckExtensionIDsOnSBThread(SafeBrowsingCheck* check); | 329 void CheckExtensionIDsOnSBThread(SafeBrowsingCheck* check); |
| 344 | 330 |
| 345 // Helper function that calls safe browsing client and cleans up |checks_|. | 331 // Helper function that calls safe browsing client and cleans up |checks_|. |
| 346 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); | 332 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); |
| 347 | 333 |
| 348 // Helper function to set |check| with default values and start a safe | 334 // Helper function to set |check| with default values and start a safe |
| 349 // browsing check with timeout of |timeout|. |task| will be called on | 335 // browsing check with timeout of |timeout|. |task| will be called on |
| 350 // success, otherwise TimeoutCallback will be called. | 336 // success, otherwise TimeoutCallback will be called. |
| 351 void StartSafeBrowsingCheck(SafeBrowsingCheck* check, | 337 void StartSafeBrowsingCheck(SafeBrowsingCheck* check, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 405 |
| 420 std::deque<QueuedCheck> queued_checks_; | 406 std::deque<QueuedCheck> queued_checks_; |
| 421 | 407 |
| 422 // Timeout to use for safe browsing checks. | 408 // Timeout to use for safe browsing checks. |
| 423 base::TimeDelta check_timeout_; | 409 base::TimeDelta check_timeout_; |
| 424 | 410 |
| 425 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); | 411 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); |
| 426 }; | 412 }; |
| 427 | 413 |
| 428 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 414 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| OLD | NEW |