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 #include "chrome/browser/safe_browsing/permission_reporter.h" | 5 #include "chrome/browser/safe_browsing/permission_reporter.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 | 8 |
9 #include "base/hash.h" | 9 #include "base/hash.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 std::unique_ptr<net::ReportSender> report_sender, | 124 std::unique_ptr<net::ReportSender> report_sender, |
125 std::unique_ptr<base::Clock> clock) | 125 std::unique_ptr<base::Clock> clock) |
126 : permission_report_sender_(std::move(report_sender)), | 126 : permission_report_sender_(std::move(report_sender)), |
127 clock_(std::move(clock)) {} | 127 clock_(std::move(clock)) {} |
128 | 128 |
129 PermissionReporter::~PermissionReporter() {} | 129 PermissionReporter::~PermissionReporter() {} |
130 | 130 |
131 void PermissionReporter::SendReport(const GURL& origin, | 131 void PermissionReporter::SendReport(const GURL& origin, |
132 content::PermissionType permission, | 132 content::PermissionType permission, |
133 PermissionAction action, | 133 PermissionAction action, |
134 PermissionSourceUI source_ui) { | 134 PermissionSourceUI source_ui, |
| 135 bool user_gesture) { |
135 if (IsReportThresholdExceeded(permission, origin)) | 136 if (IsReportThresholdExceeded(permission, origin)) |
136 return; | 137 return; |
137 std::string serialized_report; | 138 std::string serialized_report; |
138 BuildReport(origin, permission, action, source_ui, &serialized_report); | 139 BuildReport(origin, permission, action, source_ui, user_gesture, |
| 140 &serialized_report); |
139 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | 141 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
140 serialized_report); | 142 serialized_report); |
141 } | 143 } |
142 | 144 |
143 // static | 145 // static |
144 bool PermissionReporter::BuildReport(const GURL& origin, | 146 bool PermissionReporter::BuildReport(const GURL& origin, |
145 PermissionType permission, | 147 PermissionType permission, |
146 PermissionAction action, | 148 PermissionAction action, |
147 PermissionSourceUI source_ui, | 149 PermissionSourceUI source_ui, |
| 150 bool user_gesture, |
148 std::string* output) { | 151 std::string* output) { |
149 PermissionReport report; | 152 PermissionReport report; |
150 report.set_origin(origin.spec()); | 153 report.set_origin(origin.spec()); |
151 report.set_permission(PermissionTypeForReport(permission)); | 154 report.set_permission(PermissionTypeForReport(permission)); |
152 report.set_action(PermissionActionForReport(action)); | 155 report.set_action(PermissionActionForReport(action)); |
153 report.set_source_ui(SourceUIForReport(source_ui)); | 156 report.set_source_ui(SourceUIForReport(source_ui)); |
| 157 if (user_gesture) |
| 158 report.add_request_trigger(PermissionReport::AFTER_GESTURE); |
154 | 159 |
155 // Collect platform data. | 160 // Collect platform data. |
156 #if defined(OS_ANDROID) | 161 #if defined(OS_ANDROID) |
157 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); | 162 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); |
158 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 163 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
159 defined(OS_LINUX) | 164 defined(OS_LINUX) |
160 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); | 165 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); |
161 #else | 166 #else |
162 #error Unsupported platform. | 167 #error Unsupported platform. |
163 #endif | 168 #endif |
(...skipping 21 matching lines...) Expand all Loading... |
185 } | 190 } |
186 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { | 191 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { |
187 log.push(current_time); | 192 log.push(current_time); |
188 return false; | 193 return false; |
189 } else { | 194 } else { |
190 return true; | 195 return true; |
191 } | 196 } |
192 } | 197 } |
193 | 198 |
194 } // namespace safe_browsing | 199 } // namespace safe_browsing |
OLD | NEW |