| 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" |
| 11 #include "chrome/browser/permissions/permission_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "components/rappor/rappor_service.h" | 13 #include "components/rappor/rappor_service.h" |
| 13 #include "components/rappor/rappor_utils.h" | 14 #include "components/rappor/rappor_utils.h" |
| 14 #include "content/public/browser/permission_type.h" | 15 #include "content/public/browser/permission_type.h" |
| 15 #include "content/public/common/origin_util.h" | 16 #include "content/public/common/origin_util.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 // UMA keys need to be statically initialized so plain function would not | 19 // UMA keys need to be statically initialized so plain function would not |
| 19 // work. Use a Macro instead. | 20 // work. Use a Macro instead. |
| 20 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ | 21 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 41 DISMISSED = 2, | 42 DISMISSED = 2, |
| 42 IGNORED = 3, | 43 IGNORED = 3, |
| 43 REVOKED = 4, | 44 REVOKED = 4, |
| 44 REENABLED = 5, | 45 REENABLED = 5, |
| 45 REQUESTED = 6, | 46 REQUESTED = 6, |
| 46 | 47 |
| 47 // Always keep this at the end. | 48 // Always keep this at the end. |
| 48 PERMISSION_ACTION_NUM, | 49 PERMISSION_ACTION_NUM, |
| 49 }; | 50 }; |
| 50 | 51 |
| 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 | 52 // Deprecated. This method is used for the single-dimensional RAPPOR metrics |
| 76 // that are being replaced by the multi-dimensional ones. | 53 // that are being replaced by the multi-dimensional ones. |
| 77 const std::string GetRapporMetric(ContentSettingsType permission, | 54 const std::string GetRapporMetric(ContentSettingsType permission, |
| 78 PermissionAction action) { | 55 PermissionAction action) { |
| 79 std::string action_str; | 56 std::string action_str; |
| 80 switch (action) { | 57 switch (action) { |
| 81 case GRANTED: | 58 case GRANTED: |
| 82 action_str = "Granted"; | 59 action_str = "Granted"; |
| 83 break; | 60 break; |
| 84 case DENIED: | 61 case DENIED: |
| 85 action_str = "Denied"; | 62 action_str = "Denied"; |
| 86 break; | 63 break; |
| 87 case DISMISSED: | 64 case DISMISSED: |
| 88 action_str = "Dismissed"; | 65 action_str = "Dismissed"; |
| 89 break; | 66 break; |
| 90 case IGNORED: | 67 case IGNORED: |
| 91 action_str = "Ignored"; | 68 action_str = "Ignored"; |
| 92 break; | 69 break; |
| 93 default: | 70 default: |
| 94 NOTREACHED(); | 71 NOTREACHED(); |
| 95 break; | 72 break; |
| 96 } | 73 } |
| 97 | 74 |
| 98 std::string permission_str = GetPermissionString(permission); | 75 std::string permission_str = |
| 76 PermissionUtil::GetPermissionString(permission); |
| 99 if (permission_str.empty()) | 77 if (permission_str.empty()) |
| 100 return ""; | 78 return ""; |
| 101 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", | 79 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", |
| 102 permission_str.c_str(), action_str.c_str()); | 80 permission_str.c_str(), action_str.c_str()); |
| 103 } | 81 } |
| 104 | 82 |
| 105 void RecordPermissionAction(ContentSettingsType permission, | 83 void RecordPermissionAction(ContentSettingsType permission, |
| 106 PermissionAction action, | 84 PermissionAction action, |
| 107 const GURL& requesting_origin) { | 85 const GURL& requesting_origin) { |
| 108 bool secure_origin = content::IsOriginSecure(requesting_origin); | 86 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: | 142 // There are two sets of semi-redundant RAPPOR metrics being reported: |
| 165 // The soon-to-be-deprecated single dimensional ones, and the new | 143 // The soon-to-be-deprecated single dimensional ones, and the new |
| 166 // multi-dimensional ones. | 144 // multi-dimensional ones. |
| 167 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); | 145 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); |
| 168 const std::string rappor_metric = GetRapporMetric(permission, action); | 146 const std::string rappor_metric = GetRapporMetric(permission, action); |
| 169 if (!rappor_metric.empty()) | 147 if (!rappor_metric.empty()) |
| 170 rappor::SampleDomainAndRegistryFromGURL( | 148 rappor::SampleDomainAndRegistryFromGURL( |
| 171 rappor_service, rappor_metric, requesting_origin); | 149 rappor_service, rappor_metric, requesting_origin); |
| 172 | 150 |
| 173 // Add multi-dimensional RAPPOR reporting for safe-browsing users. | 151 // Add multi-dimensional RAPPOR reporting for safe-browsing users. |
| 174 std::string permission_str = GetPermissionString(permission); | 152 std::string permission_str = |
| 153 PermissionUtil::GetPermissionString(permission); |
| 175 if (!rappor_service || permission_str.empty()) | 154 if (!rappor_service || permission_str.empty()) |
| 176 return; | 155 return; |
| 177 | 156 |
| 178 scoped_ptr<rappor::Sample> sample = | 157 scoped_ptr<rappor::Sample> sample = |
| 179 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE); | 158 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE); |
| 180 sample->SetStringField("Scheme", requesting_origin.scheme()); | 159 sample->SetStringField("Scheme", requesting_origin.scheme()); |
| 181 sample->SetStringField("Host", requesting_origin.host()); | 160 sample->SetStringField("Host", requesting_origin.host()); |
| 182 sample->SetStringField("Port", requesting_origin.port()); | 161 sample->SetStringField("Port", requesting_origin.port()); |
| 183 sample->SetStringField("Domain", | 162 sample->SetStringField("Domain", |
| 184 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 163 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 300 |
| 322 void PermissionContextUmaUtil::PermissionDismissed( | 301 void PermissionContextUmaUtil::PermissionDismissed( |
| 323 ContentSettingsType permission, const GURL& requesting_origin) { | 302 ContentSettingsType permission, const GURL& requesting_origin) { |
| 324 RecordPermissionAction(permission, DISMISSED, requesting_origin); | 303 RecordPermissionAction(permission, DISMISSED, requesting_origin); |
| 325 } | 304 } |
| 326 | 305 |
| 327 void PermissionContextUmaUtil::PermissionIgnored( | 306 void PermissionContextUmaUtil::PermissionIgnored( |
| 328 ContentSettingsType permission, const GURL& requesting_origin) { | 307 ContentSettingsType permission, const GURL& requesting_origin) { |
| 329 RecordPermissionAction(permission, IGNORED, requesting_origin); | 308 RecordPermissionAction(permission, IGNORED, requesting_origin); |
| 330 } | 309 } |
| OLD | NEW |