| 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ |
| 7 | 7 |
| 8 // A class that reports safebrowsing statistics to Google's SafeBrowsing | 8 // A class that reports safebrowsing statistics to Google's SafeBrowsing |
| 9 // servers. | 9 // servers. |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "chrome/browser/permissions/permission_uma_util.h" |
| 17 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" | 18 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" |
| 18 #include "components/safe_browsing_db/hit_report.h" | 19 #include "components/safe_browsing_db/hit_report.h" |
| 19 #include "components/safe_browsing_db/util.h" | 20 #include "components/safe_browsing_db/util.h" |
| 21 #include "content/public/browser/permission_type.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 22 | 24 |
| 23 namespace certificate_reporting { | 25 namespace certificate_reporting { |
| 24 class ErrorReporter; | 26 class ErrorReporter; |
| 25 } | 27 } |
| 26 | 28 |
| 27 namespace net { | 29 namespace net { |
| 28 class SSLInfo; | 30 class SSLInfo; |
| 29 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
| 30 } // namespace net | 32 } // namespace net |
| 31 | 33 |
| 32 namespace safe_browsing { | 34 namespace safe_browsing { |
| 33 | 35 |
| 36 class PermissionReporter; |
| 37 |
| 34 class SafeBrowsingPingManager : public net::URLFetcherDelegate { | 38 class SafeBrowsingPingManager : public net::URLFetcherDelegate { |
| 35 public: | 39 public: |
| 36 ~SafeBrowsingPingManager() override; | 40 ~SafeBrowsingPingManager() override; |
| 37 | 41 |
| 38 // Create an instance of the safe browsing ping manager. | 42 // Create an instance of the safe browsing ping manager. |
| 39 static SafeBrowsingPingManager* Create( | 43 static SafeBrowsingPingManager* Create( |
| 40 net::URLRequestContextGetter* request_context_getter, | 44 net::URLRequestContextGetter* request_context_getter, |
| 41 const SafeBrowsingProtocolConfig& config); | 45 const SafeBrowsingProtocolConfig& config); |
| 42 | 46 |
| 43 // net::URLFetcherDelegate interface. | 47 // net::URLFetcherDelegate interface. |
| 44 void OnURLFetchComplete(const net::URLFetcher* source) override; | 48 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 45 | 49 |
| 46 // Report to Google when a SafeBrowsing warning is shown to the user. | 50 // Report to Google when a SafeBrowsing warning is shown to the user. |
| 47 // |hit_report.threat_type| should be one of the types known by | 51 // |hit_report.threat_type| should be one of the types known by |
| 48 // SafeBrowsingtHitUrl. | 52 // SafeBrowsingtHitUrl. |
| 49 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report); | 53 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report); |
| 50 | 54 |
| 51 // Users can opt-in on the SafeBrowsing interstitial to send detailed | 55 // Users can opt-in on the SafeBrowsing interstitial to send detailed |
| 52 // threat reports. |report| is the serialized report. | 56 // threat reports. |report| is the serialized report. |
| 53 void ReportThreatDetails(const std::string& report); | 57 void ReportThreatDetails(const std::string& report); |
| 54 | 58 |
| 55 // Users can opt-in on the SSL interstitial to send reports of invalid | 59 // Users can opt-in on the SSL interstitial to send reports of invalid |
| 56 // certificate chains. | 60 // certificate chains. |
| 57 void ReportInvalidCertificateChain(const std::string& serialized_report); | 61 void ReportInvalidCertificateChain(const std::string& serialized_report); |
| 58 | 62 |
| 59 void SetCertificateErrorReporterForTesting( | 63 void SetCertificateErrorReporterForTesting( |
| 60 std::unique_ptr<certificate_reporting::ErrorReporter> | 64 std::unique_ptr<certificate_reporting::ErrorReporter> |
| 61 certificate_error_reporter); | 65 certificate_error_reporter); |
| 62 | 66 |
| 67 // Report permission action to SafeBrowsing servers. |
| 68 void ReportPermissionAction(const GURL& origin, |
| 69 content::PermissionType permission, |
| 70 PermissionAction action); |
| 71 |
| 63 private: | 72 private: |
| 64 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, | 73 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, |
| 65 TestSafeBrowsingHitUrl); | 74 TestSafeBrowsingHitUrl); |
| 66 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, TestThreatDetailsUrl); | 75 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, TestThreatDetailsUrl); |
| 67 | 76 |
| 68 typedef std::set<const net::URLFetcher*> Reports; | 77 typedef std::set<const net::URLFetcher*> Reports; |
| 69 | 78 |
| 70 // Constructs a SafeBrowsingPingManager that issues network requests | 79 // Constructs a SafeBrowsingPingManager that issues network requests |
| 71 // using |request_context_getter|. | 80 // using |request_context_getter|. |
| 72 SafeBrowsingPingManager( | 81 SafeBrowsingPingManager( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 93 std::string url_prefix_; | 102 std::string url_prefix_; |
| 94 | 103 |
| 95 // Track outstanding SafeBrowsing report fetchers for clean up. | 104 // Track outstanding SafeBrowsing report fetchers for clean up. |
| 96 // We add both "hit" and "detail" fetchers in this set. | 105 // We add both "hit" and "detail" fetchers in this set. |
| 97 Reports safebrowsing_reports_; | 106 Reports safebrowsing_reports_; |
| 98 | 107 |
| 99 // Sends reports of invalid SSL certificate chains. | 108 // Sends reports of invalid SSL certificate chains. |
| 100 std::unique_ptr<certificate_reporting::ErrorReporter> | 109 std::unique_ptr<certificate_reporting::ErrorReporter> |
| 101 certificate_error_reporter_; | 110 certificate_error_reporter_; |
| 102 | 111 |
| 112 // Sends reports of permission actions. |
| 113 std::unique_ptr<PermissionReporter> permission_reporter_; |
| 114 |
| 103 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager); | 115 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager); |
| 104 }; | 116 }; |
| 105 | 117 |
| 106 } // namespace safe_browsing | 118 } // namespace safe_browsing |
| 107 | 119 |
| 108 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ | 120 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ |
| OLD | NEW |