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..d0364bcda25efd32910ce1bd1c9ab355edb9ced8 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,82 @@ namespace { |
| const char kPermissionActionReportingUploadUrl[] = |
| "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| "permission-action"; |
| + |
| +PermissionReport::PermissionType PermissionTypeToPermissionReportPermission( |
|
Nathan Parker
2016/06/20 16:10:09
wholey smokes that's a lot of Permissions. Could t
stefanocs
2016/06/21 03:26:53
Done.
|
| + 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 PermissionActionToPermissionReportAction( |
| + 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( |
|
Nathan Parker
2016/06/20 16:10:09
nit: This could call the constructor below. That
stefanocs
2016/06/21 03:26:53
Done.
|
| + request_context, |
| + net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {} |
| + |
| PermissionReporter::PermissionReporter( |
| - net::URLRequestContext* request_context) {} |
| + std::unique_ptr<net::ReportSender> report_sender) |
| + : permission_report_sender_(std::move(report_sender)) {} |
| 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 +99,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(PermissionTypeToPermissionReportPermission(permission)); |
| + report.set_action(PermissionActionToPermissionReportAction(action)); |
| + // TODO(stefanocs): Collect other data for the report from global variables. |
|
Nathan Parker
2016/06/20 16:10:09
What other data do you need? You could list them
stefanocs
2016/06/21 03:26:53
Done.
|
| + return report.SerializeToString(output); |
| } |
| } // namespace safe_browsing |