Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/safe_browsing/ping_manager.h

Issue 2650973005: Componentize ping_manager (Closed)
Patch Set: fix deps Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/browser/permission_type.h"
22 #include "net/log/net_log_with_source.h"
23 #include "net/url_request/url_fetcher_delegate.h"
24 #include "url/gurl.h"
25
26 class Profile;
27 class SkBitmap; 12 class SkBitmap;
28 13
29 namespace net { 14 namespace net {
30 class URLRequestContextGetter; 15 class URLRequestContextGetter;
31 } // namespace net 16 } // namespace net
32 17
33 namespace safe_browsing { 18 namespace safe_browsing {
34 19
35 class NotificationImageReporter; 20 class NotificationImageReporter;
36 class PermissionReporter; 21 class PermissionReporter;
37 class SafeBrowsingDatabaseManager; 22 class SafeBrowsingDatabaseManager;
38 23
39 class SafeBrowsingPingManager : public net::URLFetcherDelegate { 24 class SafeBrowsingPingManager : public BasePingManager {
40 public: 25 public:
41 ~SafeBrowsingPingManager() override; 26 ~SafeBrowsingPingManager() override;
42 27
43 // Create an instance of the safe browsing ping manager. 28 // Create an instance of the safe browsing ping manager.
44 static std::unique_ptr<SafeBrowsingPingManager> Create( 29 static std::unique_ptr<SafeBrowsingPingManager> Create(
45 net::URLRequestContextGetter* request_context_getter, 30 net::URLRequestContextGetter* request_context_getter,
46 const SafeBrowsingProtocolConfig& config); 31 const SafeBrowsingProtocolConfig& config);
47 32
48 // net::URLFetcherDelegate interface.
49 void OnURLFetchComplete(const net::URLFetcher* source) override;
50
51 // 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
53 // SafeBrowsingtHitUrl.
54 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report);
55
56 // Users can opt-in on the SafeBrowsing interstitial to send detailed
57 // threat reports. |report| is the serialized report.
58 void ReportThreatDetails(const std::string& report);
59
60 // Report permission action to SafeBrowsing servers. 33 // Report permission action to SafeBrowsing servers.
61 void ReportPermissionAction(const PermissionReportInfo& report_info); 34 void ReportPermissionAction(const PermissionReportInfo& report_info);
62 35
63 // Report notification content image to SafeBrowsing CSD server if necessary. 36 // Report notification content image to SafeBrowsing CSD server if necessary.
64 void ReportNotificationImage( 37 void ReportNotificationImage(
65 Profile* profile, 38 Profile* profile,
66 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, 39 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
67 const GURL& origin, 40 const GURL& origin,
68 const SkBitmap& image); 41 const SkBitmap& image);
69 42
70 private: 43 private:
71 friend class NotificationImageReporterTest; 44 friend class NotificationImageReporterTest;
72 friend class PermissionReporterBrowserTest; 45 friend class PermissionReporterBrowserTest;
73 friend class SafeBrowsingPingManagerTest;
74 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest,
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, 46 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerCertReportingTest,
82 UMAOnFailure); 47 UMAOnFailure);
83 48
84 typedef std::set<std::unique_ptr<net::URLFetcher>> Reports;
85
86 // Constructs a SafeBrowsingPingManager that issues network requests 49 // Constructs a SafeBrowsingPingManager that issues network requests
87 // using |request_context_getter|. 50 // using |request_context_getter|.
88 SafeBrowsingPingManager( 51 SafeBrowsingPingManager(
89 net::URLRequestContextGetter* request_context_getter, 52 net::URLRequestContextGetter* request_context_getter,
90 const SafeBrowsingProtocolConfig& config); 53 const SafeBrowsingProtocolConfig& config);
91 54
92 // Generates URL for reporting safe browsing hits.
93 GURL SafeBrowsingHitUrl(const safe_browsing::HitReport& hit_report) const;
94
95 // Generates URL for reporting threat details for users who opt-in.
96 GURL ThreatDetailsUrl() const;
97
98 // Current product version sent in each request.
99 std::string version_;
100
101 // The safe browsing client name sent in each request.
102 std::string client_name_;
103
104 // The context we use to issue network requests.
105 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
106
107 // URL prefix where browser reports hits to the safebrowsing list and
108 // sends detaild threat reports for UMA users.
109 std::string url_prefix_;
110
111 // Track outstanding SafeBrowsing report fetchers for clean up.
112 // We add both "hit" and "detail" fetchers in this set.
113 Reports safebrowsing_reports_;
114
115 // Sends reports of permission actions. 55 // Sends reports of permission actions.
116 std::unique_ptr<PermissionReporter> permission_reporter_; 56 std::unique_ptr<PermissionReporter> permission_reporter_;
117 57
118 // Sends reports of notification content images. 58 // Sends reports of notification content images.
119 std::unique_ptr<NotificationImageReporter> notification_image_reporter_; 59 std::unique_ptr<NotificationImageReporter> notification_image_reporter_;
120 60
121 net::NetLogWithSource net_log_;
122
123 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager); 61 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager);
124 }; 62 };
125 63
126 } // namespace safe_browsing 64 } // namespace safe_browsing
127 65
128 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ 66 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698