Chromium Code Reviews| Index: chrome/browser/safe_browsing/permission_reporter.cc |
| diff --git a/chrome/browser/safe_browsing/permission_reporter.cc b/chrome/browser/safe_browsing/permission_reporter.cc |
| index 98de876f1db1313ea69a72b0d95a306ec5ad57ee..fe53315981590170a796e2169aa06569aad57e90 100644 |
| --- a/chrome/browser/safe_browsing/permission_reporter.cc |
| +++ b/chrome/browser/safe_browsing/permission_reporter.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/safe_browsing/permission_reporter.h" |
| #include "chrome/common/safe_browsing/permission_report.pb.h" |
| #include "content/public/browser/permission_type.h" |
| +#include "net/url_request/report_sender.h" |
| using content::PermissionType; |
| @@ -15,18 +16,86 @@ namespace { |
| const char kPermissionActionReportingUploadUrl[] = |
| "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| "permission-action"; |
| + |
| +PermissionReport::PermissionType PermissionTypeToPermissionReportEnum( |
| + PermissionType permission) { |
| + switch (permission) { |
| + case PermissionType::MIDI_SYSEX: |
| + return PermissionReport::MIDI_SYSEX; |
| + case PermissionType::PUSH_MESSAGING: |
| + return PermissionReport::PUSH_MESSAGING; |
| + case PermissionType::NOTIFICATIONS: |
| + return PermissionReport::NOTIFICATIONS; |
| + case PermissionType::GEOLOCATION: |
| + return PermissionReport::GEOLOCATION; |
| + case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| + return PermissionReport::PROTECTED_MEDIA_IDENTIFIER; |
| + case PermissionType::MIDI: |
| + return PermissionReport::MIDI; |
| + case PermissionType::DURABLE_STORAGE: |
| + return PermissionReport::DURABLE_STORAGE; |
| + case PermissionType::AUDIO_CAPTURE: |
| + return PermissionReport::AUDIO_CAPTURE; |
| + case PermissionType::VIDEO_CAPTURE: |
| + return PermissionReport::VIDEO_CAPTURE; |
| + case PermissionType::BACKGROUND_SYNC: |
| + return PermissionReport::UNKNOWN_PERMISSION; |
| + case PermissionType::NUM: |
| + break; |
| + } |
| + |
| + NOTREACHED(); |
| + return PermissionReport::UNKNOWN_PERMISSION; |
| +} |
| + |
| +PermissionReport::Action PermissionActionToPermissionReportEnum( |
| + PermissionAction action) { |
| + switch (action) { |
| + case GRANTED: |
| + return PermissionReport::GRANTED; |
| + case DENIED: |
| + return PermissionReport::DENIED; |
| + case DISMISSED: |
| + return PermissionReport::DISMISSED; |
| + case IGNORED: |
| + return PermissionReport::IGNORED; |
| + case REVOKED: |
| + return PermissionReport::REVOKED; |
| + case REENABLED: |
| + case REQUESTED: |
| + return PermissionReport::ACTION_UNSPECIFIED; |
| + case PERMISSION_ACTION_NUM: |
| + break; |
| + } |
| + |
| + NOTREACHED(); |
| + return PermissionReport::ACTION_UNSPECIFIED; |
| +} |
| + |
| } // namespace |
| +PermissionReporter::PermissionReporter(net::URLRequestContext* request_context) |
| + : permission_report_sender_(new net::ReportSender( |
| + request_context, |
| + net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) { |
| + DCHECK(permission_report_sender_); |
|
raymes
2016/06/09 01:30:40
nit: this isn't needed (because it's clear from co
stefanocs
2016/06/09 05:56:11
Done.
|
| +} |
| + |
| PermissionReporter::PermissionReporter( |
| - net::URLRequestContext* request_context) {} |
| + std::unique_ptr<net::ReportSender> report_sender) |
| + : permission_report_sender_(std::move(report_sender)) { |
| + DCHECK(permission_report_sender_); |
|
raymes
2016/06/09 01:30:40
nit: I'd also say this isn't really needed. It's o
stefanocs
2016/06/09 05:56:11
Done.
|
| +} |
| PermissionReporter::~PermissionReporter() {} |
| void PermissionReporter::SendReport(const GURL& origin, |
| content::PermissionType permission, |
| PermissionAction action) { |
| - // TODO(stefanocs): Implement SendReport function. |
| - ALLOW_UNUSED_LOCAL(kPermissionActionReportingUploadUrl); |
| + std::string serialized_report; |
| + BuildReport(origin, permission, action, &serialized_report); |
| + permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
| + serialized_report); |
| } |
| // static |
| @@ -34,8 +103,12 @@ bool PermissionReporter::BuildReport(const GURL& origin, |
| PermissionType permission, |
| PermissionAction action, |
| std::string* output) { |
| - // TODO(stefanocs): Implement BuildReport function. |
| - return true; |
| + PermissionReport report; |
| + report.set_origin(origin.spec()); |
| + report.set_permission(PermissionTypeToPermissionReportEnum(permission)); |
| + report.set_action(PermissionActionToPermissionReportEnum(action)); |
| + // TODO(stefanocs): Collect other data for the report from global variables |
|
raymes
2016/06/09 01:30:40
nit: "." at end
stefanocs
2016/06/09 05:56:11
Done.
|
| + return report.SerializeToString(output); |
| } |
| } // namespace safe_browsing |