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

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: merge Created 4 years, 5 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 6
7 #include <functional> 7 #include <functional>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 case REQUESTED: 73 case REQUESTED:
74 return PermissionReport::ACTION_UNSPECIFIED; 74 return PermissionReport::ACTION_UNSPECIFIED;
75 case PERMISSION_ACTION_NUM: 75 case PERMISSION_ACTION_NUM:
76 break; 76 break;
77 } 77 }
78 78
79 NOTREACHED(); 79 NOTREACHED();
80 return PermissionReport::ACTION_UNSPECIFIED; 80 return PermissionReport::ACTION_UNSPECIFIED;
81 } 81 }
82 82
83 PermissionReport::SourceUI SourceUIForReport(PermissionSourceUI source_ui) {
84 switch (source_ui) {
85 case PermissionSourceUI::PROMPT:
86 return PermissionReport::PROMPT;
87 case PermissionSourceUI::OIB:
88 return PermissionReport::OIB;
89 case PermissionSourceUI::SITE_SETTINGS:
90 return PermissionReport::SITE_SETTINGS;
91 case PermissionSourceUI::PAGE_ACTION:
92 return PermissionReport::PAGE_ACTION;
93 case PermissionSourceUI::SOURCE_UI_NUM:
94 break;
95 }
96
97 NOTREACHED();
98 return PermissionReport::SOURCE_UI_UNSPECIFIED;
99 }
100
83 } // namespace 101 } // namespace
84 102
85 bool PermissionAndOrigin::operator==(const PermissionAndOrigin& other) const { 103 bool PermissionAndOrigin::operator==(const PermissionAndOrigin& other) const {
86 return (permission == other.permission && origin == other.origin); 104 return (permission == other.permission && origin == other.origin);
87 } 105 }
88 106
89 std::size_t PermissionAndOriginHash::operator()( 107 std::size_t PermissionAndOriginHash::operator()(
90 const PermissionAndOrigin& permission_and_origin) const { 108 const PermissionAndOrigin& permission_and_origin) const {
91 std::size_t permission_hash = 109 std::size_t permission_hash =
92 static_cast<std::size_t>(permission_and_origin.permission); 110 static_cast<std::size_t>(permission_and_origin.permission);
(...skipping 12 matching lines...) Expand all
105 PermissionReporter::PermissionReporter( 123 PermissionReporter::PermissionReporter(
106 std::unique_ptr<net::ReportSender> report_sender, 124 std::unique_ptr<net::ReportSender> report_sender,
107 std::unique_ptr<base::Clock> clock) 125 std::unique_ptr<base::Clock> clock)
108 : permission_report_sender_(std::move(report_sender)), 126 : permission_report_sender_(std::move(report_sender)),
109 clock_(std::move(clock)) {} 127 clock_(std::move(clock)) {}
110 128
111 PermissionReporter::~PermissionReporter() {} 129 PermissionReporter::~PermissionReporter() {}
112 130
113 void PermissionReporter::SendReport(const GURL& origin, 131 void PermissionReporter::SendReport(const GURL& origin,
114 content::PermissionType permission, 132 content::PermissionType permission,
115 PermissionAction action) { 133 PermissionAction action,
134 PermissionSourceUI source_ui) {
116 if (IsReportThresholdExceeded(permission, origin)) 135 if (IsReportThresholdExceeded(permission, origin))
117 return; 136 return;
118 std::string serialized_report; 137 std::string serialized_report;
119 BuildReport(origin, permission, action, &serialized_report); 138 BuildReport(origin, permission, action, source_ui, &serialized_report);
120 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), 139 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl),
121 serialized_report); 140 serialized_report);
122 } 141 }
123 142
124 // static 143 // static
125 bool PermissionReporter::BuildReport(const GURL& origin, 144 bool PermissionReporter::BuildReport(const GURL& origin,
126 PermissionType permission, 145 PermissionType permission,
127 PermissionAction action, 146 PermissionAction action,
147 PermissionSourceUI source_ui,
128 std::string* output) { 148 std::string* output) {
129 PermissionReport report; 149 PermissionReport report;
130 report.set_origin(origin.spec()); 150 report.set_origin(origin.spec());
131 report.set_permission(PermissionTypeForReport(permission)); 151 report.set_permission(PermissionTypeForReport(permission));
132 report.set_action(PermissionActionForReport(action)); 152 report.set_action(PermissionActionForReport(action));
153 report.set_source_ui(SourceUIForReport(source_ui));
133 154
134 // Collect platform data. 155 // Collect platform data.
135 #if defined(OS_ANDROID) 156 #if defined(OS_ANDROID)
136 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); 157 report.set_platform_type(PermissionReport::ANDROID_PLATFORM);
137 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ 158 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \
138 defined(OS_LINUX) 159 defined(OS_LINUX)
139 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); 160 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM);
140 #else 161 #else
141 #error Unsupported platform. 162 #error Unsupported platform.
142 #endif 163 #endif
(...skipping 21 matching lines...) Expand all
164 } 185 }
165 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) { 186 if (log.size() < kMaximumReportsPerOriginPerPermissionPerMinute) {
166 log.push(current_time); 187 log.push(current_time);
167 return false; 188 return false;
168 } else { 189 } else {
169 return true; 190 return true;
170 } 191 }
171 } 192 }
172 193
173 } // namespace safe_browsing 194 } // namespace safe_browsing
OLDNEW
« 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