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

Side by Side Diff: chrome/browser/permissions/permission_context_uma_util.cc

Issue 1401073002: Add Rappor reporting for grant/deny/cancel/ignore of Mediastream permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use existing rappor code Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/permissions/permission_context_uma_util.h" 5 #include "chrome/browser/permissions/permission_context_uma_util.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/permissions/permission_manager.h" 10 #include "chrome/browser/permissions/permission_manager.h"
(...skipping 14 matching lines...) Expand all
25 PERMISSION_ACTION_NUM); \ 25 PERMISSION_ACTION_NUM); \
26 } else { \ 26 } else { \
27 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \ 27 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \
28 PERMISSION_ACTION_NUM); \ 28 PERMISSION_ACTION_NUM); \
29 } 29 }
30 30
31 using content::PermissionType; 31 using content::PermissionType;
32 32
33 namespace { 33 namespace {
34 34
35 // Enum for UMA purposes, make sure you update histograms.xml if you add new
36 // permission actions. Never delete or reorder an entry; only add new entries
37 // immediately before PERMISSION_NUM
38 enum PermissionAction {
39 GRANTED = 0,
40 DENIED = 1,
41 DISMISSED = 2,
42 IGNORED = 3,
43 REVOKED = 4,
44 REENABLED = 5,
45 REQUESTED = 6,
46
47 // Always keep this at the end.
48 PERMISSION_ACTION_NUM,
49 };
50
51 // Deprecated. This method is used for the single-dimensional RAPPOR metrics 35 // Deprecated. This method is used for the single-dimensional RAPPOR metrics
52 // that are being replaced by the multi-dimensional ones. 36 // that are being replaced by the multi-dimensional ones.
53 const std::string GetRapporMetric(ContentSettingsType permission, 37 const std::string GetRapporMetric(ContentSettingsType permission,
54 PermissionAction action) { 38 PermissionAction action) {
55 std::string action_str; 39 std::string action_str;
56 switch (action) { 40 switch (action) {
57 case GRANTED: 41 case GRANTED:
58 action_str = "Granted"; 42 action_str = "Granted";
59 break; 43 break;
60 case DENIED: 44 case DENIED:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // There are two sets of semi-redundant RAPPOR metrics being reported: 125 // There are two sets of semi-redundant RAPPOR metrics being reported:
142 // The soon-to-be-deprecated single dimensional ones, and the new 126 // The soon-to-be-deprecated single dimensional ones, and the new
143 // multi-dimensional ones. 127 // multi-dimensional ones.
144 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); 128 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
145 const std::string rappor_metric = GetRapporMetric(permission, action); 129 const std::string rappor_metric = GetRapporMetric(permission, action);
146 if (!rappor_metric.empty()) 130 if (!rappor_metric.empty())
147 rappor::SampleDomainAndRegistryFromGURL( 131 rappor::SampleDomainAndRegistryFromGURL(
148 rappor_service, rappor_metric, requesting_origin); 132 rappor_service, rappor_metric, requesting_origin);
149 133
150 // Add multi-dimensional RAPPOR reporting for safe-browsing users. 134 // Add multi-dimensional RAPPOR reporting for safe-browsing users.
151 std::string permission_str = 135 PermissionContextUmaUtil::RecordMultiDRapporAction(permission,
152 PermissionContextUmaUtil::GetPermissionString(permission); 136 requesting_origin, action);
153 if (!rappor_service || permission_str.empty())
154 return;
155
156 scoped_ptr<rappor::Sample> sample =
157 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE);
158 sample->SetStringField("Scheme", requesting_origin.scheme());
159 sample->SetStringField("Host", requesting_origin.host());
160 sample->SetStringField("Port", requesting_origin.port());
161 sample->SetStringField("Domain",
162 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin));
163 sample->SetFlagsField("Actions",
164 1 << action,
165 PermissionAction::PERMISSION_ACTION_NUM);
166 rappor_service->RecordSampleObj("Permissions.Action." +
167 permission_str, sample.Pass());
168 } 137 }
169 138
170 std::string PermissionTypeToString(PermissionType permission_type) { 139 std::string PermissionTypeToString(PermissionType permission_type) {
171 switch (permission_type) { 140 switch (permission_type) {
172 case PermissionType::MIDI_SYSEX: 141 case PermissionType::MIDI_SYSEX:
173 return "MidiSysex"; 142 return "MidiSysex";
174 case PermissionType::PUSH_MESSAGING: 143 case PermissionType::PUSH_MESSAGING:
175 return "PushMessaging"; 144 return "PushMessaging";
176 case PermissionType::NOTIFICATIONS: 145 case PermissionType::NOTIFICATIONS:
177 return "Notifications"; 146 return "Notifications";
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 #endif 298 #endif
330 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: 299 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
331 return "MediaStreamMic"; 300 return "MediaStreamMic";
332 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: 301 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
333 return "MediaStreamCamera"; 302 return "MediaStreamCamera";
334 default: 303 default:
335 NOTREACHED(); 304 NOTREACHED();
336 return ""; 305 return "";
337 } 306 }
338 } 307 }
308
309 void PermissionContextUmaUtil::RecordMultiDRapporAction(
310 ContentSettingsType permission,
311 const GURL& requesting_origin,
312 PermissionAction action) {
313 rappor::RapporService* rappor_service = g_browser_process->rappor_service();
314 const std::string permission_str = GetPermissionString(permission);
315 if (!rappor_service || permission_str.empty())
316 return;
317
318 scoped_ptr<rappor::Sample> sample =
319 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE);
320 sample->SetStringField("Scheme", requesting_origin.scheme());
321 sample->SetStringField("Host", requesting_origin.host());
322 sample->SetStringField("Port", requesting_origin.port());
323 sample->SetStringField("Domain",
324 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin));
325 sample->SetFlagsField("Actions",
326 1 << action,
327 PermissionAction::PERMISSION_ACTION_NUM);
328 rappor_service->RecordSampleObj("Permissions.Action." +
329 permission_str, sample.Pass());
330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698