| 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_uma_util.h" | 5 #include "chrome/browser/permissions/permission_uma_util.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 PERMISSION_ACTION_NUM); \ | 29 PERMISSION_ACTION_NUM); \ |
| 30 } else { \ | 30 } else { \ |
| 31 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \ | 31 UMA_HISTOGRAM_ENUMERATION(permission_insecure, action, \ |
| 32 PERMISSION_ACTION_NUM); \ | 32 PERMISSION_ACTION_NUM); \ |
| 33 } | 33 } |
| 34 | 34 |
| 35 using content::PermissionType; | 35 using content::PermissionType; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // Deprecated. This method is used for the single-dimensional RAPPOR metrics | |
| 40 // that are being replaced by the multi-dimensional ones. | |
| 41 const std::string GetRapporMetric(PermissionType permission, | 39 const std::string GetRapporMetric(PermissionType permission, |
| 42 PermissionAction action) { | 40 PermissionAction action) { |
| 43 std::string action_str; | 41 std::string action_str; |
| 44 switch (action) { | 42 switch (action) { |
| 45 case GRANTED: | 43 case GRANTED: |
| 46 action_str = "Granted"; | 44 action_str = "Granted"; |
| 47 break; | 45 break; |
| 48 case DENIED: | 46 case DENIED: |
| 49 action_str = "Denied"; | 47 action_str = "Denied"; |
| 50 break; | 48 break; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // The user is not prompted for these permissions, thus there is no | 135 // The user is not prompted for these permissions, thus there is no |
| 138 // permission action recorded for them. | 136 // permission action recorded for them. |
| 139 case PermissionType::MIDI: | 137 case PermissionType::MIDI: |
| 140 case PermissionType::BACKGROUND_SYNC: | 138 case PermissionType::BACKGROUND_SYNC: |
| 141 case PermissionType::NUM: | 139 case PermissionType::NUM: |
| 142 NOTREACHED() << "PERMISSION " | 140 NOTREACHED() << "PERMISSION " |
| 143 << PermissionUtil::GetPermissionString(permission) | 141 << PermissionUtil::GetPermissionString(permission) |
| 144 << " not accounted for"; | 142 << " not accounted for"; |
| 145 } | 143 } |
| 146 | 144 |
| 147 // There are two sets of semi-redundant RAPPOR metrics being reported: | 145 // Retrieve the name of the RAPPOR metric. Currently, the new metric name is |
| 148 // The soon-to-be-deprecated single dimensional ones, and the new | 146 // the deprecated name with "2" on the end, e.g. |
| 149 // multi-dimensional ones. | 147 // ContentSettings.PermissionActions_Geolocation.Granted.Url2. For simplicity, |
| 148 // we retrieve the deprecated name and append the "2" for the new name. |
| 149 // TODO(dominickn): remove the deprecated metric and replace it solely with |
| 150 // the new one in GetRapporMetric - crbug.com/605836. |
| 151 const std::string deprecated_metric = GetRapporMetric(permission, action); |
| 150 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); | 152 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); |
| 151 const std::string rappor_metric = GetRapporMetric(permission, action); | 153 if (!deprecated_metric.empty() && rappor_service) { |
| 152 if (!rappor_metric.empty()) | 154 rappor::SampleDomainAndRegistryFromGURL(rappor_service, deprecated_metric, |
| 153 rappor::SampleDomainAndRegistryFromGURL( | 155 requesting_origin); |
| 154 rappor_service, rappor_metric, requesting_origin); | |
| 155 | 156 |
| 156 // Add multi-dimensional RAPPOR reporting for safe-browsing users. | 157 std::string rappor_metric = deprecated_metric + "2"; |
| 157 std::string permission_str = | 158 rappor_service->RecordSample( |
| 158 PermissionUtil::GetPermissionString(permission); | 159 rappor_metric, rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 159 if (!rappor_service || permission_str.empty()) | 160 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
| 160 return; | 161 } |
| 161 | |
| 162 std::unique_ptr<rappor::Sample> sample = | |
| 163 rappor_service->CreateSample(rappor::SAFEBROWSING_RAPPOR_TYPE); | |
| 164 sample->SetStringField("Scheme", requesting_origin.scheme()); | |
| 165 sample->SetStringField("Host", requesting_origin.host()); | |
| 166 sample->SetStringField("Port", requesting_origin.port()); | |
| 167 sample->SetStringField("Domain", | |
| 168 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | |
| 169 sample->SetFlagsField("Actions", static_cast<uint64_t>(1) << action, | |
| 170 PermissionAction::PERMISSION_ACTION_NUM); | |
| 171 rappor_service->RecordSampleObj("Permissions.Action." + permission_str, | |
| 172 std::move(sample)); | |
| 173 } | 162 } |
| 174 | 163 |
| 175 void RecordPermissionRequest(PermissionType permission, | 164 void RecordPermissionRequest(PermissionType permission, |
| 176 const GURL& requesting_origin, | 165 const GURL& requesting_origin, |
| 177 const GURL& embedding_origin, | 166 const GURL& embedding_origin, |
| 178 Profile* profile) { | 167 Profile* profile) { |
| 179 bool secure_origin = content::IsOriginSecure(requesting_origin); | 168 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); |
| 180 if (permission == PermissionType::GEOLOCATION) { | 169 if (rappor_service) { |
| 170 if (permission == PermissionType::GEOLOCATION) { |
| 171 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. |
| 181 rappor::SampleDomainAndRegistryFromGURL( | 172 rappor::SampleDomainAndRegistryFromGURL( |
| 182 g_browser_process->rappor_service(), | 173 rappor_service, |
| 183 "ContentSettings.PermissionRequested.Geolocation.Url", | 174 "ContentSettings.PermissionRequested.Geolocation.Url", |
| 184 requesting_origin); | 175 requesting_origin); |
| 185 } else if (permission == PermissionType::NOTIFICATIONS) { | 176 rappor_service->RecordSample( |
| 177 "ContentSettings.PermissionRequested.Geolocation.Url2", |
| 178 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 179 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
| 180 } else if (permission == PermissionType::NOTIFICATIONS) { |
| 181 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. |
| 186 rappor::SampleDomainAndRegistryFromGURL( | 182 rappor::SampleDomainAndRegistryFromGURL( |
| 187 g_browser_process->rappor_service(), | 183 rappor_service, |
| 188 "ContentSettings.PermissionRequested.Notifications.Url", | 184 "ContentSettings.PermissionRequested.Notifications.Url", |
| 189 requesting_origin); | 185 requesting_origin); |
| 186 rappor_service->RecordSample( |
| 187 "ContentSettings.PermissionRequested.Notifications.Url2", |
| 188 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 189 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
| 190 } |
| 190 } | 191 } |
| 192 |
| 193 bool secure_origin = content::IsOriginSecure(requesting_origin); |
| 191 UMA_HISTOGRAM_ENUMERATION( | 194 UMA_HISTOGRAM_ENUMERATION( |
| 192 "ContentSettings.PermissionRequested", | 195 "ContentSettings.PermissionRequested", |
| 193 static_cast<base::HistogramBase::Sample>(permission), | 196 static_cast<base::HistogramBase::Sample>(permission), |
| 194 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 197 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 195 if (secure_origin) { | 198 if (secure_origin) { |
| 196 UMA_HISTOGRAM_ENUMERATION( | 199 UMA_HISTOGRAM_ENUMERATION( |
| 197 "ContentSettings.PermissionRequested_SecureOrigin", | 200 "ContentSettings.PermissionRequested_SecureOrigin", |
| 198 static_cast<base::HistogramBase::Sample>(permission), | 201 static_cast<base::HistogramBase::Sample>(permission), |
| 199 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); | 202 static_cast<base::HistogramBase::Sample>(PermissionType::NUM)); |
| 200 } else { | 203 } else { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 const std::vector<PermissionBubbleRequest*>& requests) { | 283 const std::vector<PermissionBubbleRequest*>& requests) { |
| 281 DCHECK(!requests.empty()); | 284 DCHECK(!requests.empty()); |
| 282 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; | 285 PermissionBubbleType permission_prompt_type = PermissionBubbleType::MULTIPLE; |
| 283 if (requests.size() == 1) | 286 if (requests.size() == 1) |
| 284 permission_prompt_type = requests[0]->GetPermissionBubbleType(); | 287 permission_prompt_type = requests[0]->GetPermissionBubbleType(); |
| 285 UMA_HISTOGRAM_ENUMERATION( | 288 UMA_HISTOGRAM_ENUMERATION( |
| 286 "Permissions.Prompt.Shown", | 289 "Permissions.Prompt.Shown", |
| 287 static_cast<base::HistogramBase::Sample>(permission_prompt_type), | 290 static_cast<base::HistogramBase::Sample>(permission_prompt_type), |
| 288 static_cast<base::HistogramBase::Sample>(PermissionBubbleType::NUM)); | 291 static_cast<base::HistogramBase::Sample>(PermissionBubbleType::NUM)); |
| 289 } | 292 } |
| OLD | NEW |