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/rappor/rappor_utils.h" | 9 #include "components/rappor/rappor_utils.h" |
| 10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; | 132 NOTREACHED() << "PERMISSION " << permission << " not accounted for"; |
| 133 } | 133 } |
| 134 | 134 |
| 135 const std::string& rappor_metric = GetRapporMetric(permission, action); | 135 const std::string& rappor_metric = GetRapporMetric(permission, action); |
| 136 if (!rappor_metric.empty()) | 136 if (!rappor_metric.empty()) |
| 137 rappor::SampleDomainAndRegistryFromGURL( | 137 rappor::SampleDomainAndRegistryFromGURL( |
| 138 g_browser_process->rappor_service(), rappor_metric, | 138 g_browser_process->rappor_service(), rappor_metric, |
| 139 requesting_origin); | 139 requesting_origin); |
| 140 } | 140 } |
| 141 | 141 |
| 142 std::string PermissionTypeToString(PermissionType permission_type) { | |
| 143 switch (permission_type) { | |
| 144 case PermissionType::MIDI_SYSEX: | |
| 145 return "MidiSysex"; | |
| 146 case PermissionType::PUSH_MESSAGING: | |
| 147 return "PushMessagin"; | |
| 148 case PermissionType::NOTIFICATIONS: | |
| 149 return "Notifications"; | |
| 150 case PermissionType::GEOLOCATION: | |
| 151 return "Geolocation"; | |
| 152 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 153 return "ProtectedMediaIdentifier"; | |
| 154 default: | |
| 155 // TODO(keenanb) | |
|
jww
2015/06/23 05:32:58
I don't really think this is necessary at all, so
mlamouri (slow - plz ping)
2015/06/23 10:02:32
You might actually want to have no default case so
keenanb
2015/06/24 22:26:11
Done.
keenanb
2015/06/24 22:26:11
Done.
| |
| 156 // NOTREACHED() << "PERMISSION TYPE " << | |
| 157 // permission_type << " not accounted for"; | |
| 158 return "UnknownPermissionType"; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 std::string ContentSettingToString(ContentSetting content_setting) { | |
| 163 switch (content_setting) { | |
| 164 case CONTENT_SETTING_DEFAULT: | |
| 165 return "Default"; | |
| 166 case CONTENT_SETTING_ALLOW: | |
| 167 return "Allow"; | |
| 168 case CONTENT_SETTING_BLOCK: | |
| 169 return "Block"; | |
| 170 case CONTENT_SETTING_ASK: | |
| 171 return "Ask"; | |
| 172 case CONTENT_SETTING_SESSION_ONLY: | |
| 173 return "SessionOnly"; | |
| 174 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | |
| 175 return "DetectImportant"; | |
| 176 default: | |
| 177 // TODO(keenanb) | |
| 178 // NOTREACHED() << "CONTENT SETTING " | |
|
jww
2015/06/23 05:32:58
See above comment.
mlamouri (slow - plz ping)
2015/06/23 10:02:32
ditto. Also, you probably don't need SessionOnly,
keenanb
2015/06/24 22:26:11
Done.
keenanb
2015/06/24 22:26:11
Done.
| |
| 179 // << content_setting << " not accounted for"; | |
| 180 return "UnknownContentSetting"; | |
| 181 } | |
| 182 } | |
| 183 | |
| 142 void RecordPermissionRequest(ContentSettingsType permission, | 184 void RecordPermissionRequest(ContentSettingsType permission, |
| 143 const GURL& requesting_origin) { | 185 HostContentSettingsMap* hostContentSettingsMap, |
| 186 const GURL& requesting_origin, | |
| 187 const GURL& embedding_origin) { | |
| 144 bool secure_origin = content::IsOriginSecure(requesting_origin); | 188 bool secure_origin = content::IsOriginSecure(requesting_origin); |
| 145 PermissionType type; | 189 PermissionType type; |
| 146 switch (permission) { | 190 switch (permission) { |
| 147 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 191 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 148 type = PermissionType::GEOLOCATION; | 192 type = PermissionType::GEOLOCATION; |
| 149 rappor::SampleDomainAndRegistryFromGURL( | 193 rappor::SampleDomainAndRegistryFromGURL( |
| 150 g_browser_process->rappor_service(), | 194 g_browser_process->rappor_service(), |
| 151 "ContentSettings.PermissionRequested.Geolocation.Url", | 195 "ContentSettings.PermissionRequested.Geolocation.Url", |
| 152 requesting_origin); | 196 requesting_origin); |
| 153 break; | 197 break; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 181 UMA_HISTOGRAM_ENUMERATION( | 225 UMA_HISTOGRAM_ENUMERATION( |
| 182 "ContentSettings.PermissionRequested_SecureOrigin", | 226 "ContentSettings.PermissionRequested_SecureOrigin", |
| 183 static_cast<base::HistogramBase::Sample>(type), | 227 static_cast<base::HistogramBase::Sample>(type), |
| 184 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 228 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 185 } else { | 229 } else { |
| 186 UMA_HISTOGRAM_ENUMERATION( | 230 UMA_HISTOGRAM_ENUMERATION( |
| 187 "ContentSettings.PermissionRequested_InsecureOrigin", | 231 "ContentSettings.PermissionRequested_InsecureOrigin", |
| 188 static_cast<base::HistogramBase::Sample>(type), | 232 static_cast<base::HistogramBase::Sample>(type), |
| 189 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 233 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 190 } | 234 } |
| 235 | |
| 236 // TODO(keenanb): skip if another permission request is already pending. | |
| 237 // otherwise statistics get skewed when, for example, | |
| 238 // getCurrentPosition gets called ten times each second. | |
| 239 // (it could even be best to check for pending requests | |
| 240 // in permission_context_uma_util which calls this function.) | |
| 241 // just make sure to invoke the callback. | |
| 242 | |
| 243 std::string permission_type_string = PermissionTypeToString(type); | |
| 244 | |
| 245 // FIXME(keenanb): find out if using the same value | |
| 246 // for both primary and secondary GURLs could be bad or subpar. | |
| 247 ContentSetting embedding_content_setting = | |
| 248 hostContentSettingsMap->GetContentSettingAndMaybeUpdateLastUsage( | |
|
mlamouri (slow - plz ping)
2015/06/23 10:02:32
I'm not sure you want to call the "MaybeUpdateLast
keenanb
2015/06/24 22:26:11
Done.
| |
| 249 embedding_origin, embedding_origin, permission, std::string()); | |
| 250 std::string embedding_content_setting_string = | |
| 251 ContentSettingToString(embedding_content_setting); | |
| 252 | |
| 253 // TODO(keenanb): is calling GetOrigin redundant? | |
|
felt
2015/06/22 22:56:01
Test out the behavior, do you need to call GetOrig
keenanb
2015/06/24 22:26:11
i had tested it. it looks to be always a pure orig
| |
| 254 // check calling code arguments. | |
| 255 bool requester_is_off_origin_iframe = | |
| 256 requesting_origin.GetOrigin() != embedding_origin.GetOrigin(); | |
| 257 if (requester_is_off_origin_iframe) { | |
|
mlamouri (slow - plz ping)
2015/06/23 10:02:32
I guess you can get ride of the bool and directly
keenanb
2015/06/24 22:26:11
thanks for the tip. partly done. i'd rather keep t
| |
| 258 // Summing over all top frame content setting values | |
| 259 // would give the total of all iframe requests. | |
| 260 UMA_HISTOGRAM_ENUMERATION( | |
| 261 base::StringPrintf( | |
|
jww
2015/06/23 05:32:58
Use base::SStringPrintf instead to avoid the call
keenanb
2015/06/24 22:26:11
Acknowledged.
| |
| 262 "ContentSettings.PermissionRequested_IFrame.%s.TopFrame%s", | |
| 263 permission_type_string.c_str(), | |
| 264 embedding_content_setting_string.c_str()), | |
| 265 static_cast<base::HistogramBase::Sample>(type), | |
| 266 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | |
| 267 } else { | |
| 268 // Record when a top frame requests a permission for comparison. | |
| 269 UMA_HISTOGRAM_ENUMERATION( | |
|
jww
2015/06/23 05:32:58
See above re: SStringPrintf.
keenanb
2015/06/24 22:26:11
Acknowledged.
| |
| 270 base::StringPrintf("ContentSettings.PermissionRequested_TopFrame.%s", | |
|
jww
2015/06/23 05:32:58
Personally, I think this would be a little easier
keenanb
2015/06/24 22:26:11
good point. but that would only almost work. the e
| |
| 271 permission_type_string.c_str()), | |
| 272 static_cast<base::HistogramBase::Sample>(type), | |
| 273 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | |
| 274 } | |
| 191 } | 275 } |
| 192 | 276 |
| 193 } // namespace | 277 } // namespace |
| 194 | 278 |
| 195 // Make sure you update histograms.xml permission histogram_suffix if you | 279 // Make sure you update histograms.xml permission histogram_suffix if you |
| 196 // add new permission | 280 // add new permission |
| 197 void PermissionContextUmaUtil::PermissionRequested( | 281 void PermissionContextUmaUtil::PermissionRequested( |
| 198 ContentSettingsType permission, const GURL& requesting_origin) { | 282 ContentSettingsType permission, |
| 199 RecordPermissionRequest(permission, requesting_origin); | 283 HostContentSettingsMap* hostContentSettingsMap, |
| 284 const GURL& requesting_origin, | |
| 285 const GURL& embedding_origin) { | |
| 286 RecordPermissionRequest(permission, hostContentSettingsMap, requesting_origin, | |
| 287 embedding_origin); | |
| 200 } | 288 } |
| 201 | 289 |
| 202 void PermissionContextUmaUtil::PermissionGranted( | 290 void PermissionContextUmaUtil::PermissionGranted( |
| 203 ContentSettingsType permission, const GURL& requesting_origin) { | 291 ContentSettingsType permission, const GURL& requesting_origin) { |
| 204 RecordPermissionAction(permission, GRANTED, requesting_origin); | 292 RecordPermissionAction(permission, GRANTED, requesting_origin); |
| 205 } | 293 } |
| 206 | 294 |
| 207 void PermissionContextUmaUtil::PermissionDenied( | 295 void PermissionContextUmaUtil::PermissionDenied( |
| 208 ContentSettingsType permission, const GURL& requesting_origin) { | 296 ContentSettingsType permission, const GURL& requesting_origin) { |
| 209 RecordPermissionAction(permission, DENIED, requesting_origin); | 297 RecordPermissionAction(permission, DENIED, requesting_origin); |
| 210 } | 298 } |
| 211 | 299 |
| 212 void PermissionContextUmaUtil::PermissionDismissed( | 300 void PermissionContextUmaUtil::PermissionDismissed( |
| 213 ContentSettingsType permission, const GURL& requesting_origin) { | 301 ContentSettingsType permission, const GURL& requesting_origin) { |
| 214 RecordPermissionAction(permission, DISMISSED, requesting_origin); | 302 RecordPermissionAction(permission, DISMISSED, requesting_origin); |
| 215 } | 303 } |
| 216 | 304 |
| 217 void PermissionContextUmaUtil::PermissionIgnored( | 305 void PermissionContextUmaUtil::PermissionIgnored( |
| 218 ContentSettingsType permission, const GURL& requesting_origin) { | 306 ContentSettingsType permission, const GURL& requesting_origin) { |
| 219 RecordPermissionAction(permission, IGNORED, requesting_origin); | 307 RecordPermissionAction(permission, IGNORED, requesting_origin); |
| 220 } | 308 } |
| OLD | NEW |