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

Side by Side Diff: components/safe_browsing/base_ping_manager.h

Issue 2650973005: Componentize ping_manager (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « components/safe_browsing/DEPS ('k') | components/safe_browsing/base_ping_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
20 #include "content/public/browser/permission_type.h"
21 #include "net/log/net_log_with_source.h" 21 #include "net/log/net_log_with_source.h"
22 #include "net/url_request/url_fetcher_delegate.h" 22 #include "net/url_request/url_fetcher_delegate.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 class Profile;
26 class SkBitmap;
27
28 namespace net { 25 namespace net {
29 class URLRequestContextGetter; 26 class URLRequestContextGetter;
30 } // namespace net 27 } // namespace net
31 28
32 namespace safe_browsing { 29 namespace safe_browsing {
33 30
34 class NotificationImageReporter; 31 class BasePingManager : public net::URLFetcherDelegate {
35 class PermissionReporter;
36 class SafeBrowsingDatabaseManager;
37
38 class SafeBrowsingPingManager : public net::URLFetcherDelegate {
39 public: 32 public:
40 ~SafeBrowsingPingManager() override; 33 ~BasePingManager() override;
41 34
42 // Create an instance of the safe browsing ping manager. 35 // Create an instance of the safe browsing ping manager.
43 static std::unique_ptr<SafeBrowsingPingManager> Create( 36 static std::unique_ptr<BasePingManager> Create(
44 net::URLRequestContextGetter* request_context_getter, 37 net::URLRequestContextGetter* request_context_getter,
45 const SafeBrowsingProtocolConfig& config); 38 const SafeBrowsingProtocolConfig& config);
46 39
47 // net::URLFetcherDelegate interface. 40 // net::URLFetcherDelegate interface.
48 void OnURLFetchComplete(const net::URLFetcher* source) override; 41 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 42
50 // 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.
51 // |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
52 // SafeBrowsingtHitUrl. 45 // SafeBrowsingtHitUrl.
53 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report); 46 void ReportSafeBrowsingHit(const safe_browsing::HitReport& hit_report);
54 47
55 // Users can opt-in on the SafeBrowsing interstitial to send detailed 48 // Users can opt-in on the SafeBrowsing interstitial to send detailed
56 // threat reports. |report| is the serialized report. 49 // threat reports. |report| is the serialized report.
57 void ReportThreatDetails(const std::string& report); 50 void ReportThreatDetails(const std::string& report);
58 51
59 // Report permission action to SafeBrowsing servers. 52 protected:
60 void ReportPermissionAction(const PermissionReportInfo& report_info); 53 friend class BasePingManagerTest;
61 54 // Constructs a BasePingManager that issues network requests
62 // Report notification content image to SafeBrowsing CSD server if necessary. 55 // using |request_context_getter|.
63 void ReportNotificationImage( 56 BasePingManager(net::URLRequestContextGetter* request_context_getter,
64 Profile* profile, 57 const SafeBrowsingProtocolConfig& config);
65 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager,
66 const GURL& origin,
67 const SkBitmap& image);
68 58
69 private: 59 private:
70 friend class NotificationImageReporterTest; 60 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestSafeBrowsingHitUrl);
71 friend class PermissionReporterBrowserTest; 61 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestThreatDetailsUrl);
72 friend class SafeBrowsingPingManagerTest; 62 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportThreatDetails);
73 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, 63 FRIEND_TEST_ALL_PREFIXES(BasePingManagerTest, TestReportSafeBrowsingHit);
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,
81 UMAOnFailure);
82 64
83 typedef std::set<std::unique_ptr<net::URLFetcher>> Reports; 65 typedef std::set<std::unique_ptr<net::URLFetcher>> Reports;
84 66
85 // Constructs a SafeBrowsingPingManager that issues network requests
86 // using |request_context_getter|.
87 SafeBrowsingPingManager(
88 net::URLRequestContextGetter* request_context_getter,
89 const SafeBrowsingProtocolConfig& config);
90
91 // Generates URL for reporting safe browsing hits. 67 // Generates URL for reporting safe browsing hits.
92 GURL SafeBrowsingHitUrl(const safe_browsing::HitReport& hit_report) const; 68 GURL SafeBrowsingHitUrl(const safe_browsing::HitReport& hit_report) const;
93 69
94 // Generates URL for reporting threat details for users who opt-in. 70 // Generates URL for reporting threat details for users who opt-in.
95 GURL ThreatDetailsUrl() const; 71 GURL ThreatDetailsUrl() const;
96 72
97 // Current product version sent in each request. 73 // Current product version sent in each request.
98 std::string version_; 74 std::string version_;
99 75
100 // The safe browsing client name sent in each request. 76 // The safe browsing client name sent in each request.
101 std::string client_name_; 77 std::string client_name_;
102 78
103 // The context we use to issue network requests. 79 // The context we use to issue network requests.
104 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 80 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
105 81
106 // URL prefix where browser reports hits to the safebrowsing list and 82 // URL prefix where browser reports hits to the safebrowsing list and
107 // sends detaild threat reports for UMA users. 83 // sends detaild threat reports for UMA users.
108 std::string url_prefix_; 84 std::string url_prefix_;
109 85
110 // Track outstanding SafeBrowsing report fetchers for clean up. 86 // Track outstanding SafeBrowsing report fetchers for clean up.
111 // We add both "hit" and "detail" fetchers in this set. 87 // We add both "hit" and "detail" fetchers in this set.
112 Reports safebrowsing_reports_; 88 Reports safebrowsing_reports_;
113 89
114 // Sends reports of permission actions.
115 std::unique_ptr<PermissionReporter> permission_reporter_;
116
117 // Sends reports of notification content images.
118 std::unique_ptr<NotificationImageReporter> notification_image_reporter_;
119
120 net::NetLogWithSource net_log_; 90 net::NetLogWithSource net_log_;
121 91
122 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingPingManager); 92 DISALLOW_COPY_AND_ASSIGN(BasePingManager);
123 }; 93 };
124 94
125 } // namespace safe_browsing 95 } // namespace safe_browsing
126 96
127 #endif // CHROME_BROWSER_SAFE_BROWSING_PING_MANAGER_H_ 97 #endif // COMPONENTS_SAFE_BROWSING_BASE_PING_MANAGER_H_
OLDNEW
« no previous file with comments | « components/safe_browsing/DEPS ('k') | components/safe_browsing/base_ping_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698