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