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

Side by Side 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: Fix small mistakes 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 unified diff | Download patch
OLDNEW
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 #include "chrome/common/safe_browsing/permission_report.pb.h" 6 #include "chrome/common/safe_browsing/permission_report.pb.h"
7 #include "content/public/browser/permission_type.h" 7 #include "content/public/browser/permission_type.h"
8 #include "net/url_request/report_sender.h"
8 9
9 using content::PermissionType; 10 using content::PermissionType;
10 11
11 namespace safe_browsing { 12 namespace safe_browsing {
12 13
13 namespace { 14 namespace {
14 // URL to upload permission action reports. 15 // URL to upload permission action reports.
15 const char kPermissionActionReportingUploadUrl[] = 16 const char kPermissionActionReportingUploadUrl[] =
16 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" 17 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
17 "permission-action"; 18 "permission-action";
19
20 PermissionReport::PermissionType PermissionTypeToPermissionReportEnum(
21 PermissionType permission) {
22 switch (permission) {
23 case PermissionType::MIDI_SYSEX:
24 return PermissionReport::MIDI_SYSEX;
25 case PermissionType::PUSH_MESSAGING:
26 return PermissionReport::PUSH_MESSAGING;
27 case PermissionType::NOTIFICATIONS:
28 return PermissionReport::NOTIFICATIONS;
29 case PermissionType::GEOLOCATION:
30 return PermissionReport::GEOLOCATION;
31 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
32 return PermissionReport::PROTECTED_MEDIA_IDENTIFIER;
33 case PermissionType::MIDI:
34 return PermissionReport::MIDI;
35 case PermissionType::DURABLE_STORAGE:
36 return PermissionReport::DURABLE_STORAGE;
37 case PermissionType::AUDIO_CAPTURE:
38 return PermissionReport::AUDIO_CAPTURE;
39 case PermissionType::VIDEO_CAPTURE:
40 return PermissionReport::VIDEO_CAPTURE;
41 case PermissionType::BACKGROUND_SYNC:
42 return PermissionReport::UNKNOWN_PERMISSION;
43 case PermissionType::NUM:
44 break;
45 }
46
47 NOTREACHED();
48 return PermissionReport::UNKNOWN_PERMISSION;
49 }
50
51 PermissionReport::Action PermissionActionToPermissionReportEnum(
52 PermissionAction action) {
53 switch (action) {
54 case GRANTED:
55 return PermissionReport::GRANTED;
56 case DENIED:
57 return PermissionReport::DENIED;
58 case DISMISSED:
59 return PermissionReport::DISMISSED;
60 case IGNORED:
61 return PermissionReport::IGNORED;
62 case REVOKED:
63 return PermissionReport::REVOKED;
64 case REENABLED:
65 case REQUESTED:
66 return PermissionReport::ACTION_UNSPECIFIED;
67 case PERMISSION_ACTION_NUM:
68 break;
69 }
70
71 NOTREACHED();
72 return PermissionReport::ACTION_UNSPECIFIED;
73 }
74
18 } // namespace 75 } // namespace
19 76
77 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context)
78 : permission_report_sender_(new net::ReportSender(
79 request_context,
80 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {
81 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.
82 }
83
20 PermissionReporter::PermissionReporter( 84 PermissionReporter::PermissionReporter(
21 net::URLRequestContext* request_context) {} 85 std::unique_ptr<net::ReportSender> report_sender)
86 : permission_report_sender_(std::move(report_sender)) {
87 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.
88 }
22 89
23 PermissionReporter::~PermissionReporter() {} 90 PermissionReporter::~PermissionReporter() {}
24 91
25 void PermissionReporter::SendReport(const GURL& origin, 92 void PermissionReporter::SendReport(const GURL& origin,
26 content::PermissionType permission, 93 content::PermissionType permission,
27 PermissionAction action) { 94 PermissionAction action) {
28 // TODO(stefanocs): Implement SendReport function. 95 std::string serialized_report;
29 ALLOW_UNUSED_LOCAL(kPermissionActionReportingUploadUrl); 96 BuildReport(origin, permission, action, &serialized_report);
97 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl),
98 serialized_report);
30 } 99 }
31 100
32 // static 101 // static
33 bool PermissionReporter::BuildReport(const GURL& origin, 102 bool PermissionReporter::BuildReport(const GURL& origin,
34 PermissionType permission, 103 PermissionType permission,
35 PermissionAction action, 104 PermissionAction action,
36 std::string* output) { 105 std::string* output) {
37 // TODO(stefanocs): Implement BuildReport function. 106 PermissionReport report;
38 return true; 107 report.set_origin(origin.spec());
108 report.set_permission(PermissionTypeToPermissionReportEnum(permission));
109 report.set_action(PermissionActionToPermissionReportEnum(action));
110 // 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.
111 return report.SerializeToString(output);
39 } 112 }
40 113
41 } // namespace safe_browsing 114 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698