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