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

Side by Side Diff: chrome/browser/safe_browsing/permission_reporter.cc

Issue 2075523002: Add SourceUI field to permission report (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 #include "net/url_request/report_sender.h"
9 9
10 using content::PermissionType; 10 using content::PermissionType;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 case REQUESTED: 65 case REQUESTED:
66 return PermissionReport::ACTION_UNSPECIFIED; 66 return PermissionReport::ACTION_UNSPECIFIED;
67 case PERMISSION_ACTION_NUM: 67 case PERMISSION_ACTION_NUM:
68 break; 68 break;
69 } 69 }
70 70
71 NOTREACHED(); 71 NOTREACHED();
72 return PermissionReport::ACTION_UNSPECIFIED; 72 return PermissionReport::ACTION_UNSPECIFIED;
73 } 73 }
74 74
75 PermissionReport::SourceUI SourceUIToPermissionReportSourceUI(
76 SourceUI source_ui) {
77 switch (source_ui) {
78 case PROMPT:
79 return PermissionReport::PROMPT;
80 case OIB:
81 return PermissionReport::OIB;
82 case SITE_SETTINGS:
83 return PermissionReport::SITE_SETTINGS;
84 case PAGE_ACTION:
85 return PermissionReport::PAGE_ACTION;
86 case SOURCE_UI_NUM:
87 break;
88 }
89
90 NOTREACHED();
91 return PermissionReport::SOURCE_UI_UNSPECIFIED;
92 }
93
75 } // namespace 94 } // namespace
76 95
77 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context) 96 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context)
78 : permission_report_sender_(new net::ReportSender( 97 : permission_report_sender_(new net::ReportSender(
79 request_context, 98 request_context,
80 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {} 99 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {}
81 100
82 PermissionReporter::PermissionReporter( 101 PermissionReporter::PermissionReporter(
83 std::unique_ptr<net::ReportSender> report_sender) 102 std::unique_ptr<net::ReportSender> report_sender)
84 : permission_report_sender_(std::move(report_sender)) {} 103 : permission_report_sender_(std::move(report_sender)) {}
85 104
86 PermissionReporter::~PermissionReporter() {} 105 PermissionReporter::~PermissionReporter() {}
87 106
88 void PermissionReporter::SendReport(const GURL& origin, 107 void PermissionReporter::SendReport(const GURL& origin,
89 content::PermissionType permission, 108 content::PermissionType permission,
90 PermissionAction action) { 109 PermissionAction action,
110 SourceUI source_ui) {
91 std::string serialized_report; 111 std::string serialized_report;
92 BuildReport(origin, permission, action, &serialized_report); 112 BuildReport(origin, permission, action, source_ui, &serialized_report);
93 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), 113 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl),
94 serialized_report); 114 serialized_report);
95 } 115 }
96 116
97 // static 117 // static
98 bool PermissionReporter::BuildReport(const GURL& origin, 118 bool PermissionReporter::BuildReport(const GURL& origin,
99 PermissionType permission, 119 PermissionType permission,
100 PermissionAction action, 120 PermissionAction action,
121 SourceUI source_ui,
101 std::string* output) { 122 std::string* output) {
102 PermissionReport report; 123 PermissionReport report;
103 report.set_origin(origin.spec()); 124 report.set_origin(origin.spec());
104 report.set_permission(PermissionTypeToPermissionReportPermission(permission)); 125 report.set_permission(PermissionTypeToPermissionReportPermission(permission));
105 report.set_action(PermissionActionToPermissionReportAction(action)); 126 report.set_action(PermissionActionToPermissionReportAction(action));
127 report.set_source_ui(SourceUIToPermissionReportSourceUI(source_ui));
106 // TODO(stefanocs): Collect other data for the report from global variables. 128 // TODO(stefanocs): Collect other data for the report from global variables.
107 return report.SerializeToString(output); 129 return report.SerializeToString(output);
108 } 130 }
109 131
110 } // namespace safe_browsing 132 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698