0

Componentize ProfileMetrics::Counts

ProfileMetrics::Counts and related histograms are used by all platforms
including iOS, and it is important that iOS remains consistent with the
other platforms.
This CL componentizes these metrics to be able to share them cleanly on
iOS.

TBR=jochen

Review URL: https://codereview.chromium.org/1417903006

Cr-Commit-Position: refs/heads/master@{#357333}
This commit is contained in:
droger
2015-11-02 03:25:59 -08:00
committed by Commit bot
parent 68141892e6
commit 78da6543bf
12 changed files with 125 additions and 34 deletions

@@ -297,6 +297,7 @@ source_set("browser") {
"//components/password_manager/content/browser",
"//components/password_manager/sync/browser",
"//components/plugins/common",
"//components/profile_metrics",
"//components/proxy_config",
"//components/resources",
"//components/safe_browsing_db",

@@ -76,6 +76,7 @@ include_rules = [
"+components/pref_registry",
"+components/printing/browser",
"+components/printing/common",
"+components/profile_metrics",
"+components/proximity_auth",
"+components/proxy_config",
"+components/query_parser",

@@ -15,6 +15,7 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/installer/util/google_update_settings.h"
#include "components/profile_metrics/counts.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.h"
@@ -143,7 +144,7 @@ enum ProfileAvatar {
};
bool ProfileMetrics::CountProfileInformation(ProfileManager* manager,
ProfileCounts* counts) {
profile_metrics::Counts* counts) {
const ProfileInfoCache& info_cache = manager->GetProfileInfoCache();
size_t number_of_profiles = info_cache.GetNumberOfProfiles();
counts->total = number_of_profiles;
@@ -176,7 +177,7 @@ bool ProfileMetrics::CountProfileInformation(ProfileManager* manager,
void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) {
#if defined(OS_WIN) || defined(OS_MACOSX)
ProfileCounts counts;
profile_metrics::Counts counts;
if (CountProfileInformation(manager, &counts)) {
size_t limited_total = counts.total;
size_t limited_signedin = counts.signedin;
@@ -207,25 +208,13 @@ void ProfileMetrics::UpdateReportedOSProfileStatistics(
#endif
void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) {
ProfileCounts counts;
profile_metrics::Counts counts;
bool success = CountProfileInformation(manager, &counts);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total);
profile_metrics::LogProfileMetricsCounts(counts);
// Ignore other metrics if we have no profiles.
if (success) {
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles",
counts.supervised);
UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles",
100 * counts.supervised / counts.total);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfiles",
counts.signedin);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfUnusedProfiles",
counts.unused);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfilesWithGAIAIcons",
counts.gaia_icon);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfilesWithAuthErrors",
counts.auth_errors);
LogLockedProfileInformation(manager);
#if defined(OS_WIN) || defined(OS_MACOSX)

@@ -19,24 +19,12 @@ namespace base {
class FilePath;
}
namespace profile_metrics {
struct Counts;
}
class ProfileMetrics {
public:
struct ProfileCounts {
size_t total;
size_t signedin;
size_t supervised;
size_t unused;
size_t gaia_icon;
size_t auth_errors;
ProfileCounts()
: total(0),
signedin(0),
supervised(0),
unused(0),
gaia_icon(0),
auth_errors(0) {}
};
// Enum for counting the ways users were added.
enum ProfileAdd {
@@ -213,7 +201,7 @@ class ProfileMetrics {
// Count and return summary information about the profiles currently in the
// |manager|. This information is returned in the output variable |counts|.
static bool CountProfileInformation(ProfileManager* manager,
ProfileCounts* counts);
profile_metrics::Counts* counts);
#if !defined(OS_ANDROID) && !defined(OS_IOS)
static void LogNumberOfProfileSwitches();

@@ -3234,6 +3234,7 @@
'../components/components.gyp:password_manager_sync_browser',
'../components/components.gyp:plugins_common',
'../components/components.gyp:power',
'../components/components.gyp:profile_metrics',
'../components/components.gyp:proxy_config',
'../components/components.gyp:safe_browsing_db',
'../components/components.gyp:safe_json',

@@ -232,6 +232,10 @@ per-file policy*=bartfab@chromium.org
per-file policy*=atwilson@chromium.org
per-file policy*=cschuet@chromium.org
per-file profile_metrics*=anthonyvd@chromium.org
per-file profile_metrics*=erg@chromium.org
per-file profile_metrics*=mlerman@chromium.org
per-file proximity_auth*=isherman@chromium.org
per-file proximity_auth*=tbarzic@chromium.org
per-file proximity_auth*=tengs@chromium.org

@@ -66,6 +66,7 @@
'policy.gypi',
'precache.gypi',
'pref_registry.gypi',
'profile_metrics.gypi',
'proxy_config.gypi',
'query_parser.gypi',
'rappor.gypi',

@@ -0,0 +1,24 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
# GN version: //components/profile_metrics
'target_name': 'profile_metrics',
'type': 'static_library',
'include_dirs': [
'..',
],
'dependencies': [
'../base/base.gyp:base',
],
'sources': [
# Note: sources list duplicated in GN build.
'profile_metrics/counts.cc',
'profile_metrics/counts.h',
],
},
],
}

@@ -0,0 +1,15 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# GYP version: components/profile_metrics.gypi:profile_metrics
static_library("profile_metrics") {
sources = [
"counts.cc",
"counts.h",
]
deps = [
"//base",
]
}

@@ -0,0 +1,3 @@
anthonyvd@chromium.org
erg@chromium.org
mlerman@chromium.org

@@ -0,0 +1,30 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/profile_metrics/counts.h"
#include "base/metrics/histogram.h"
namespace profile_metrics {
void LogProfileMetricsCounts(const Counts& counts) {
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total);
// Ignore other metrics if we have no profiles.
if (counts.total > 0) {
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles",
counts.supervised);
UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles",
100 * counts.supervised / counts.total);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfiles",
counts.signedin);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfUnusedProfiles", counts.unused);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSignedInProfilesWithGAIAIcons",
counts.gaia_icon);
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfilesWithAuthErrors",
counts.auth_errors);
}
}
} // namespace profile_metrics

@@ -0,0 +1,34 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PROFILE_METRICS_COUNTS_H_
#define COMPONENTS_PROFILE_METRICS_COUNTS_H_
#include "base/metrics/histogram_base.h"
namespace profile_metrics {
struct Counts {
base::HistogramBase::Sample total;
base::HistogramBase::Sample signedin;
base::HistogramBase::Sample supervised;
base::HistogramBase::Sample unused;
base::HistogramBase::Sample gaia_icon;
base::HistogramBase::Sample auth_errors;
Counts()
: total(0),
signedin(0),
supervised(0),
unused(0),
gaia_icon(0),
auth_errors(0) {}
};
// Logs metrics related to |counts|.
void LogProfileMetricsCounts(const Counts& counts);
} // namespace profile_metrics
#endif // COMPONENTS_PROFILE_METRICS_COUNTS_H_