OLD | NEW |
---|---|
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 Loading... | |
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 |
58 void SendReport(const GURL& origin, | 60 void SendReport(const GURL& origin, |
59 content::PermissionType permission, | 61 content::PermissionType permission, |
60 PermissionAction action, | 62 PermissionAction action, |
61 PermissionSourceUI source_ui, | 63 PermissionSourceUI source_ui, |
62 PermissionRequestGestureType gesture_type); | 64 PermissionRequestGestureType gesture_type, |
65 int num_prior_dismissals, | |
Nathan Parker
2016/08/17 20:06:01
This is getting pretty long, and consecutive same-
kcarattini
2016/08/17 22:37:26
Acknowledged. Added a TODO to address this in a fo
| |
66 int num_prior_ignores); | |
63 | 67 |
64 private: | 68 private: |
65 friend class PermissionReporterBrowserTest; | 69 friend class PermissionReporterBrowserTest; |
66 friend class PermissionReporterTest; | 70 friend class PermissionReporterTest; |
67 | 71 |
68 // Used by tests. This constructor allows tests to have access to the | 72 // Used by tests. This constructor allows tests to have access to the |
69 // ReportSender and use a test Clock. | 73 // ReportSender and use a test Clock. |
70 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, | 74 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, |
71 std::unique_ptr<base::Clock> clock); | 75 std::unique_ptr<base::Clock> clock); |
72 | 76 |
73 // Builds and serializes a permission report with |origin| as the origin of | 77 // Builds and serializes a permission report with |origin| as the origin of |
74 // the site requesting permission, |permission| as the type of permission | 78 // the site requesting permission, |permission| as the type of permission |
75 // requested, and |action| as the action taken. The serialized report is | 79 // requested, and |action| as the action taken. The serialized report is |
76 // written into |output|. Returns true if the serialization was successful and | 80 // written into |output|. Returns true if the serialization was successful and |
77 // false otherwise. | 81 // false otherwise. |
78 static bool BuildReport(const GURL& origin, | 82 static bool BuildReport(const GURL& origin, |
79 content::PermissionType permission, | 83 content::PermissionType permission, |
80 PermissionAction action, | 84 PermissionAction action, |
81 PermissionSourceUI source_ui, | 85 PermissionSourceUI source_ui, |
82 PermissionRequestGestureType gesture_type, | 86 PermissionRequestGestureType gesture_type, |
87 int num_prior_dismissals, | |
88 int num_prior_ignores, | |
83 std::string* output); | 89 std::string* output); |
84 | 90 |
85 // Returns false if the number of reports sent in the last one minute per | 91 // Returns false if the number of reports sent in the last one minute per |
86 // origin per permission is under a threshold, otherwise true. | 92 // origin per permission is under a threshold, otherwise true. |
87 bool IsReportThresholdExceeded(content::PermissionType permission, | 93 bool IsReportThresholdExceeded(content::PermissionType permission, |
88 const GURL& origin); | 94 const GURL& origin); |
89 | 95 |
90 std::unique_ptr<net::ReportSender> permission_report_sender_; | 96 std::unique_ptr<net::ReportSender> permission_report_sender_; |
91 | 97 |
92 // TODO(stefanocs): This might introduce a memory issue since older entries | 98 // 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 | 99 // 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. | 100 // should address this issue if that becomes a problem in the future. |
95 std::unordered_map<PermissionAndOrigin, | 101 std::unordered_map<PermissionAndOrigin, |
96 std::queue<base::Time>, | 102 std::queue<base::Time>, |
97 PermissionAndOriginHash> | 103 PermissionAndOriginHash> |
98 report_logs_; | 104 report_logs_; |
99 | 105 |
100 std::unique_ptr<base::Clock> clock_; | 106 std::unique_ptr<base::Clock> clock_; |
101 | 107 |
102 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); | 108 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
103 }; | 109 }; |
104 | 110 |
105 } // namespace safe_browsing | 111 } // namespace safe_browsing |
106 | 112 |
107 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 113 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
OLD | NEW |