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"
21 const int kMaximumReportedProfileCount
= 5;
23 struct ProfileCounts
{
28 ProfileCounts() : total(0), signedin(0), managed(0) {}
31 ProfileMetrics::ProfileType
GetProfileType(
32 const base::FilePath
& profile_path
) {
33 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
34 ProfileMetrics::ProfileType metric
= ProfileMetrics::SECONDARY
;
35 ProfileManager
* manager
= g_browser_process
->profile_manager();
36 base::FilePath user_data_dir
;
37 // In unittests, we do not always have a profile_manager so check.
39 user_data_dir
= manager
->user_data_dir();
41 if (profile_path
== user_data_dir
.AppendASCII(chrome::kInitialProfile
)) {
42 metric
= ProfileMetrics::ORIGINAL
;
47 void UpdateReportedOSProfileStatistics(int active
, int signedin
) {
49 GoogleUpdateSettings::UpdateProfileCounts(active
, signedin
);
53 bool CountProfileInformation(ProfileManager
* manager
, ProfileCounts
* counts
) {
54 const ProfileInfoCache
& info_cache
= manager
->GetProfileInfoCache();
55 size_t number_of_profiles
= info_cache
.GetNumberOfProfiles();
56 counts
->total
= number_of_profiles
;
58 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests.
59 if (!number_of_profiles
)
62 for (size_t i
= 0; i
< number_of_profiles
; ++i
) {
63 if (info_cache
.ProfileIsManagedAtIndex(i
))
65 if (!info_cache
.GetUserNameOfProfileAtIndex(i
).empty())
74 AVATAR_GENERIC
= 0, // The names for avatar icons
78 AVATAR_GENERIC_ORANGE
,
79 AVATAR_GENERIC_PURPLE
,
81 AVATAR_GENERIC_YELLOW
,
84 AVATAR_VOLLEYBALL
, // 10
100 AVATAR_UNKNOWN
, // 26
102 NUM_PROFILE_AVATAR_METRICS
105 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager
* manager
) {
106 ProfileCounts counts
;
107 if (CountProfileInformation(manager
, &counts
)) {
108 int limited_total
= counts
.total
;
109 int limited_signedin
= counts
.signedin
;
110 if (limited_total
> kMaximumReportedProfileCount
) {
111 limited_total
= kMaximumReportedProfileCount
+ 1;
113 (int)((float)(counts
.signedin
* limited_total
)
114 / counts
.total
+ 0.5);
116 UpdateReportedOSProfileStatistics(limited_total
, limited_signedin
);
120 void ProfileMetrics::LogNumberOfProfiles(ProfileManager
* manager
) {
121 ProfileCounts counts
;
122 bool success
= CountProfileInformation(manager
, &counts
);
123 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts
.total
);
125 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests.
127 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles",
129 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles",
130 100 * counts
.managed
/ counts
.total
);
131 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfiles",
134 UpdateReportedOSProfileStatistics(counts
.total
, counts
.signedin
);
138 void ProfileMetrics::LogProfileAddNewUser(ProfileAdd metric
) {
139 DCHECK(metric
< NUM_PROFILE_ADD_METRICS
);
140 UMA_HISTOGRAM_ENUMERATION("Profile.AddNewUser", metric
,
141 NUM_PROFILE_ADD_METRICS
);
142 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", ADD_NEW_USER
,
143 NUM_PROFILE_NET_METRICS
);
146 void ProfileMetrics::LogProfileAvatarSelection(size_t icon_index
) {
147 DCHECK(icon_index
< NUM_PROFILE_AVATAR_METRICS
);
148 ProfileAvatar icon_name
= AVATAR_UNKNOWN
;
149 switch (icon_index
) {
151 icon_name
= AVATAR_GENERIC
;
154 icon_name
= AVATAR_GENERIC_AQUA
;
157 icon_name
= AVATAR_GENERIC_BLUE
;
160 icon_name
= AVATAR_GENERIC_GREEN
;
163 icon_name
= AVATAR_GENERIC_ORANGE
;
166 icon_name
= AVATAR_GENERIC_PURPLE
;
169 icon_name
= AVATAR_GENERIC_RED
;
172 icon_name
= AVATAR_GENERIC_YELLOW
;
175 icon_name
= AVATAR_SECRET_AGENT
;
178 icon_name
= AVATAR_SUPERHERO
;
181 icon_name
= AVATAR_VOLLEYBALL
;
184 icon_name
= AVATAR_BUSINESSMAN
;
187 icon_name
= AVATAR_NINJA
;
190 icon_name
= AVATAR_ALIEN
;
193 icon_name
= AVATAR_AWESOME
;
196 icon_name
= AVATAR_FLOWER
;
199 icon_name
= AVATAR_PIZZA
;
202 icon_name
= AVATAR_SOCCER
;
205 icon_name
= AVATAR_BURGER
;
208 icon_name
= AVATAR_CAT
;
211 icon_name
= AVATAR_CUPCAKE
;
214 icon_name
= AVATAR_DOG
;
217 icon_name
= AVATAR_HORSE
;
220 icon_name
= AVATAR_MARGARITA
;
223 icon_name
= AVATAR_NOTE
;
226 icon_name
= AVATAR_SUN_CLOUD
;
229 icon_name
= AVATAR_GAIA
;
231 default: // We should never actually get here.
235 UMA_HISTOGRAM_ENUMERATION("Profile.Avatar", icon_name
,
236 NUM_PROFILE_AVATAR_METRICS
);
239 void ProfileMetrics::LogProfileDeleteUser(ProfileNetUserCounts metric
) {
240 DCHECK(metric
< NUM_PROFILE_NET_METRICS
);
241 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", metric
,
242 NUM_PROFILE_NET_METRICS
);
245 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric
) {
246 DCHECK(metric
< NUM_PROFILE_OPEN_METRICS
);
247 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric
,
248 NUM_PROFILE_OPEN_METRICS
);
251 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric
) {
252 if (metric
== GAIA_OPT_IN
)
253 LogProfileAvatarSelection(AVATAR_GAIA
);
254 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings",
256 NUM_PROFILE_GAIA_METRICS
);
259 void ProfileMetrics::LogProfileSwitchUser(ProfileOpen metric
) {
260 DCHECK(metric
< NUM_PROFILE_OPEN_METRICS
);
261 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric
,
262 NUM_PROFILE_OPEN_METRICS
);
265 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric
) {
266 DCHECK(metric
< NUM_PROFILE_SYNC_METRICS
);
267 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric
,
268 NUM_PROFILE_SYNC_METRICS
);
271 void ProfileMetrics::LogProfileLaunch(Profile
* profile
) {
272 base::FilePath profile_path
= profile
->GetPath();
273 UMA_HISTOGRAM_ENUMERATION("Profile.LaunchBrowser",
274 GetProfileType(profile_path
),
275 NUM_PROFILE_TYPE_METRICS
);
277 if (profile
->IsManaged()) {
278 content::RecordAction(
279 base::UserMetricsAction("ManagedMode_NewManagedUserWindow"));
283 void ProfileMetrics::LogProfileSyncSignIn(const base::FilePath
& profile_path
) {
284 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn",
285 GetProfileType(profile_path
),
286 NUM_PROFILE_TYPE_METRICS
);
289 void ProfileMetrics::LogProfileUpdate(const base::FilePath
& profile_path
) {
290 UMA_HISTOGRAM_ENUMERATION("Profile.Update",
291 GetProfileType(profile_path
),
292 NUM_PROFILE_TYPE_METRICS
);