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