Chromium Code Reviews| 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 "base/metrics/histogram_macros.h" | 5 #include "base/metrics/histogram_macros.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 8 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
| 9 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 9 #include "components/rappor/rappor_utils.h" | 10 #include "components/rappor/rappor_utils.h" |
| 10 #include "content/public/browser/permission_type.h" | 11 #include "content/public/browser/permission_type.h" |
| 11 #include "content/public/common/origin_util.h" | 12 #include "content/public/common/origin_util.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 // UMA keys need to be statically initialized so plain function would not | 15 // UMA keys need to be statically initialized so plain function would not |
| 15 // work. Use a Macro instead. | 16 // work. Use a Macro instead. |
| 16 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ | 17 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ |
| 17 permission_insecure, action) \ | 18 permission_insecure, action) \ |
| 18 UMA_HISTOGRAM_ENUMERATION(permission, action, PERMISSION_ACTION_NUM); \ | 19 UMA_HISTOGRAM_ENUMERATION(permission, action, PERMISSION_ACTION_NUM); \ |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; | 133 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 133 } | 134 } |
| 134 | 135 |
| 135 const std::string& rappor_metric = GetRapporMetric(permission, action); | 136 const std::string& rappor_metric = GetRapporMetric(permission, action); |
| 136 if (!rappor_metric.empty()) | 137 if (!rappor_metric.empty()) |
| 137 rappor::SampleDomainAndRegistryFromGURL( | 138 rappor::SampleDomainAndRegistryFromGURL( |
| 138 g_browser_process->rappor_service(), rappor_metric, | 139 g_browser_process->rappor_service(), rappor_metric, |
| 139 requesting_origin); | 140 requesting_origin); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void RecordPermissionRequest(ContentSettingsType permission, | 143 std::string PermissionTypeToString(PermissionType permission_type) { |
| 143 const GURL& requesting_origin) { | 144 switch (permission_type) { |
| 145 case PermissionType::MIDI_SYSEX: | |
| 146 return "MidiSysex"; | |
| 147 case PermissionType::PUSH_MESSAGING: | |
| 148 return "PushMessaging"; | |
| 149 case PermissionType::NOTIFICATIONS: | |
| 150 return "Notifications"; | |
| 151 case PermissionType::GEOLOCATION: | |
| 152 return "Geolocation"; | |
| 153 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 154 return "ProtectedMediaIdentifier"; | |
| 155 case PermissionType::NUM: | |
| 156 NOTREACHED(); | |
| 157 } | |
| 158 return std::string(); | |
|
mlamouri (slow - plz ping)
2015/06/30 10:27:20
nit: could you add a NOTREACHED() here too? Sorry,
keenanb
2015/06/30 21:20:07
might as well just move NOTREACHED.
| |
| 159 } | |
| 160 | |
| 161 void RecordPermissionRequest( | |
| 162 ContentSettingsType permission, | |
| 163 const GURL& requesting_origin, | |
| 164 const GURL& embedding_origin, | |
| 165 HostContentSettingsMap* host_content_settings_map) { | |
| 144 bool secure_origin = content::IsOriginSecure(requesting_origin); | 166 bool secure_origin = content::IsOriginSecure(requesting_origin); |
| 145 PermissionType type; | 167 PermissionType type; |
| 146 switch (permission) { | 168 switch (permission) { |
| 147 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 169 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 148 type = PermissionType::GEOLOCATION; | 170 type = PermissionType::GEOLOCATION; |
| 149 rappor::SampleDomainAndRegistryFromGURL( | 171 rappor::SampleDomainAndRegistryFromGURL( |
| 150 g_browser_process->rappor_service(), | 172 g_browser_process->rappor_service(), |
| 151 "ContentSettings.PermissionRequested.Geolocation.Url", | 173 "ContentSettings.PermissionRequested.Geolocation.Url", |
| 152 requesting_origin); | 174 requesting_origin); |
| 153 break; | 175 break; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 181 UMA_HISTOGRAM_ENUMERATION( | 203 UMA_HISTOGRAM_ENUMERATION( |
| 182 "ContentSettings.PermissionRequested_SecureOrigin", | 204 "ContentSettings.PermissionRequested_SecureOrigin", |
| 183 static_cast<base::HistogramBase::Sample>(type), | 205 static_cast<base::HistogramBase::Sample>(type), |
| 184 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 206 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 185 } else { | 207 } else { |
| 186 UMA_HISTOGRAM_ENUMERATION( | 208 UMA_HISTOGRAM_ENUMERATION( |
| 187 "ContentSettings.PermissionRequested_InsecureOrigin", | 209 "ContentSettings.PermissionRequested_InsecureOrigin", |
| 188 static_cast<base::HistogramBase::Sample>(type), | 210 static_cast<base::HistogramBase::Sample>(type), |
| 189 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 211 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 190 } | 212 } |
| 213 | |
| 214 // We have dicided not to worry about it, | |
| 215 // but statistics will get skewed if, for example, | |
| 216 // before the user has made a permission decision, | |
| 217 // getCurrentPosition gets called ten times each second | |
| 218 // and generates ten permission requests each second. | |
| 219 // That may be a job for RAPPOR. | |
|
mlamouri (slow - plz ping)
2015/06/30 10:27:20
nit: the wrapping of that comment block seems off.
keenanb
2015/06/30 21:20:08
Done.
| |
| 220 if (requesting_origin.GetOrigin() != embedding_origin.GetOrigin()) { | |
| 221 ContentSetting embedding_content_setting = | |
| 222 host_content_settings_map->GetContentSetting( | |
| 223 embedding_origin, embedding_origin, permission, std::string()); | |
|
mlamouri (slow - plz ping)
2015/06/30 10:27:20
Could you get the profile instead of HostContentSe
keenanb
2015/06/30 21:20:08
Profile does not expose GetPermissionStatus; it's
mlamouri (slow - plz ping)
2015/07/01 11:23:05
You can get the PermissionManager from a profile (
| |
| 224 UMA_HISTOGRAM_ENUMERATION("ContentSettings.PermissionRequested.OffOrigin_" + | |
| 225 PermissionTypeToString(type), | |
| 226 embedding_content_setting, | |
| 227 CONTENT_SETTING_NUM_SETTINGS); | |
| 228 } else { | |
| 229 UMA_HISTOGRAM_ENUMERATION( | |
| 230 "ContentSettings.PermissionRequested.SameOrigin", | |
| 231 static_cast<base::HistogramBase::Sample>(type), | |
| 232 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | |
| 233 } | |
| 191 } | 234 } |
| 192 | 235 |
| 193 } // namespace | 236 } // namespace |
| 194 | 237 |
| 195 // Make sure you update histograms.xml permission histogram_suffix if you | 238 // Make sure you update histograms.xml permission histogram_suffix if you |
| 196 // add new permission | 239 // add new permission |
| 197 void PermissionContextUmaUtil::PermissionRequested( | 240 void PermissionContextUmaUtil::PermissionRequested( |
| 198 ContentSettingsType permission, const GURL& requesting_origin) { | 241 ContentSettingsType permission, |
| 199 RecordPermissionRequest(permission, requesting_origin); | 242 const GURL& requesting_origin, |
| 243 const GURL& embedding_origin, | |
| 244 HostContentSettingsMap* host_content_settings_map) { | |
| 245 RecordPermissionRequest(permission, requesting_origin, embedding_origin, | |
| 246 host_content_settings_map); | |
| 200 } | 247 } |
| 201 | 248 |
| 202 void PermissionContextUmaUtil::PermissionGranted( | 249 void PermissionContextUmaUtil::PermissionGranted( |
| 203 ContentSettingsType permission, const GURL& requesting_origin) { | 250 ContentSettingsType permission, const GURL& requesting_origin) { |
| 204 RecordPermissionAction(permission, GRANTED, requesting_origin); | 251 RecordPermissionAction(permission, GRANTED, requesting_origin); |
| 205 } | 252 } |
| 206 | 253 |
| 207 void PermissionContextUmaUtil::PermissionDenied( | 254 void PermissionContextUmaUtil::PermissionDenied( |
| 208 ContentSettingsType permission, const GURL& requesting_origin) { | 255 ContentSettingsType permission, const GURL& requesting_origin) { |
| 209 RecordPermissionAction(permission, DENIED, requesting_origin); | 256 RecordPermissionAction(permission, DENIED, requesting_origin); |
| 210 } | 257 } |
| 211 | 258 |
| 212 void PermissionContextUmaUtil::PermissionDismissed( | 259 void PermissionContextUmaUtil::PermissionDismissed( |
| 213 ContentSettingsType permission, const GURL& requesting_origin) { | 260 ContentSettingsType permission, const GURL& requesting_origin) { |
| 214 RecordPermissionAction(permission, DISMISSED, requesting_origin); | 261 RecordPermissionAction(permission, DISMISSED, requesting_origin); |
| 215 } | 262 } |
| 216 | 263 |
| 217 void PermissionContextUmaUtil::PermissionIgnored( | 264 void PermissionContextUmaUtil::PermissionIgnored( |
| 218 ContentSettingsType permission, const GURL& requesting_origin) { | 265 ContentSettingsType permission, const GURL& requesting_origin) { |
| 219 RecordPermissionAction(permission, IGNORED, requesting_origin); | 266 RecordPermissionAction(permission, IGNORED, requesting_origin); |
| 220 } | 267 } |
| OLD | NEW |