| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 std::unique_ptr<base::Clock> clock) | 143 std::unique_ptr<base::Clock> clock) |
| 144 : permission_report_sender_(std::move(report_sender)), | 144 : permission_report_sender_(std::move(report_sender)), |
| 145 clock_(std::move(clock)) {} | 145 clock_(std::move(clock)) {} |
| 146 | 146 |
| 147 PermissionReporter::~PermissionReporter() {} | 147 PermissionReporter::~PermissionReporter() {} |
| 148 | 148 |
| 149 void PermissionReporter::SendReport(const GURL& origin, | 149 void PermissionReporter::SendReport(const GURL& origin, |
| 150 content::PermissionType permission, | 150 content::PermissionType permission, |
| 151 PermissionAction action, | 151 PermissionAction action, |
| 152 PermissionSourceUI source_ui, | 152 PermissionSourceUI source_ui, |
| 153 PermissionRequestGestureType gesture_type) { | 153 PermissionRequestGestureType gesture_type, |
| 154 int num_prior_dismissals, |
| 155 int num_prior_ignores) { |
| 154 if (IsReportThresholdExceeded(permission, origin)) | 156 if (IsReportThresholdExceeded(permission, origin)) |
| 155 return; | 157 return; |
| 156 std::string serialized_report; | 158 std::string serialized_report; |
| 157 BuildReport(origin, permission, action, source_ui, gesture_type, | 159 BuildReport(origin, permission, action, source_ui, gesture_type, |
| 158 &serialized_report); | 160 num_prior_dismissals, num_prior_ignores, &serialized_report); |
| 159 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | 161 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
| 160 serialized_report); | 162 serialized_report); |
| 161 } | 163 } |
| 162 | 164 |
| 163 // static | 165 // static |
| 164 bool PermissionReporter::BuildReport(const GURL& origin, | 166 bool PermissionReporter::BuildReport(const GURL& origin, |
| 165 PermissionType permission, | 167 PermissionType permission, |
| 166 PermissionAction action, | 168 PermissionAction action, |
| 167 PermissionSourceUI source_ui, | 169 PermissionSourceUI source_ui, |
| 168 PermissionRequestGestureType gesture_type, | 170 PermissionRequestGestureType gesture_type, |
| 171 int num_prior_dismissals, |
| 172 int num_prior_ignores, |
| 169 std::string* output) { | 173 std::string* output) { |
| 170 PermissionReport report; | 174 PermissionReport report; |
| 171 report.set_origin(origin.spec()); | 175 report.set_origin(origin.spec()); |
| 172 report.set_permission(PermissionTypeForReport(permission)); | 176 report.set_permission(PermissionTypeForReport(permission)); |
| 173 report.set_action(PermissionActionForReport(action)); | 177 report.set_action(PermissionActionForReport(action)); |
| 174 report.set_source_ui(SourceUIForReport(source_ui)); | 178 report.set_source_ui(SourceUIForReport(source_ui)); |
| 175 report.set_gesture(GestureTypeForReport(gesture_type)); | 179 report.set_gesture(GestureTypeForReport(gesture_type)); |
| 180 report.set_num_prior_dismissals(num_prior_dismissals); |
| 181 report.set_num_prior_ignores(num_prior_ignores); |
| 176 | 182 |
| 177 // Collect platform data. | 183 // Collect platform data. |
| 178 #if defined(OS_ANDROID) | 184 #if defined(OS_ANDROID) |
| 179 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); | 185 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); |
| 180 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 186 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
| 181 defined(OS_LINUX) | 187 defined(OS_LINUX) |
| 182 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); | 188 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); |
| 183 #else | 189 #else |
| 184 #error Unsupported platform. | 190 #error Unsupported platform. |
| 185 #endif | 191 #endif |
| (...skipping 21 matching lines...) Expand all Loading... |
| 207 } | 213 } |
| 208 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { | 214 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { |
| 209 log.push(current_time); | 215 log.push(current_time); |
| 210 return false; | 216 return false; |
| 211 } else { | 217 } else { |
| 212 return true; | 218 return true; |
| 213 } | 219 } |
| 214 } | 220 } |
| 215 | 221 |
| 216 } // namespace safe_browsing | 222 } // namespace safe_browsing |
| OLD | NEW |