OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ | 6 #define COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ |
7 | 7 |
8 // A class that reports safebrowsing statistics to Google's SafeBrowsing | 8 // A class that reports basic 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 "base/memory/ref_counted.h" |
18 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" | |
19 #include "components/safe_browsing_db/hit_report.h" | 18 #include "components/safe_browsing_db/hit_report.h" |
20 #include "components/safe_browsing_db/util.h" | 19 #include "components/safe_browsing_db/util.h" |
21 #include "content/public/browser/permission_type.h" | 20 #include "content/public/browser/permission_type.h" |
22 #include "net/log/net_log_with_source.h" | 21 #include "net/log/net_log_with_source.h" |
23 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 class Profile; | |
27 class SkBitmap; | |
28 | |
29 namespace net { | 25 namespace net { |
30 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
31 } // namespace net | 27 } // namespace net |
32 | 28 |
33 namespace safe_browsing { | 29 namespace safe_browsing { |
34 | 30 |
35 class NotificationImageReporter; | 31 class BasePingManager : public net::URLFetcherDelegate { |
36 class PermissionReporter; | |
37 class SafeBrowsingDatabaseManager; | |
38 | |
39 class SafeBrowsingPingManager : public net::URLFetcherDelegate { | |
40 public: | 32 public: |
41 ~SafeBrowsingPingManager() override; | 33 ~BasePingManager() override; |
42 | 34 |
43 // Create an instance of the safe browsing ping manager. | 35 // Create an instance of the safe browsing ping manager. |
44 static std::unique_ptr<SafeBrowsingPingManager> Create( | 36 static std::unique_ptr<BasePingManager> Create( |
45 net::URLRequestContextGetter* request_context_getter, | 37 net::URLRequestContextGetter* request_context_getter, |
46 const SafeBrowsingProtocolConfig& config); | 38 const SafeBrowsingProtocolConfig& config); |
47 | 39 |
48 // net::URLFetcherDelegate interface. | 40 // net::URLFetcherDelegate interface. |
49 void OnURLFetchComplete(const net::URLFetcher* source) override; | 41 void OnURLFetchComplete(const net::URLFetcher* source) override; |
50 | 42 |
51 // Report to Google when a SafeBrowsing warning is shown to the user. | 43 // Report to Google when a SafeBrowsing warning is shown to the user. |
52 // |hit_report.threat_type| should be one of the types known by | 44 // |hit_report.threat_type| should be one of the types known by |
53 // SafeBrowsingtHitUrl. | 45 // SafeBrowsingtHitUrl. |
54 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report); | 46 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report); |
55 | 47 |
56 // Users can opt-in on the SafeBrowsing interstitial to send detailed | 48 // Users can opt-in on the SafeBrowsing interstitial to send detailed |
57 // threat reports. |report| is the serialized report. | 49 // threat reports. |report| is the serialized report. |
58 void ReportThreatDetails(const std::string& report); | 50 void ReportThreatDetails(const std::string& report); |
59 | 51 |
60 // Report permission action to SafeBrowsing servers. | 52 protected: |
61 void ReportPermissionAction(const PermissionReportInfo& report_info); | 53 friend class BasePingManagerTest; |
62 | 54 // Constructs a BasePingManager that issues network requests |
63 // Report notification content image to SafeBrowsing CSD server if necessary. | 55 // using |request_context_getter|. |
64 void ReportNotificationImage( | 56 BasePingManager(net::URLRequestContextGetter* request_context_getter, |
65 Profile* profile, | 57 const SafeBrowsingProtocolConfig& config); |
66 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | |
67 const GURL& origin, | |
68 const SkBitmap& image); | |
69 | 58 |
70 private: | 59 private: |
71 friend class NotificationImageReporterTest; | 60 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestSafeBrowsingHitUrl); |
72 friend class PermissionReporterBrowserTest; | 61 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestThreatDetailsUrl); |
73 friend class SafeBrowsingPingManagerTest; | 62 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportThreatDetails); |
74 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, | 63 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportSafeBrowsingHit); |
75 TestSafeBrowsingHitUrl); | |
76 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, TestThreatDetailsUrl); | |
77 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, | |
78 TestReportThreatDetails); | |
79 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, | |
80 TestReportSafeBrowsingHit); | |
81 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerCertReportingTest, | |
82 UMAOnFailure); | |
83 | 64 |
84 typedef std::set<std::unique_ptr<net::URLFetcher>> Reports; | 65 typedef std::set<std::unique_ptr<net::URLFetcher>> Reports; |
85 | 66 |
86 // Constructs a SafeBrowsingPingManager that issues network requests | |
87 // using |request_context_getter|. | |
88 SafeBrowsingPingManager( | |
89 net::URLRequestContextGetter* request_context_getter, | |
90 const SafeBrowsingProtocolConfig& config); | |
91 | |
92 // Generates URL for reporting safe browsing hits. | 67 // Generates URL for reporting safe browsing hits. |
93 GURL SafeBrowsingHitUrl(const safe_browsing::HitReport& hit_report) const; | 68 GURL SafeBrowsingHitUrl(const safe_browsing::HitReport& hit_report) const; |
94 | 69 |
95 // Generates URL for reporting threat details for users who opt-in. | 70 // Generates URL for reporting threat details for users who opt-in. |
96 GURL ThreatDetailsUrl() const; | 71 GURL ThreatDetailsUrl() const; |
97 | 72 |
98 // Current product version sent in each request. | 73 // Current product version sent in each request. |
99 std::string version_; | 74 std::string version_; |
100 | 75 |
101 // The safe browsing client name sent in each request. | 76 // The safe browsing client name sent in each request. |
102 std::string client_name_; | 77 std::string client_name_; |
103 | 78 |
104 // The context we use to issue network requests. | 79 // The context we use to issue network requests. |
105 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 80 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
106 | 81 |
107 // URL prefix where browser reports hits to the safebrowsing list and | 82 // URL prefix where browser reports hits to the safebrowsing list and |
108 // sends detaild threat reports for UMA users. | 83 // sends detaild threat reports for UMA users. |
109 std::string url_prefix_; | 84 std::string url_prefix_; |
110 | 85 |
111 // Track outstanding SafeBrowsing report fetchers for clean up. | 86 // Track outstanding SafeBrowsing report fetchers for clean up. |
112 // We add both "hit" and "detail" fetchers in this set. | 87 // We add both "hit" and "detail" fetchers in this set. |
113 Reports safebrowsing_reports_; | 88 Reports safebrowsing_reports_; |
114 | 89 |
115 // Sends reports of permission actions. | |
116 std::unique_ptr<PermissionReporter> permission_reporter_; | |
117 | |
118 // Sends reports of notification content images. | |
119 std::unique_ptr<NotificationImageReporter> notification_image_reporter_; | |
120 | |
121 net::NetLogWithSource net_log_; | 90 net::NetLogWithSource net_log_; |
122 | 91 |
123 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager); | 92 DISALLOW_COPY_AND_ASSIGN(BasePingManager); |
124 }; | 93 }; |
125 | 94 |
126 } // namespace safe_browsing | 95 } // namespace safe_browsing |
127 | 96 |
128 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ | 97 #endif // COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_ |
OLD | NEW |