Home | History | Annotate | Download | only in profiles
      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.
      4 
      5 #include "chrome/browser/profiles/profile_metrics.h"
      6 
      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"
     17 
     18 namespace {
     19 
     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.
     27   if (manager) {
     28     user_data_dir = manager->user_data_dir();
     29   }
     30   if (profile_path == user_data_dir.AppendASCII(chrome::kInitialProfile)) {
     31     metric = ProfileMetrics::ORIGINAL;
     32   }
     33   return metric;
     34 }
     35 
     36 }  // namespace
     37 
     38 enum ProfileAvatar {
     39   AVATAR_GENERIC = 0,       // The names for avatar icons
     40   AVATAR_GENERIC_AQUA,
     41   AVATAR_GENERIC_BLUE,
     42   AVATAR_GENERIC_GREEN,
     43   AVATAR_GENERIC_ORANGE,
     44   AVATAR_GENERIC_PURPLE,
     45   AVATAR_GENERIC_RED,
     46   AVATAR_GENERIC_YELLOW,
     47   AVATAR_SECRET_AGENT,
     48   AVATAR_SUPERHERO,
     49   AVATAR_VOLLEYBALL,        // 10
     50   AVATAR_BUSINESSMAN,
     51   AVATAR_NINJA,
     52   AVATAR_ALIEN,
     53   AVATAR_AWESOME,
     54   AVATAR_FLOWER,
     55   AVATAR_PIZZA,
     56   AVATAR_SOCCER,
     57   AVATAR_BURGER,
     58   AVATAR_CAT,
     59   AVATAR_CUPCAKE,           // 20
     60   AVATAR_DOG,
     61   AVATAR_HORSE,
     62   AVATAR_MARGARITA,
     63   AVATAR_NOTE,
     64   AVATAR_SUN_CLOUD,
     65   AVATAR_UNKNOWN,           // 26
     66   AVATAR_GAIA,              // 27
     67   NUM_PROFILE_AVATAR_METRICS
     68 };
     69 
     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",
     74                             number_of_profiles);
     75 
     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;
     85     }
     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);
     92   }
     93 }
     94 
     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);
    101 }
    102 
    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) {
    107     case 0:
    108       icon_name = AVATAR_GENERIC;
    109       break;
    110     case 1:
    111       icon_name = AVATAR_GENERIC_AQUA;
    112       break;
    113     case 2:
    114       icon_name = AVATAR_GENERIC_BLUE;
    115       break;
    116     case 3:
    117       icon_name = AVATAR_GENERIC_GREEN;
    118       break;
    119     case 4:
    120       icon_name = AVATAR_GENERIC_ORANGE;
    121       break;
    122     case 5:
    123       icon_name = AVATAR_GENERIC_PURPLE;
    124       break;
    125     case 6:
    126       icon_name = AVATAR_GENERIC_RED;
    127       break;
    128     case 7:
    129       icon_name = AVATAR_GENERIC_YELLOW;
    130       break;
    131     case 8:
    132       icon_name = AVATAR_SECRET_AGENT;
    133       break;
    134     case 9:
    135       icon_name = AVATAR_SUPERHERO;
    136       break;
    137     case 10:
    138       icon_name = AVATAR_VOLLEYBALL;
    139       break;
    140     case 11:
    141       icon_name = AVATAR_BUSINESSMAN;
    142       break;
    143     case 12:
    144       icon_name = AVATAR_NINJA;
    145       break;
    146     case 13:
    147       icon_name = AVATAR_ALIEN;
    148       break;
    149     case 14:
    150       icon_name = AVATAR_AWESOME;
    151       break;
    152     case 15:
    153       icon_name = AVATAR_FLOWER;
    154       break;
    155     case 16:
    156       icon_name = AVATAR_PIZZA;
    157       break;
    158     case 17:
    159       icon_name = AVATAR_SOCCER;
    160       break;
    161     case 18:
    162       icon_name = AVATAR_BURGER;
    163       break;
    164     case 19:
    165       icon_name = AVATAR_CAT;
    166       break;
    167     case 20:
    168       icon_name = AVATAR_CUPCAKE;
    169       break;
    170     case 21:
    171       icon_name = AVATAR_DOG;
    172       break;
    173     case 22:
    174       icon_name = AVATAR_HORSE;
    175       break;
    176     case 23:
    177       icon_name = AVATAR_MARGARITA;
    178       break;
    179     case 24:
    180       icon_name = AVATAR_NOTE;
    181       break;
    182     case 25:
    183       icon_name = AVATAR_SUN_CLOUD;
    184       break;
    185     case 27:
    186       icon_name = AVATAR_GAIA;
    187       break;
    188     default:  // We should never actually get here.
    189       NOTREACHED();
    190       break;
    191   }
    192   UMA_HISTOGRAM_ENUMERATION("Profile.Avatar", icon_name,
    193                             NUM_PROFILE_AVATAR_METRICS);
    194 }
    195 
    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);
    200 }
    201 
    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);
    206 }
    207 
    208 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) {
    209   if (metric == GAIA_OPT_IN)
    210     LogProfileAvatarSelection(AVATAR_GAIA);
    211   UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings",
    212                             metric,
    213                             NUM_PROFILE_GAIA_METRICS);
    214 }
    215 
    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);
    220 }
    221 
    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);
    226 }
    227 
    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);
    233 
    234   if (profile->IsManaged()) {
    235     content::RecordAction(
    236         content::UserMetricsAction("ManagedMode_NewManagedUserWindow"));
    237   }
    238 }
    239 
    240 void ProfileMetrics::LogProfileSyncSignIn(const base::FilePath& profile_path) {
    241   UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn",
    242                             GetProfileType(profile_path),
    243                             NUM_PROFILE_TYPE_METRICS);
    244 }
    245 
    246 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) {
    247   UMA_HISTOGRAM_ENUMERATION("Profile.Update",
    248                             GetProfileType(profile_path),
    249                             NUM_PROFILE_TYPE_METRICS);
    250 }
    251