Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #include "components/signin/core/browser/signin_metrics.h"
      6 
      7 #include "base/logging.h"
      8 #include "base/metrics/histogram.h"
      9 #include "base/metrics/user_metrics.h"
     10 
     11 namespace signin_metrics {
     12 
     13 // Helper method to determine which |DifferentPrimaryAccounts| applies.
     14 DifferentPrimaryAccounts ComparePrimaryAccounts(bool primary_accounts_same,
     15                                                 int pre_count_gaia_cookies) {
     16   if (primary_accounts_same)
     17     return ACCOUNTS_SAME;
     18   if (pre_count_gaia_cookies == 0)
     19     return NO_COOKIE_PRESENT;
     20   return COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT;
     21 }
     22 
     23 void LogSigninAccountReconciliation(int total_number_accounts,
     24                                     int count_added_to_cookie_jar,
     25                                     int count_removed_from_cookie_jar,
     26                                     bool primary_accounts_same,
     27                                     bool is_first_reconcile,
     28                                     int pre_count_gaia_cookies) {
     29   UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfAccountsPerProfile",
     30                            total_number_accounts);
     31   // We want to include zeroes in the counts of added or removed accounts to
     32   // easily capture _relatively_ how often we merge accounts.
     33   if (is_first_reconcile) {
     34     UMA_HISTOGRAM_COUNTS_100("Signin.Reconciler.AddedToCookieJar.FirstRun",
     35                              count_added_to_cookie_jar);
     36     UMA_HISTOGRAM_COUNTS_100("Signin.Reconciler.RemovedFromCookieJar.FirstRun",
     37                              count_removed_from_cookie_jar);
     38     UMA_HISTOGRAM_ENUMERATION(
     39         "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
     40         ComparePrimaryAccounts(primary_accounts_same, pre_count_gaia_cookies),
     41         NUM_DIFFERENT_PRIMARY_ACCOUNT_METRICS);
     42   } else {
     43     UMA_HISTOGRAM_COUNTS_100("Signin.Reconciler.AddedToCookieJar.SubsequentRun",
     44                              count_added_to_cookie_jar);
     45     UMA_HISTOGRAM_COUNTS_100(
     46         "Signin.Reconciler.RemovedFromCookieJar.SubsequentRun",
     47         count_removed_from_cookie_jar);
     48     UMA_HISTOGRAM_ENUMERATION(
     49         "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun",
     50         ComparePrimaryAccounts(primary_accounts_same, pre_count_gaia_cookies),
     51         NUM_DIFFERENT_PRIMARY_ACCOUNT_METRICS);
     52   }
     53 }
     54 
     55 void LogSigninProfile(bool is_first_run, base::Time install_date) {
     56   // Track whether or not the user signed in during the first run of Chrome.
     57   UMA_HISTOGRAM_BOOLEAN("Signin.DuringFirstRun", is_first_run);
     58 
     59   // Determine how much time passed since install when this profile was signed
     60   // in.
     61   base::TimeDelta elapsed_time = base::Time::Now() - install_date;
     62   UMA_HISTOGRAM_COUNTS("Signin.ElapsedTimeFromInstallToSignin",
     63                        elapsed_time.InMinutes());
     64 }
     65 
     66 void LogSigninAddAccount() {
     67   // Account signin may fail for a wide variety of reasons. There is no
     68   // explicit false, but one can compare this value with the various UI
     69   // flows that lead to account sign-in, and deduce that the difference
     70   // counts the failures.
     71   UMA_HISTOGRAM_BOOLEAN("Signin.AddAccount", true);
     72 }
     73 
     74 void LogSignout(ProfileSignout metric) {
     75   UMA_HISTOGRAM_ENUMERATION("Signin.SignoutProfile", metric,
     76                             NUM_PROFILE_SIGNOUT_METRICS);
     77 }
     78 
     79 void LogExternalCcResultFetches(bool fetches_completed) {
     80   UMA_HISTOGRAM_BOOLEAN("Signin.Reconciler.AllExternalCcResultCompleted",
     81                         fetches_completed);
     82 }
     83 
     84 }  // namespace signin_metrics
     85