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

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

Issue 2250893002: Permission Action Reporting: Add num_prior_* fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@par-new-fields-proto
Patch Set: todo 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>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // the SafeBrowsing permission action server, using |request_context| as the 45 // the SafeBrowsing permission action server, using |request_context| as the
46 // context for the reports. 46 // context for the reports.
47 explicit PermissionReporter(net::URLRequestContext* request_context); 47 explicit PermissionReporter(net::URLRequestContext* request_context);
48 48
49 ~PermissionReporter(); 49 ~PermissionReporter();
50 50
51 // Sends a serialized permission report to the report collection server. 51 // Sends a serialized permission report to the report collection server.
52 // The permission report includes |origin| as the origin of 52 // The permission report includes |origin| as the origin of
53 // the site requesting permission, |permission| as the type of permission 53 // the site requesting permission, |permission| as the type of permission
54 // requested, |action| as the action taken, and |gesture_type| as to whether 54 // requested, |action| as the action taken, and |gesture_type| as to whether
55 // the action occurred after a user gesture. The report will be serialized 55 // the action occurred after a user gesture. It also includes
56 // using protobuf defined in 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
57 // //src/chrome/common/safe_browsing/permission_report.proto 59 // //src/chrome/common/safe_browsing/permission_report.proto
60 //
61 // TODO(kcarattini): Move these params to a PermissionReportInfo struct.
58 void SendReport(const GURL& origin, 62 void SendReport(const GURL& origin,
59 content::PermissionType permission, 63 content::PermissionType permission,
60 PermissionAction action, 64 PermissionAction action,
61 PermissionSourceUI source_ui, 65 PermissionSourceUI source_ui,
62 PermissionRequestGestureType gesture_type); 66 PermissionRequestGestureType gesture_type,
67 int num_prior_dismissals,
68 int num_prior_ignores);
63 69
64 private: 70 private:
65 friend class PermissionReporterBrowserTest; 71 friend class PermissionReporterBrowserTest;
66 friend class PermissionReporterTest; 72 friend class PermissionReporterTest;
67 73
68 // Used by tests. This constructor allows tests to have access to the 74 // Used by tests. This constructor allows tests to have access to the
69 // ReportSender and use a test Clock. 75 // ReportSender and use a test Clock.
70 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, 76 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender,
71 std::unique_ptr<base::Clock> clock); 77 std::unique_ptr<base::Clock> clock);
72 78
73 // Builds and serializes a permission report with |origin| as the origin of 79 // Builds and serializes a permission report with |origin| as the origin of
74 // the site requesting permission, |permission| as the type of permission 80 // the site requesting permission, |permission| as the type of permission
75 // requested, and |action| as the action taken. The serialized report is 81 // requested, and |action| as the action taken. The serialized report is
76 // written into |output|. Returns true if the serialization was successful and 82 // written into |output|. Returns true if the serialization was successful and
77 // false otherwise. 83 // false otherwise.
78 static bool BuildReport(const GURL& origin, 84 static bool BuildReport(const GURL& origin,
79 content::PermissionType permission, 85 content::PermissionType permission,
80 PermissionAction action, 86 PermissionAction action,
81 PermissionSourceUI source_ui, 87 PermissionSourceUI source_ui,
82 PermissionRequestGestureType gesture_type, 88 PermissionRequestGestureType gesture_type,
89 int num_prior_dismissals,
90 int num_prior_ignores,
83 std::string* output); 91 std::string* output);
84 92
85 // Returns false if the number of reports sent in the last one minute per 93 // Returns false if the number of reports sent in the last one minute per
86 // origin per permission is under a threshold, otherwise true. 94 // origin per permission is under a threshold, otherwise true.
87 bool IsReportThresholdExceeded(content::PermissionType permission, 95 bool IsReportThresholdExceeded(content::PermissionType permission,
88 const GURL& origin); 96 const GURL& origin);
89 97
90 std::unique_ptr<net::ReportSender> permission_report_sender_; 98 std::unique_ptr<net::ReportSender> permission_report_sender_;
91 99
92 // TODO(stefanocs): This might introduce a memory issue since older entries 100 // TODO(stefanocs): This might introduce a memory issue since older entries
93 // are not removed until a new report with the corresponding key is added. We 101 // are not removed until a new report with the corresponding key is added. We
94 // should address this issue if that becomes a problem in the future. 102 // should address this issue if that becomes a problem in the future.
95 std::unordered_map<PermissionAndOrigin, 103 std::unordered_map<PermissionAndOrigin,
96 std::queue<base::Time>, 104 std::queue<base::Time>,
97 PermissionAndOriginHash> 105 PermissionAndOriginHash>
98 report_logs_; 106 report_logs_;
99 107
100 std::unique_ptr<base::Clock> clock_; 108 std::unique_ptr<base::Clock> clock_;
101 109
102 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); 110 DISALLOW_COPY_AND_ASSIGN(PermissionReporter);
103 }; 111 };
104 112
105 } // namespace safe_browsing 113 } // namespace safe_browsing
106 114
107 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ 115 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_uma_util.cc ('k') | chrome/browser/safe_browsing/permission_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698