| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 case PermissionRequestGestureType::NO_GESTURE: | 109 case PermissionRequestGestureType::NO_GESTURE: |
| 110 return PermissionReport::NO_GESTURE; | 110 return PermissionReport::NO_GESTURE; |
| 111 case PermissionRequestGestureType::NUM: | 111 case PermissionRequestGestureType::NUM: |
| 112 break; | 112 break; |
| 113 } | 113 } |
| 114 | 114 |
| 115 NOTREACHED(); | 115 NOTREACHED(); |
| 116 return PermissionReport::GESTURE_TYPE_UNSPECIFIED; | 116 return PermissionReport::GESTURE_TYPE_UNSPECIFIED; |
| 117 } | 117 } |
| 118 | 118 |
| 119 PermissionReport::PersistDecision PersistDecisionForReport( |
| 120 PermissionPersistDecision persist_decision) { |
| 121 switch (persist_decision) { |
| 122 case PermissionPersistDecision::UNSPECIFIED: |
| 123 return PermissionReport::PERSIST_DECISION_UNSPECIFIED; |
| 124 case PermissionPersistDecision::PERSISTED: |
| 125 return PermissionReport::PERSISTED; |
| 126 case PermissionPersistDecision::NOT_PERSISTED: |
| 127 return PermissionReport::NOT_PERSISTED; |
| 128 } |
| 129 |
| 130 NOTREACHED(); |
| 131 return PermissionReport::PERSIST_DECISION_UNSPECIFIED; |
| 132 } |
| 133 |
| 119 } // namespace | 134 } // namespace |
| 120 | 135 |
| 121 bool PermissionAndOrigin::operator==(const PermissionAndOrigin& other) const { | 136 bool PermissionAndOrigin::operator==(const PermissionAndOrigin& other) const { |
| 122 return (permission == other.permission && origin == other.origin); | 137 return (permission == other.permission && origin == other.origin); |
| 123 } | 138 } |
| 124 | 139 |
| 125 std::size_t PermissionAndOriginHash::operator()( | 140 std::size_t PermissionAndOriginHash::operator()( |
| 126 const PermissionAndOrigin& permission_and_origin) const { | 141 const PermissionAndOrigin& permission_and_origin) const { |
| 127 std::size_t permission_hash = | 142 std::size_t permission_hash = |
| 128 static_cast<std::size_t>(permission_and_origin.permission); | 143 static_cast<std::size_t>(permission_and_origin.permission); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 139 base::WrapUnique(new base::DefaultClock)) {} | 154 base::WrapUnique(new base::DefaultClock)) {} |
| 140 | 155 |
| 141 PermissionReporter::PermissionReporter( | 156 PermissionReporter::PermissionReporter( |
| 142 std::unique_ptr<net::ReportSender> report_sender, | 157 std::unique_ptr<net::ReportSender> report_sender, |
| 143 std::unique_ptr<base::Clock> clock) | 158 std::unique_ptr<base::Clock> clock) |
| 144 : permission_report_sender_(std::move(report_sender)), | 159 : permission_report_sender_(std::move(report_sender)), |
| 145 clock_(std::move(clock)) {} | 160 clock_(std::move(clock)) {} |
| 146 | 161 |
| 147 PermissionReporter::~PermissionReporter() {} | 162 PermissionReporter::~PermissionReporter() {} |
| 148 | 163 |
| 149 void PermissionReporter::SendReport(const GURL& origin, | 164 void PermissionReporter::SendReport(const PermissionReportInfo& report_info) { |
| 150 content::PermissionType permission, | 165 if (IsReportThresholdExceeded(report_info.permission, report_info.origin)) |
| 151 PermissionAction action, | |
| 152 PermissionSourceUI source_ui, | |
| 153 PermissionRequestGestureType gesture_type, | |
| 154 int num_prior_dismissals, | |
| 155 int num_prior_ignores) { | |
| 156 if (IsReportThresholdExceeded(permission, origin)) | |
| 157 return; | 166 return; |
| 167 |
| 158 std::string serialized_report; | 168 std::string serialized_report; |
| 159 BuildReport(origin, permission, action, source_ui, gesture_type, | 169 BuildReport(report_info, &serialized_report); |
| 160 num_prior_dismissals, num_prior_ignores, &serialized_report); | |
| 161 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | 170 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
| 162 serialized_report); | 171 serialized_report); |
| 163 } | 172 } |
| 164 | 173 |
| 165 // static | 174 // static |
| 166 bool PermissionReporter::BuildReport(const GURL& origin, | 175 bool PermissionReporter::BuildReport(const PermissionReportInfo& report_info, |
| 167 PermissionType permission, | |
| 168 PermissionAction action, | |
| 169 PermissionSourceUI source_ui, | |
| 170 PermissionRequestGestureType gesture_type, | |
| 171 int num_prior_dismissals, | |
| 172 int num_prior_ignores, | |
| 173 std::string* output) { | 176 std::string* output) { |
| 174 PermissionReport report; | 177 PermissionReport report; |
| 175 report.set_origin(origin.spec()); | 178 report.set_origin(report_info.origin.spec()); |
| 176 report.set_permission(PermissionTypeForReport(permission)); | 179 report.set_permission(PermissionTypeForReport(report_info.permission)); |
| 177 report.set_action(PermissionActionForReport(action)); | 180 report.set_action(PermissionActionForReport(report_info.action)); |
| 178 report.set_source_ui(SourceUIForReport(source_ui)); | 181 report.set_source_ui(SourceUIForReport(report_info.source_ui)); |
| 179 report.set_gesture(GestureTypeForReport(gesture_type)); | 182 report.set_gesture(GestureTypeForReport(report_info.gesture_type)); |
| 180 report.set_num_prior_dismissals(num_prior_dismissals); | 183 report.set_persisted( |
| 181 report.set_num_prior_ignores(num_prior_ignores); | 184 PersistDecisionForReport(report_info.persist_decision)); |
| 185 report.set_num_prior_dismissals(report_info.num_prior_dismissals); |
| 186 report.set_num_prior_ignores(report_info.num_prior_ignores); |
| 182 | 187 |
| 183 // Collect platform data. | 188 // Collect platform data. |
| 184 #if defined(OS_ANDROID) | 189 #if defined(OS_ANDROID) |
| 185 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); | 190 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); |
| 186 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 191 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
| 187 defined(OS_LINUX) | 192 defined(OS_LINUX) |
| 188 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); | 193 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); |
| 189 #else | 194 #else |
| 190 #error Unsupported platform. | 195 #error Unsupported platform. |
| 191 #endif | 196 #endif |
| (...skipping 21 matching lines...) Expand all Loading... |
| 213 } | 218 } |
| 214 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { | 219 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { |
| 215 log.push(current_time); | 220 log.push(current_time); |
| 216 return false; | 221 return false; |
| 217 } else { | 222 } else { |
| 218 return true; | 223 return true; |
| 219 } | 224 } |
| 220 } | 225 } |
| 221 | 226 |
| 222 } // namespace safe_browsing | 227 } // namespace safe_browsing |
| OLD | NEW |