Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / profiles / profile_metrics.cc
bloba829be238793e76afa1d163b7239a18873845578
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile_metrics.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/installer/util/google_update_settings.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/user_metrics.h"
19 namespace {
21 const int kMaximumReportedProfileCount = 5;
22 const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks.
24 struct ProfileCounts {
25 size_t total;
26 size_t signedin;
27 size_t managed;
28 size_t unused;
30 ProfileCounts() : total(0), signedin(0), managed(0), unused(0) {}
33 ProfileMetrics::ProfileType GetProfileType(
34 const base::FilePath& profile_path) {
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
36 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY;
37 ProfileManager* manager = g_browser_process->profile_manager();
38 base::FilePath user_data_dir;
39 // In unittests, we do not always have a profile_manager so check.
40 if (manager) {
41 user_data_dir = manager->user_data_dir();
43 if (profile_path == user_data_dir.AppendASCII(chrome::kInitialProfile)) {
44 metric = ProfileMetrics::ORIGINAL;
46 return metric;
49 void UpdateReportedOSProfileStatistics(int active, int signedin) {
50 #if defined(OS_WIN)
51 GoogleUpdateSettings::UpdateProfileCounts(active, signedin);
52 #endif
55 bool CountProfileInformation(ProfileManager* manager, ProfileCounts* counts) {
56 const ProfileInfoCache& info_cache = manager->GetProfileInfoCache();
57 size_t number_of_profiles = info_cache.GetNumberOfProfiles();
58 counts->total = number_of_profiles;
60 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests.
61 if (!number_of_profiles)
62 return false;
64 // Maximum age for "active" profile is 4 weeks.
65 base::Time oldest = base::Time::Now() -
66 base::TimeDelta::FromDays(kMaximumDaysOfDisuse);
68 for (size_t i = 0; i < number_of_profiles; ++i) {
69 if (info_cache.GetProfileActiveTimeAtIndex(i) < oldest) {
70 counts->unused++;
71 } else {
72 if (info_cache.ProfileIsManagedAtIndex(i))
73 counts->managed++;
74 if (!info_cache.GetUserNameOfProfileAtIndex(i).empty())
75 counts->signedin++;
78 return true;
81 } // namespace
83 enum ProfileAvatar {
84 AVATAR_GENERIC = 0, // The names for avatar icons
85 AVATAR_GENERIC_AQUA,
86 AVATAR_GENERIC_BLUE,
87 AVATAR_GENERIC_GREEN,
88 AVATAR_GENERIC_ORANGE,
89 AVATAR_GENERIC_PURPLE,
90 AVATAR_GENERIC_RED,
91 AVATAR_GENERIC_YELLOW,
92 AVATAR_SECRET_AGENT,
93 AVATAR_SUPERHERO,
94 AVATAR_VOLLEYBALL, // 10
95 AVATAR_BUSINESSMAN,
96 AVATAR_NINJA,
97 AVATAR_ALIEN,
98 AVATAR_AWESOME,
99 AVATAR_FLOWER,
100 AVATAR_PIZZA,
101 AVATAR_SOCCER,
102 AVATAR_BURGER,
103 AVATAR_CAT,
104 AVATAR_CUPCAKE, // 20
105 AVATAR_DOG,
106 AVATAR_HORSE,
107 AVATAR_MARGARITA,
108 AVATAR_NOTE,
109 AVATAR_SUN_CLOUD,
110 AVATAR_PLACEHOLDER,
111 AVATAR_UNKNOWN, // 27
112 AVATAR_GAIA, // 28
113 NUM_PROFILE_AVATAR_METRICS
116 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) {
117 ProfileCounts counts;
118 if (CountProfileInformation(manager, &counts)) {
119 int limited_total = counts.total;
120 int limited_signedin = counts.signedin;
121 if (limited_total > kMaximumReportedProfileCount) {
122 limited_total = kMaximumReportedProfileCount + 1;
123 limited_signedin =
124 (int)((float)(counts.signedin * limited_total)
125 / counts.total + 0.5);
127 UpdateReportedOSProfileStatistics(limited_total, limited_signedin);
131 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) {
132 ProfileCounts counts;
133 bool success = CountProfileInformation(manager, &counts);
134 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total);
136 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests.
137 if (success) {
138 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles",
139 counts.managed);
140 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles",
141 100 * counts.managed / counts.total);
142 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfiles",
143 counts.signedin);
144 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfUnusedProfiles",
145 counts.unused);
147 UpdateReportedOSProfileStatistics(counts.total, counts.signedin);
151 void ProfileMetrics::LogProfileAddNewUser(ProfileAdd metric) {
152 DCHECK(metric < NUM_PROFILE_ADD_METRICS);
153 UMA_HISTOGRAM_ENUMERATION("Profile.AddNewUser", metric,
154 NUM_PROFILE_ADD_METRICS);
155 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", ADD_NEW_USER,
156 NUM_PROFILE_NET_METRICS);
159 void ProfileMetrics::LogProfileAvatarSelection(size_t icon_index) {
160 DCHECK(icon_index < NUM_PROFILE_AVATAR_METRICS);
161 ProfileAvatar icon_name = AVATAR_UNKNOWN;
162 switch (icon_index) {
163 case 0:
164 icon_name = AVATAR_GENERIC;
165 break;
166 case 1:
167 icon_name = AVATAR_GENERIC_AQUA;
168 break;
169 case 2:
170 icon_name = AVATAR_GENERIC_BLUE;
171 break;
172 case 3:
173 icon_name = AVATAR_GENERIC_GREEN;
174 break;
175 case 4:
176 icon_name = AVATAR_GENERIC_ORANGE;
177 break;
178 case 5:
179 icon_name = AVATAR_GENERIC_PURPLE;
180 break;
181 case 6:
182 icon_name = AVATAR_GENERIC_RED;
183 break;
184 case 7:
185 icon_name = AVATAR_GENERIC_YELLOW;
186 break;
187 case 8:
188 icon_name = AVATAR_SECRET_AGENT;
189 break;
190 case 9:
191 icon_name = AVATAR_SUPERHERO;
192 break;
193 case 10:
194 icon_name = AVATAR_VOLLEYBALL;
195 break;
196 case 11:
197 icon_name = AVATAR_BUSINESSMAN;
198 break;
199 case 12:
200 icon_name = AVATAR_NINJA;
201 break;
202 case 13:
203 icon_name = AVATAR_ALIEN;
204 break;
205 case 14:
206 icon_name = AVATAR_AWESOME;
207 break;
208 case 15:
209 icon_name = AVATAR_FLOWER;
210 break;
211 case 16:
212 icon_name = AVATAR_PIZZA;
213 break;
214 case 17:
215 icon_name = AVATAR_SOCCER;
216 break;
217 case 18:
218 icon_name = AVATAR_BURGER;
219 break;
220 case 19:
221 icon_name = AVATAR_CAT;
222 break;
223 case 20:
224 icon_name = AVATAR_CUPCAKE;
225 break;
226 case 21:
227 icon_name = AVATAR_DOG;
228 break;
229 case 22:
230 icon_name = AVATAR_HORSE;
231 break;
232 case 23:
233 icon_name = AVATAR_MARGARITA;
234 break;
235 case 24:
236 icon_name = AVATAR_NOTE;
237 break;
238 case 25:
239 icon_name = AVATAR_SUN_CLOUD;
240 break;
241 case 26:
242 icon_name = AVATAR_PLACEHOLDER;
243 break;
244 case 28:
245 icon_name = AVATAR_GAIA;
246 break;
247 default: // We should never actually get here.
248 NOTREACHED();
249 break;
251 UMA_HISTOGRAM_ENUMERATION("Profile.Avatar", icon_name,
252 NUM_PROFILE_AVATAR_METRICS);
255 void ProfileMetrics::LogProfileDeleteUser(ProfileNetUserCounts metric) {
256 DCHECK(metric < NUM_PROFILE_NET_METRICS);
257 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", metric,
258 NUM_PROFILE_NET_METRICS);
261 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) {
262 DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
263 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric,
264 NUM_PROFILE_OPEN_METRICS);
267 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) {
268 if (metric == GAIA_OPT_IN)
269 LogProfileAvatarSelection(AVATAR_GAIA);
270 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings",
271 metric,
272 NUM_PROFILE_GAIA_METRICS);
275 void ProfileMetrics::LogProfileSwitchUser(ProfileOpen metric) {
276 DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
277 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric,
278 NUM_PROFILE_OPEN_METRICS);
281 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) {
282 DCHECK(metric < NUM_PROFILE_SYNC_METRICS);
283 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric,
284 NUM_PROFILE_SYNC_METRICS);
287 void ProfileMetrics::LogProfileAuthResult(ProfileAuth metric) {
288 UMA_HISTOGRAM_ENUMERATION("Profile.AuthResult", metric,
289 NUM_PROFILE_AUTH_METRICS);
292 void ProfileMetrics::LogProfileUpgradeEnrollment(
293 ProfileUpgradeEnrollment metric) {
294 UMA_HISTOGRAM_ENUMERATION("Profile.UpgradeEnrollment", metric,
295 NUM_PROFILE_ENROLLMENT_METRICS);
298 void ProfileMetrics::LogProfileLaunch(Profile* profile) {
299 base::FilePath profile_path = profile->GetPath();
300 UMA_HISTOGRAM_ENUMERATION("Profile.LaunchBrowser",
301 GetProfileType(profile_path),
302 NUM_PROFILE_TYPE_METRICS);
304 if (profile->IsManaged()) {
305 content::RecordAction(
306 base::UserMetricsAction("ManagedMode_NewManagedUserWindow"));
310 void ProfileMetrics::LogProfileSyncSignIn(const base::FilePath& profile_path) {
311 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn",
312 GetProfileType(profile_path),
313 NUM_PROFILE_TYPE_METRICS);
316 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) {
317 UMA_HISTOGRAM_ENUMERATION("Profile.Update",
318 GetProfileType(profile_path),
319 NUM_PROFILE_TYPE_METRICS);