| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 DISMISSED = 2, | 41 DISMISSED = 2, |
| 42 IGNORED = 3, | 42 IGNORED = 3, |
| 43 REVOKED = 4, | 43 REVOKED = 4, |
| 44 REENABLED = 5, | 44 REENABLED = 5, |
| 45 REQUESTED = 6, | 45 REQUESTED = 6, |
| 46 | 46 |
| 47 // Always keep this at the end. | 47 // Always keep this at the end. |
| 48 PERMISSION_ACTION_NUM, | 48 PERMISSION_ACTION_NUM, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // The returned strings must match the RAPPOR metrics in rappor.xml, | |
| 52 // e.g. Permissions.Action.Geolocation etc.. | |
| 53 const std::string GetPermissionString(ContentSettingsType permission) { | |
| 54 switch (permission) { | |
| 55 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | |
| 56 return "Geolocation"; | |
| 57 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | |
| 58 return "Notifications"; | |
| 59 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
| 60 return "MidiSysEx"; | |
| 61 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | |
| 62 return "PushMessaging"; | |
| 63 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE: | |
| 64 return "DurableStorage"; | |
| 65 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
| 66 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | |
| 67 return "ProtectedMediaIdentifier"; | |
| 68 #endif | |
| 69 default: | |
| 70 NOTREACHED(); | |
| 71 return ""; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 // Deprecated. This method is used for the single-dimensional RAPPOR metrics | 51 // Deprecated. This method is used for the single-dimensional RAPPOR metrics |
| 76 // that are being replaced by the multi-dimensional ones. | 52 // that are being replaced by the multi-dimensional ones. |
| 77 const std::string GetRapporMetric(ContentSettingsType permission, | 53 const std::string GetRapporMetric(ContentSettingsType permission, |
| 78 PermissionAction action) { | 54 PermissionAction action) { |
| 79 std::string action_str; | 55 std::string action_str; |
| 80 switch (action) { | 56 switch (action) { |
| 81 case GRANTED: | 57 case GRANTED: |
| 82 action_str = "Granted"; | 58 action_str = "Granted"; |
| 83 break; | 59 break; |
| 84 case DENIED: | 60 case DENIED: |
| 85 action_str = "Denied"; | 61 action_str = "Denied"; |
| 86 break; | 62 break; |
| 87 case DISMISSED: | 63 case DISMISSED: |
| 88 action_str = "Dismissed"; | 64 action_str = "Dismissed"; |
| 89 break; | 65 break; |
| 90 case IGNORED: | 66 case IGNORED: |
| 91 action_str = "Ignored"; | 67 action_str = "Ignored"; |
| 92 break; | 68 break; |
| 93 default: | 69 default: |
| 94 NOTREACHED(); | 70 NOTREACHED(); |
| 95 break; | 71 break; |
| 96 } | 72 } |
| 97 | 73 |
| 98 std::string permission_str = GetPermissionString(permission); | 74 std::string permission_str = |
| 75 PermissionContextUmaUtil::GetPermissionString(permission); |
| 99 if (permission_str.empty()) | 76 if (permission_str.empty()) |
| 100 return ""; | 77 return ""; |
| 101 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", | 78 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", |
| 102 permission_str.c_str(), action_str.c_str()); | 79 permission_str.c_str(), action_str.c_str()); |
| 103 } | 80 } |
| 104 | 81 |
| 105 void RecordPermissionAction(ContentSettingsType permission, | 82 void RecordPermissionAction(ContentSettingsType permission, |
| 106 PermissionAction action, | 83 PermissionAction action, |
| 107 const GURL& requesting_origin) { | 84 const GURL& requesting_origin) { |
| 108 bool secure_origin = content::IsOriginSecure(requesting_origin); | 85 bool secure_origin = content::IsOriginSecure(requesting_origin); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // There are two sets of semi-redundant RAPPOR metrics being reported: | 141 // There are two sets of semi-redundant RAPPOR metrics being reported: |
| 165 // The soon-to-be-deprecated single dimensional ones, and the new | 142 // The soon-to-be-deprecated single dimensional ones, and the new |
| 166 // multi-dimensional ones. | 143 // multi-dimensional ones. |
| 167 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); | 144 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); |
| 168 const std::string rappor_metric = GetRapporMetric(permission, action); | 145 const std::string rappor_metric = GetRapporMetric(permission, action); |
| 169 if (!rappor_metric.empty()) | 146 if (!rappor_metric.empty()) |
| 170 rappor::SampleDomainAndRegistryFromGURL( | 147 rappor::SampleDomainAndRegistryFromGURL( |
| 171 rappor_service, rappor_metric, requesting_origin); | 148 rappor_service, rappor_metric, requesting_origin); |
| 172 | 149 |
| 173 // Add multi-dimensional RAPPOR reporting for safe-browsing users. | 150 // Add multi-dimensional RAPPOR reporting for safe-browsing users. |
| 174 std::string permission_str = GetPermissionString(permission); | 151 std::string permission_str = |
| 152 PermissionContextUmaUtil::GetPermissionString(permission); |
| 175 if (!rappor_service || permission_str.empty()) | 153 if (!rappor_service || permission_str.empty()) |
| 176 return; | 154 return; |
| 177 | 155 |
| 178 scoped_ptr<rappor::Sample> sample = | 156 scoped_ptr<rappor::Sample> sample = |
| 179 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE); | 157 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE); |
| 180 sample->SetStringField("Scheme", requesting_origin.scheme()); | 158 sample->SetStringField("Scheme", requesting_origin.scheme()); |
| 181 sample->SetStringField("Host", requesting_origin.host()); | 159 sample->SetStringField("Host", requesting_origin.host()); |
| 182 sample->SetStringField("Port", requesting_origin.port()); | 160 sample->SetStringField("Port", requesting_origin.port()); |
| 183 sample->SetStringField("Domain", | 161 sample->SetStringField("Domain", |
| 184 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 162 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 299 |
| 322 void PermissionContextUmaUtil::PermissionDismissed( | 300 void PermissionContextUmaUtil::PermissionDismissed( |
| 323 ContentSettingsType permission, const GURL& requesting_origin) { | 301 ContentSettingsType permission, const GURL& requesting_origin) { |
| 324 RecordPermissionAction(permission, DISMISSED, requesting_origin); | 302 RecordPermissionAction(permission, DISMISSED, requesting_origin); |
| 325 } | 303 } |
| 326 | 304 |
| 327 void PermissionContextUmaUtil::PermissionIgnored( | 305 void PermissionContextUmaUtil::PermissionIgnored( |
| 328 ContentSettingsType permission, const GURL& requesting_origin) { | 306 ContentSettingsType permission, const GURL& requesting_origin) { |
| 329 RecordPermissionAction(permission, IGNORED, requesting_origin); | 307 RecordPermissionAction(permission, IGNORED, requesting_origin); |
| 330 } | 308 } |
| 309 |
| 310 // The returned strings must match the RAPPOR metrics in rappor.xml, |
| 311 // and any Finch configs for the API kill switch e.g. |
| 312 // Permissions.Action.Geolocation etc.. |
| 313 const std::string PermissionContextUmaUtil::GetPermissionString( |
| 314 ContentSettingsType permission) { |
| 315 switch (permission) { |
| 316 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 317 return "Geolocation"; |
| 318 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 319 return "Notifications"; |
| 320 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 321 return "MidiSysEx"; |
| 322 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 323 return "PushMessaging"; |
| 324 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE: |
| 325 return "DurableStorage"; |
| 326 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 327 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 328 return "ProtectedMediaIdentifier"; |
| 329 #endif |
| 330 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 331 return "MediaStreamMic"; |
| 332 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 333 return "MediaStreamCamera"; |
| 334 default: |
| 335 NOTREACHED(); |
| 336 return ""; |
| 337 } |
| 338 } |
| OLD | NEW |