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 "content/public/browser/browser_thread.h"
16 #include "content/public/browser/user_metrics.h"
20 ProfileMetrics::ProfileType GetProfileType(
21 const base::FilePath& profile_path) {
22 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
23 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY;
24 ProfileManager* manager = g_browser_process->profile_manager();
25 base::FilePath user_data_dir;
26 // In unittests, we do not always have a profile_manager so check.
28 user_data_dir = manager->user_data_dir();
30 if (profile_path == user_data_dir.AppendASCII(chrome::kInitialProfile)) {
31 metric = ProfileMetrics::ORIGINAL;
39 AVATAR_GENERIC = 0, // The names for avatar icons
43 AVATAR_GENERIC_ORANGE,
44 AVATAR_GENERIC_PURPLE,
46 AVATAR_GENERIC_YELLOW,
49 AVATAR_VOLLEYBALL, // 10
67 NUM_PROFILE_AVATAR_METRICS
70 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) {
71 const ProfileInfoCache& info_cache = manager->GetProfileInfoCache();
72 size_t number_of_profiles = info_cache.GetNumberOfProfiles();
73 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles",
76 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests.
77 if (number_of_profiles) {
78 size_t number_of_managed_profiles = 0;
79 size_t number_of_signed_in_profiles = 0;
80 for (size_t i = 0; i < number_of_profiles; ++i) {
81 if (info_cache.ProfileIsManagedAtIndex(i))
82 ++number_of_managed_profiles;
83 if (!info_cache.GetUserNameOfProfileAtIndex(i).empty())
84 ++number_of_signed_in_profiles;
86 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles",
87 number_of_managed_profiles);
88 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles",
89 100 * number_of_managed_profiles / number_of_profiles);
90 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfiles",
91 number_of_signed_in_profiles);
95 void ProfileMetrics::LogProfileAddNewUser(ProfileAdd metric) {
96 DCHECK(metric < NUM_PROFILE_ADD_METRICS);
97 UMA_HISTOGRAM_ENUMERATION("Profile.AddNewUser", metric,
98 NUM_PROFILE_ADD_METRICS);
99 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", ADD_NEW_USER,
100 NUM_PROFILE_NET_METRICS);
103 void ProfileMetrics::LogProfileAvatarSelection(size_t icon_index) {
104 DCHECK(icon_index < NUM_PROFILE_AVATAR_METRICS);
105 ProfileAvatar icon_name = AVATAR_UNKNOWN;
106 switch (icon_index) {
108 icon_name = AVATAR_GENERIC;
111 icon_name = AVATAR_GENERIC_AQUA;
114 icon_name = AVATAR_GENERIC_BLUE;
117 icon_name = AVATAR_GENERIC_GREEN;
120 icon_name = AVATAR_GENERIC_ORANGE;
123 icon_name = AVATAR_GENERIC_PURPLE;
126 icon_name = AVATAR_GENERIC_RED;
129 icon_name = AVATAR_GENERIC_YELLOW;
132 icon_name = AVATAR_SECRET_AGENT;
135 icon_name = AVATAR_SUPERHERO;
138 icon_name = AVATAR_VOLLEYBALL;
141 icon_name = AVATAR_BUSINESSMAN;
144 icon_name = AVATAR_NINJA;
147 icon_name = AVATAR_ALIEN;
150 icon_name = AVATAR_AWESOME;
153 icon_name = AVATAR_FLOWER;
156 icon_name = AVATAR_PIZZA;
159 icon_name = AVATAR_SOCCER;
162 icon_name = AVATAR_BURGER;
165 icon_name = AVATAR_CAT;
168 icon_name = AVATAR_CUPCAKE;
171 icon_name = AVATAR_DOG;
174 icon_name = AVATAR_HORSE;
177 icon_name = AVATAR_MARGARITA;
180 icon_name = AVATAR_NOTE;
183 icon_name = AVATAR_SUN_CLOUD;
186 icon_name = AVATAR_GAIA;
188 default: // We should never actually get here.
192 UMA_HISTOGRAM_ENUMERATION("Profile.Avatar", icon_name,
193 NUM_PROFILE_AVATAR_METRICS);
196 void ProfileMetrics::LogProfileDeleteUser(ProfileNetUserCounts metric) {
197 DCHECK(metric < NUM_PROFILE_NET_METRICS);
198 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", metric,
199 NUM_PROFILE_NET_METRICS);
202 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) {
203 DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
204 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric,
205 NUM_PROFILE_OPEN_METRICS);
208 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) {
209 if (metric == GAIA_OPT_IN)
210 LogProfileAvatarSelection(AVATAR_GAIA);
211 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings",
213 NUM_PROFILE_GAIA_METRICS);
216 void ProfileMetrics::LogProfileSwitchUser(ProfileOpen metric) {
217 DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
218 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric,
219 NUM_PROFILE_OPEN_METRICS);
222 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) {
223 DCHECK(metric < NUM_PROFILE_SYNC_METRICS);
224 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric,
225 NUM_PROFILE_SYNC_METRICS);
228 void ProfileMetrics::LogProfileLaunch(Profile* profile) {
229 base::FilePath profile_path = profile->GetPath();
230 UMA_HISTOGRAM_ENUMERATION("Profile.LaunchBrowser",
231 GetProfileType(profile_path),
232 NUM_PROFILE_TYPE_METRICS);
234 if (profile->IsManaged()) {
235 content::RecordAction(
236 content::UserMetricsAction("ManagedMode_NewManagedUserWindow"));
240 void ProfileMetrics::LogProfileSyncSignIn(const base::FilePath& profile_path) {
241 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn",
242 GetProfileType(profile_path),
243 NUM_PROFILE_TYPE_METRICS);
246 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) {
247 UMA_HISTOGRAM_ENUMERATION("Profile.Update",
248 GetProfileType(profile_path),
249 NUM_PROFILE_TYPE_METRICS);