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

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

Issue 2254103003: Permission Action Reporting: Bundle report data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review Comments Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_PERMISSION_REPORTER_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 #include <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/permissions/permission_request.h"
14 #include "chrome/browser/permissions/permission_uma_util.h" 13 #include "chrome/browser/permissions/permission_uma_util.h"
15 #include "url/gurl.h" 14 #include "url/gurl.h"
16 15
17 namespace base { 16 namespace base {
18 class Clock; 17 class Clock;
19 } // namespace base 18 } // namespace base
20 19
21 namespace net { 20 namespace net {
22 class ReportSender; 21 class ReportSender;
23 class URLRequestContext; 22 class URLRequestContext;
(...skipping 18 matching lines...) Expand all
42 class PermissionReporter { 41 class PermissionReporter {
43 public: 42 public:
44 // Creates a permission reporter that will send permission reports to 43 // Creates a permission reporter that will send permission reports to
45 // the SafeBrowsing permission action server, using |request_context| as the 44 // the SafeBrowsing permission action server, using |request_context| as the
46 // context for the reports. 45 // context for the reports.
47 explicit PermissionReporter(net::URLRequestContext* request_context); 46 explicit PermissionReporter(net::URLRequestContext* request_context);
48 47
49 ~PermissionReporter(); 48 ~PermissionReporter();
50 49
51 // Sends a serialized permission report to the report collection server. 50 // Sends a serialized permission report to the report collection server.
52 // The permission report includes |origin| as the origin of 51 // The permission report includes the origin of the site requesting the
53 // the site requesting permission, |permission| as the type of permission 52 // permission and other information about the permission action included in
54 // requested, |action| as the action taken, and |gesture_type| as to whether 53 // |report_info|. The report will be serialized using protobuf defined in
55 // the action occurred after a user gesture. It also includes
56 // |num_prior_dismissals| and |num_prior_ignores| the number of dismissals
57 // and ignores for this permission and origin that occurred prior to this
58 // report. The report will be serialized using protobuf defined in
59 // //src/chrome/common/safe_browsing/permission_report.proto 54 // //src/chrome/common/safe_browsing/permission_report.proto
60 // 55 void SendReport(const PermissionReportInfo& report_info);
61 // TODO(kcarattini): Move these params to a PermissionReportInfo struct.
62 void SendReport(const GURL& origin,
63 content::PermissionType permission,
64 PermissionAction action,
65 PermissionSourceUI source_ui,
66 PermissionRequestGestureType gesture_type,
67 int num_prior_dismissals,
68 int num_prior_ignores);
69 56
70 private: 57 private:
71 friend class PermissionReporterBrowserTest; 58 friend class PermissionReporterBrowserTest;
72 friend class PermissionReporterTest; 59 friend class PermissionReporterTest;
73 60
74 // Used by tests. This constructor allows tests to have access to the 61 // Used by tests. This constructor allows tests to have access to the
75 // ReportSender and use a test Clock. 62 // ReportSender and use a test Clock.
76 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, 63 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender,
77 std::unique_ptr<base::Clock> clock); 64 std::unique_ptr<base::Clock> clock);
78 65
79 // Builds and serializes a permission report with |origin| as the origin of 66 // Builds and serializes a permission report with |report_info| included.
80 // the site requesting permission, |permission| as the type of permission 67 // The serialized report is written into |output|. Returns true if the
81 // requested, and |action| as the action taken. The serialized report is 68 // serialization was successful and false otherwise.
82 // written into |output|. Returns true if the serialization was successful and 69 static bool BuildReport(const PermissionReportInfo& report_info,
83 // false otherwise.
84 static bool BuildReport(const GURL& origin,
85 content::PermissionType permission,
86 PermissionAction action,
87 PermissionSourceUI source_ui,
88 PermissionRequestGestureType gesture_type,
89 int num_prior_dismissals,
90 int num_prior_ignores,
91 std::string* output); 70 std::string* output);
92 71
93 // Returns false if the number of reports sent in the last one minute per 72 // Returns false if the number of reports sent in the last one minute per
94 // origin per permission is under a threshold, otherwise true. 73 // origin per permission is under a threshold, otherwise true.
95 bool IsReportThresholdExceeded(content::PermissionType permission, 74 bool IsReportThresholdExceeded(content::PermissionType permission,
96 const GURL& origin); 75 const GURL& origin);
97 76
98 std::unique_ptr<net::ReportSender> permission_report_sender_; 77 std::unique_ptr<net::ReportSender> permission_report_sender_;
99 78
100 // TODO(stefanocs): This might introduce a memory issue since older entries 79 // TODO(stefanocs): This might introduce a memory issue since older entries
101 // are not removed until a new report with the corresponding key is added. We 80 // are not removed until a new report with the corresponding key is added. We
102 // should address this issue if that becomes a problem in the future. 81 // should address this issue if that becomes a problem in the future.
103 std::unordered_map<PermissionAndOrigin, 82 std::unordered_map<PermissionAndOrigin,
104 std::queue<base::Time>, 83 std::queue<base::Time>,
105 PermissionAndOriginHash> 84 PermissionAndOriginHash>
106 report_logs_; 85 report_logs_;
107 86
108 std::unique_ptr<base::Clock> clock_; 87 std::unique_ptr<base::Clock> clock_;
109 88
110 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); 89 DISALLOW_COPY_AND_ASSIGN(PermissionReporter);
111 }; 90 };
112 91
113 } // namespace safe_browsing 92 } // namespace safe_browsing
114 93
115 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ 94 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698