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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 13 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
14 #include "chrome/browser/permissions/permission_manager.h" | 14 #include "chrome/browser/permissions/permission_manager.h" |
15 #include "chrome/browser/permissions/permission_request.h" | 15 #include "chrome/browser/permissions/permission_request.h" |
16 #include "chrome/browser/permissions/permission_util.h" | 16 #include "chrome/browser/permissions/permission_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "chrome/browser/safe_browsing/ui_manager.h" | 19 #include "chrome/browser/safe_browsing/ui_manager.h" |
20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "components/browser_sync/profile_sync_service.h" | 23 #include "components/browser_sync/profile_sync_service.h" |
24 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
25 #include "components/rappor/rappor_service.h" | 25 #include "components/rappor/public/rappor_utils.h" |
26 #include "components/rappor/rappor_utils.h" | 26 #include "components/rappor/rappor_service_impl.h" |
27 #include "content/public/browser/permission_type.h" | 27 #include "content/public/browser/permission_type.h" |
28 #include "content/public/common/origin_util.h" | 28 #include "content/public/common/origin_util.h" |
29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
30 | 30 |
31 // UMA keys need to be statically initialized so plain function would not | 31 // UMA keys need to be statically initialized so plain function would not |
32 // work. Use macros instead. | 32 // work. Use macros instead. |
33 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ | 33 #define PERMISSION_ACTION_UMA(secure_origin, permission, permission_secure, \ |
34 permission_insecure, action) \ | 34 permission_insecure, action) \ |
35 UMA_HISTOGRAM_ENUMERATION(permission, action, PERMISSION_ACTION_NUM); \ | 35 UMA_HISTOGRAM_ENUMERATION(permission, action, PERMISSION_ACTION_NUM); \ |
36 if (secure_origin) { \ | 36 if (secure_origin) { \ |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (permission_str.empty()) | 90 if (permission_str.empty()) |
91 return ""; | 91 return ""; |
92 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", | 92 return base::StringPrintf("ContentSettings.PermissionActions_%s.%s.Url", |
93 permission_str.c_str(), action_str.c_str()); | 93 permission_str.c_str(), action_str.c_str()); |
94 } | 94 } |
95 | 95 |
96 void RecordPermissionRequest(PermissionType permission, | 96 void RecordPermissionRequest(PermissionType permission, |
97 const GURL& requesting_origin, | 97 const GURL& requesting_origin, |
98 const GURL& embedding_origin, | 98 const GURL& embedding_origin, |
99 Profile* profile) { | 99 Profile* profile) { |
100 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); | 100 rappor::RapporServiceImpl* rappor_service = |
| 101 g_browser_process->rappor_service(); |
101 if (rappor_service) { | 102 if (rappor_service) { |
102 if (permission == PermissionType::GEOLOCATION) { | 103 if (permission == PermissionType::GEOLOCATION) { |
103 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. | 104 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. |
104 rappor::SampleDomainAndRegistryFromGURL( | 105 rappor::SampleDomainAndRegistryFromGURL( |
105 rappor_service, "ContentSettings.PermissionRequested.Geolocation.Url", | 106 rappor_service, "ContentSettings.PermissionRequested.Geolocation.Url", |
106 requesting_origin); | 107 requesting_origin); |
107 rappor_service->RecordSample( | 108 rappor_service->RecordSampleString( |
108 "ContentSettings.PermissionRequested.Geolocation.Url2", | 109 "ContentSettings.PermissionRequested.Geolocation.Url2", |
109 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, | 110 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
110 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 111 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
111 } else if (permission == PermissionType::NOTIFICATIONS) { | 112 } else if (permission == PermissionType::NOTIFICATIONS) { |
112 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. | 113 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. |
113 rappor::SampleDomainAndRegistryFromGURL( | 114 rappor::SampleDomainAndRegistryFromGURL( |
114 rappor_service, | 115 rappor_service, |
115 "ContentSettings.PermissionRequested.Notifications.Url", | 116 "ContentSettings.PermissionRequested.Notifications.Url", |
116 requesting_origin); | 117 requesting_origin); |
117 rappor_service->RecordSample( | 118 rappor_service->RecordSampleString( |
118 "ContentSettings.PermissionRequested.Notifications.Url2", | 119 "ContentSettings.PermissionRequested.Notifications.Url2", |
119 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, | 120 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
120 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 121 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
121 } else if (permission == PermissionType::MIDI || | 122 } else if (permission == PermissionType::MIDI || |
122 permission == PermissionType::MIDI_SYSEX) { | 123 permission == PermissionType::MIDI_SYSEX) { |
123 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. | 124 // TODO(dominickn): remove this deprecated metric - crbug.com/605836. |
124 rappor::SampleDomainAndRegistryFromGURL( | 125 rappor::SampleDomainAndRegistryFromGURL( |
125 rappor_service, "ContentSettings.PermissionRequested.Midi.Url", | 126 rappor_service, "ContentSettings.PermissionRequested.Midi.Url", |
126 requesting_origin); | 127 requesting_origin); |
127 rappor_service->RecordSample( | 128 rappor_service->RecordSampleString( |
128 "ContentSettings.PermissionRequested.Midi.Url2", | 129 "ContentSettings.PermissionRequested.Midi.Url2", |
129 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, | 130 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
130 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 131 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
131 } else if (permission == PermissionType::PROTECTED_MEDIA_IDENTIFIER) { | 132 } else if (permission == PermissionType::PROTECTED_MEDIA_IDENTIFIER) { |
132 rappor_service->RecordSample( | 133 rappor_service->RecordSampleString( |
133 "ContentSettings.PermissionRequested.ProtectedMedia.Url2", | 134 "ContentSettings.PermissionRequested.ProtectedMedia.Url2", |
134 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, | 135 rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
135 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 136 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 bool secure_origin = content::IsOriginSecure(requesting_origin); | 140 bool secure_origin = content::IsOriginSecure(requesting_origin); |
140 UMA_HISTOGRAM_ENUMERATION( | 141 UMA_HISTOGRAM_ENUMERATION( |
141 "ContentSettings.PermissionRequested", | 142 "ContentSettings.PermissionRequested", |
142 static_cast<base::HistogramBase::Sample>(permission), | 143 static_cast<base::HistogramBase::Sample>(permission), |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 << " not accounted for"; | 704 << " not accounted for"; |
704 } | 705 } |
705 | 706 |
706 // Retrieve the name of the RAPPOR metric. Currently, the new metric name is | 707 // Retrieve the name of the RAPPOR metric. Currently, the new metric name is |
707 // the deprecated name with "2" on the end, e.g. | 708 // the deprecated name with "2" on the end, e.g. |
708 // ContentSettings.PermissionActions_Geolocation.Granted.Url2. For simplicity, | 709 // ContentSettings.PermissionActions_Geolocation.Granted.Url2. For simplicity, |
709 // we retrieve the deprecated name and append the "2" for the new name. | 710 // we retrieve the deprecated name and append the "2" for the new name. |
710 // TODO(dominickn): remove the deprecated metric and replace it solely with | 711 // TODO(dominickn): remove the deprecated metric and replace it solely with |
711 // the new one in GetRapporMetric - crbug.com/605836. | 712 // the new one in GetRapporMetric - crbug.com/605836. |
712 const std::string deprecated_metric = GetRapporMetric(permission, action); | 713 const std::string deprecated_metric = GetRapporMetric(permission, action); |
713 rappor::RapporService* rappor_service = g_browser_process->rappor_service(); | 714 rappor::RapporServiceImpl* rappor_service = |
| 715 g_browser_process->rappor_service(); |
714 if (!deprecated_metric.empty() && rappor_service) { | 716 if (!deprecated_metric.empty() && rappor_service) { |
715 rappor::SampleDomainAndRegistryFromGURL(rappor_service, deprecated_metric, | 717 rappor::SampleDomainAndRegistryFromGURL(rappor_service, deprecated_metric, |
716 requesting_origin); | 718 requesting_origin); |
717 | 719 |
718 std::string rappor_metric = deprecated_metric + "2"; | 720 std::string rappor_metric = deprecated_metric + "2"; |
719 rappor_service->RecordSample( | 721 rappor_service->RecordSampleString( |
720 rappor_metric, rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, | 722 rappor_metric, rappor::LOW_FREQUENCY_ETLD_PLUS_ONE_RAPPOR_TYPE, |
721 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); | 723 rappor::GetDomainAndRegistrySampleFromGURL(requesting_origin)); |
722 } | 724 } |
723 } | 725 } |
OLD | NEW |