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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Creates a permission reporter that will send permission reports to | 43 // Creates a permission reporter that will send permission reports to |
44 // the SafeBrowsing permission action server, using |request_context| as the | 44 // the SafeBrowsing permission action server, using |request_context| as the |
45 // context for the reports. | 45 // context for the reports. |
46 explicit PermissionReporter(net::URLRequestContext* request_context); | 46 explicit PermissionReporter(net::URLRequestContext* request_context); |
47 | 47 |
48 ~PermissionReporter(); | 48 ~PermissionReporter(); |
49 | 49 |
50 // Sends a serialized permission report to the report collection server. | 50 // Sends a serialized permission report to the report collection server. |
51 // The permission report includes |origin| as the origin of | 51 // The permission report includes |origin| as the origin of |
52 // the site requesting permission, |permission| as the type of permission | 52 // the site requesting permission, |permission| as the type of permission |
53 // requested, and |action| as the action taken. The report will be serialized | 53 // requested, |action| as the action taken, and |user_gesture| in the list of |
54 // using protobuf defined in | 54 // request triggers if the action occurred after a user gesture. The report |
| 55 // will be serialized using protobuf defined in |
55 // //src/chrome/common/safe_browsing/permission_report.proto | 56 // //src/chrome/common/safe_browsing/permission_report.proto |
56 void SendReport(const GURL& origin, | 57 void SendReport(const GURL& origin, |
57 content::PermissionType permission, | 58 content::PermissionType permission, |
58 PermissionAction action, | 59 PermissionAction action, |
59 PermissionSourceUI source_ui); | 60 PermissionSourceUI source_ui, |
| 61 bool user_gesture); |
60 | 62 |
61 private: | 63 private: |
62 friend class PermissionReporterTest; | 64 friend class PermissionReporterTest; |
63 | 65 |
64 // Used by tests. This constructor allows tests to have access to the | 66 // Used by tests. This constructor allows tests to have access to the |
65 // ReportSender and use a test Clock. | 67 // ReportSender and use a test Clock. |
66 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, | 68 PermissionReporter(std::unique_ptr<net::ReportSender> report_sender, |
67 std::unique_ptr<base::Clock> clock); | 69 std::unique_ptr<base::Clock> clock); |
68 | 70 |
69 // Builds and serializes a permission report with |origin| as the origin of | 71 // Builds and serializes a permission report with |origin| as the origin of |
70 // the site requesting permission, |permission| as the type of permission | 72 // the site requesting permission, |permission| as the type of permission |
71 // requested, and |action| as the action taken. The serialized report is | 73 // requested, and |action| as the action taken. The serialized report is |
72 // written into |output|. Returns true if the serialization was successful and | 74 // written into |output|. Returns true if the serialization was successful and |
73 // false otherwise. | 75 // false otherwise. |
74 static bool BuildReport(const GURL& origin, | 76 static bool BuildReport(const GURL& origin, |
75 content::PermissionType permission, | 77 content::PermissionType permission, |
76 PermissionAction action, | 78 PermissionAction action, |
77 PermissionSourceUI source_ui, | 79 PermissionSourceUI source_ui, |
| 80 bool user_gesture, |
78 std::string* output); | 81 std::string* output); |
79 | 82 |
80 // Returns false if the number of reports sent in the last one minute per | 83 // Returns false if the number of reports sent in the last one minute per |
81 // origin per permission is under a threshold, otherwise true. | 84 // origin per permission is under a threshold, otherwise true. |
82 bool IsReportThresholdExceeded(content::PermissionType permission, | 85 bool IsReportThresholdExceeded(content::PermissionType permission, |
83 const GURL& origin); | 86 const GURL& origin); |
84 | 87 |
85 std::unique_ptr<net::ReportSender> permission_report_sender_; | 88 std::unique_ptr<net::ReportSender> permission_report_sender_; |
86 | 89 |
87 // TODO(stefanocs): This might introduce a memory issue since older entries | 90 // TODO(stefanocs): This might introduce a memory issue since older entries |
88 // are not removed until a new report with the corresponding key is added. We | 91 // are not removed until a new report with the corresponding key is added. We |
89 // should address this issue if that becomes a problem in the future. | 92 // should address this issue if that becomes a problem in the future. |
90 std::unordered_map<PermissionAndOrigin, | 93 std::unordered_map<PermissionAndOrigin, |
91 std::queue<base::Time>, | 94 std::queue<base::Time>, |
92 PermissionAndOriginHash> | 95 PermissionAndOriginHash> |
93 report_logs_; | 96 report_logs_; |
94 | 97 |
95 std::unique_ptr<base::Clock> clock_; | 98 std::unique_ptr<base::Clock> clock_; |
96 | 99 |
97 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); | 100 DISALLOW_COPY_AND_ASSIGN(PermissionReporter); |
98 }; | 101 }; |
99 | 102 |
100 } // namespace safe_browsing | 103 } // namespace safe_browsing |
101 | 104 |
102 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ | 105 #endif // CHROME_BROWSER_SAFE_BROWSING_PERMISSION_REPORTER_H_ |
OLD | NEW |