Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: chrome/browser/safe_browsing/permission_reporter.cc

Issue 2035753004: Add implementation of PermissionReporter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-certificate-report-sender
Patch Set: Remove static marker in anon namespace Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b64f60ceff6ea32b265873919d5740b8253b4819 100644
--- a/chrome/browser/safe_browsing/permission_reporter.cc
+++ b/chrome/browser/safe_browsing/permission_reporter.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/ptr_util.h"
#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 +17,81 @@ namespace {
const char kPermissionActionReportingUploadUrl[] =
"http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
"permission-action";
+
+PermissionReport::PermissionType PermissionTypeForReport(
+ 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 PermissionActionForReport(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)
+ : PermissionReporter(base::WrapUnique(new net::ReportSender(
+ 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,13 @@ 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(PermissionTypeForReport(permission));
+ report.set_action(PermissionActionForReport(action));
+ // TODO(stefanocs): Collect field trials and platform type from global
+ // variables to the permission report.
+ return report.SerializeToString(output);
}
} // namespace safe_browsing
« no previous file with comments | « chrome/browser/safe_browsing/permission_reporter.h ('k') | chrome/browser/safe_browsing/permission_reporter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698