Commit 34f3304e authored by anthonyvd's avatar anthonyvd Committed by Commit bot

Add UMA metrics for profile switching.

This changes adds four histograms to UMA. Profile.NumberofSwitches
collects the number of profile switches happening over a session.

The others are:

- Profile.ProfileSwitch.ToOpenedProfile counts the number of switches to
  opened profiles and buckets depending on the UI flow used to switch.
- Profile.ProfileSwitch.ToUnopenedProfile does the same but for switches
  to unopened profiles
- Profile.ProfileSwitch aggregates the data from the previous two

BUG=448982

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

Cr-Commit-Position: refs/heads/master@{#313951}
parent 67bf7866
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/crash_keys.h" #include "chrome/common/crash_keys.h"
...@@ -153,6 +154,9 @@ bool ShutdownPreThreadsStop() { ...@@ -153,6 +154,9 @@ bool ShutdownPreThreadsStop() {
// consider putting it in BrowserProcessImpl::EndSession. // consider putting it in BrowserProcessImpl::EndSession.
PrefService* prefs = g_browser_process->local_state(); PrefService* prefs = g_browser_process->local_state();
// Log the amount of times the user switched profiles during this session.
ProfileMetrics::LogNumberOfProfileSwitches();
metrics::MetricsService* metrics = g_browser_process->metrics_service(); metrics::MetricsService* metrics = g_browser_process->metrics_service();
if (metrics) if (metrics)
metrics->RecordCompletedSessionEnd(); metrics->RecordCompletedSessionEnd();
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_header_helper.h" #include "chrome/browser/signin/signin_header_helper.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/google_update_settings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -22,6 +23,34 @@ namespace { ...@@ -22,6 +23,34 @@ namespace {
const int kMaximumReportedProfileCount = 5; const int kMaximumReportedProfileCount = 5;
const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks. const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks.
size_t number_of_profile_switches_ = 0;
// Enum for tracking the state of profiles being switched to.
enum ProfileOpenState {
// Profile being switched to is already opened and has browsers opened.
PROFILE_OPENED = 0,
// Profile being switched to is already opened but has no browsers opened.
PROFILE_OPENED_NO_BROWSER,
// Profile being switched to is not opened.
PROFILE_UNOPENED
};
ProfileOpenState GetProfileOpenState(
ProfileManager* manager,
const base::FilePath& path) {
Profile* profile_switched_to = manager->GetProfileByPath(path);
if (!profile_switched_to) {
return PROFILE_UNOPENED;
}
if (chrome::GetTotalBrowserCountForProfile(profile_switched_to) > 0) {
return PROFILE_OPENED;
}
return PROFILE_OPENED_NO_BROWSER;
}
ProfileMetrics::ProfileType GetProfileType( ProfileMetrics::ProfileType GetProfileType(
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
...@@ -147,7 +176,6 @@ bool ProfileMetrics::CountProfileInformation(ProfileManager* manager, ...@@ -147,7 +176,6 @@ bool ProfileMetrics::CountProfileInformation(ProfileManager* manager,
return true; return true;
} }
void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) {
ProfileCounts counts; ProfileCounts counts;
if (CountProfileInformation(manager, &counts)) { if (CountProfileInformation(manager, &counts)) {
...@@ -163,6 +191,11 @@ void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { ...@@ -163,6 +191,11 @@ void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) {
} }
} }
void ProfileMetrics::LogNumberOfProfileSwitches() {
UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSwitches",
number_of_profile_switches_);
}
void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) {
ProfileCounts counts; ProfileCounts counts;
bool success = CountProfileInformation(manager, &counts); bool success = CountProfileInformation(manager, &counts);
...@@ -306,6 +339,43 @@ void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { ...@@ -306,6 +339,43 @@ void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) {
NUM_PROFILE_OPEN_METRICS); NUM_PROFILE_OPEN_METRICS);
} }
void ProfileMetrics::LogProfileSwitch(
ProfileOpen metric,
ProfileManager* manager,
const base::FilePath& profile_path) {
DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
ProfileOpenState open_state = GetProfileOpenState(manager, profile_path);
switch (open_state) {
case PROFILE_OPENED:
UMA_HISTOGRAM_ENUMERATION(
"Profile.OpenMethod.ToOpenedProfile",
metric,
NUM_PROFILE_OPEN_METRICS);
break;
case PROFILE_OPENED_NO_BROWSER:
UMA_HISTOGRAM_ENUMERATION(
"Profile.OpenMethod.ToOpenedProfileWithoutBrowser",
metric,
NUM_PROFILE_OPEN_METRICS);
break;
case PROFILE_UNOPENED:
UMA_HISTOGRAM_ENUMERATION(
"Profile.OpenMethod.ToUnopenedProfile",
metric,
NUM_PROFILE_OPEN_METRICS);
break;
default:
// There are no other possible values.
NOTREACHED();
break;
}
++number_of_profile_switches_;
// The LogOpenMethod histogram aggregates data from profile switches as well
// as opening of profile related UI elements.
LogProfileOpenMethod(metric);
}
void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) {
if (metric == GAIA_OPT_IN) if (metric == GAIA_OPT_IN)
LogProfileAvatarSelection(AVATAR_GAIA); LogProfileAvatarSelection(AVATAR_GAIA);
...@@ -314,12 +384,6 @@ void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { ...@@ -314,12 +384,6 @@ void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) {
NUM_PROFILE_GAIA_METRICS); NUM_PROFILE_GAIA_METRICS);
} }
void ProfileMetrics::LogProfileSwitchUser(ProfileOpen metric) {
DCHECK(metric < NUM_PROFILE_OPEN_METRICS);
UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric,
NUM_PROFILE_OPEN_METRICS);
}
void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) {
DCHECK(metric < NUM_PROFILE_SYNC_METRICS); DCHECK(metric < NUM_PROFILE_SYNC_METRICS);
UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric, UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric,
......
...@@ -207,13 +207,16 @@ class ProfileMetrics { ...@@ -207,13 +207,16 @@ class ProfileMetrics {
static bool CountProfileInformation(ProfileManager* manager, static bool CountProfileInformation(ProfileManager* manager,
ProfileCounts* counts); ProfileCounts* counts);
static void LogNumberOfProfileSwitches();
static void LogNumberOfProfiles(ProfileManager* manager); static void LogNumberOfProfiles(ProfileManager* manager);
static void LogProfileAddNewUser(ProfileAdd metric); static void LogProfileAddNewUser(ProfileAdd metric);
static void LogProfileAvatarSelection(size_t icon_index); static void LogProfileAvatarSelection(size_t icon_index);
static void LogProfileDeleteUser(ProfileDelete metric); static void LogProfileDeleteUser(ProfileDelete metric);
static void LogProfileOpenMethod(ProfileOpen metric); static void LogProfileOpenMethod(ProfileOpen metric);
static void LogProfileSwitch(ProfileOpen metric,
ProfileManager* manager,
const base::FilePath& profile_path);
static void LogProfileSwitchGaia(ProfileGaia metric); static void LogProfileSwitchGaia(ProfileGaia metric);
static void LogProfileSwitchUser(ProfileOpen metric);
static void LogProfileSyncInfo(ProfileSync metric); static void LogProfileSyncInfo(ProfileSync metric);
static void LogProfileAuthResult(ProfileAuth metric); static void LogProfileAuthResult(ProfileAuth metric);
static void LogProfileDesktopMenu(ProfileDesktopMenu metric, static void LogProfileDesktopMenu(ProfileDesktopMenu metric,
......
...@@ -274,6 +274,9 @@ void SwitchToProfile(const base::FilePath& path, ...@@ -274,6 +274,9 @@ void SwitchToProfile(const base::FilePath& path,
bool always_create, bool always_create,
ProfileManager::CreateCallback callback, ProfileManager::CreateCallback callback,
ProfileMetrics::ProfileOpen metric) { ProfileMetrics::ProfileOpen metric) {
ProfileMetrics::LogProfileSwitch(metric,
g_browser_process->profile_manager(),
path);
g_browser_process->profile_manager()->CreateProfileAsync( g_browser_process->profile_manager()->CreateProfileAsync(
path, path,
base::Bind(&OpenBrowserWindowForProfile, base::Bind(&OpenBrowserWindowForProfile,
...@@ -284,13 +287,16 @@ void SwitchToProfile(const base::FilePath& path, ...@@ -284,13 +287,16 @@ void SwitchToProfile(const base::FilePath& path,
base::string16(), base::string16(),
base::string16(), base::string16(),
std::string()); std::string());
ProfileMetrics::LogProfileSwitchUser(metric);
} }
void SwitchToGuestProfile(chrome::HostDesktopType desktop_type, void SwitchToGuestProfile(chrome::HostDesktopType desktop_type,
ProfileManager::CreateCallback callback) { ProfileManager::CreateCallback callback) {
const base::FilePath& path = ProfileManager::GetGuestProfilePath();
ProfileMetrics::LogProfileSwitch(ProfileMetrics::SWITCH_PROFILE_GUEST,
g_browser_process->profile_manager(),
path);
g_browser_process->profile_manager()->CreateProfileAsync( g_browser_process->profile_manager()->CreateProfileAsync(
ProfileManager::GetGuestProfilePath(), path,
base::Bind(&OpenBrowserWindowForProfile, base::Bind(&OpenBrowserWindowForProfile,
callback, callback,
false, false,
...@@ -299,7 +305,6 @@ void SwitchToGuestProfile(chrome::HostDesktopType desktop_type, ...@@ -299,7 +305,6 @@ void SwitchToGuestProfile(chrome::HostDesktopType desktop_type,
base::string16(), base::string16(),
base::string16(), base::string16(),
std::string()); std::string());
ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
} }
void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type, void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type,
......
...@@ -190,7 +190,7 @@ void UserManager::Show( ...@@ -190,7 +190,7 @@ void UserManager::Show(
profiles::UserManagerProfileSelected profile_open_action) { profiles::UserManagerProfileSelected profile_open_action) {
DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());
ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
if (instance_) { if (instance_) {
// If there's a user manager window open already, just activate it. // If there's a user manager window open already, just activate it.
[instance_->window_controller() show]; [instance_->window_controller() show];
......
...@@ -50,7 +50,7 @@ void UserManager::Show( ...@@ -50,7 +50,7 @@ void UserManager::Show(
profiles::UserManagerProfileSelected profile_open_action) { profiles::UserManagerProfileSelected profile_open_action) {
DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath()); DCHECK(profile_path_to_focus != ProfileManager::GetGuestProfilePath());
ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_USER_MANAGER); ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::OPEN_USER_MANAGER);
if (instance_) { if (instance_) {
// If we are showing the User Manager after locking a profile, change the // If we are showing the User Manager after locking a profile, change the
// active profile to Guest. // active profile to Guest.
......
...@@ -459,7 +459,6 @@ void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { ...@@ -459,7 +459,6 @@ void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) {
void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
if (IsGuestModeEnabled()) { if (IsGuestModeEnabled()) {
ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
profiles::SwitchToGuestProfile( profiles::SwitchToGuestProfile(
desktop_type_, desktop_type_,
base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete,
......
...@@ -28078,6 +28078,15 @@ Therefore, the affected-histogram name has to have at least one dot in it. ...@@ -28078,6 +28078,15 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary> </summary>
</histogram> </histogram>
<histogram name="Profile.NumberOfSwitches">
<owner>anthonyvd@chromium.org</owner>
<summary>
Counts the number of times profiles were switched in a browser session. This
value is incremented when a profile is switched to and the result is logged
during shutdown.
</summary>
</histogram>
<histogram name="Profile.NumberOfUnusedProfiles"> <histogram name="Profile.NumberOfUnusedProfiles">
<owner>mlerman@chromium.org</owner> <owner>mlerman@chromium.org</owner>
<summary> <summary>
...@@ -62508,6 +62517,19 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -62508,6 +62517,19 @@ To add a new entry, add it with any value and run test to compute valid value.
<affected-histogram name="Profile.DesktopMenu"/> <affected-histogram name="Profile.DesktopMenu"/>
</histogram_suffixes> </histogram_suffixes>
<histogram_suffixes name="ProfileOpenState" separator=".">
<suffix name="ToOpenedProfile"
label="The profile being switched to was already loaded and had at
least one open browser"/>
<suffix name="ToUnopenedProfile"
label="The profile being switched to had not yet been loaded this
Chrome session"/>
<suffix name="ToOpenedProfileWithoutBrowser"
label="The profile being switched to was already opened and had no
active browsers"/>
<affected-histogram name="Profile.OpenMethod"/>
</histogram_suffixes>
<histogram_suffixes name="ProfilePictureDownload" separator="."> <histogram_suffixes name="ProfilePictureDownload" separator=".">
<suffix name="Default.OOBE" label="default picture, in OOBE"/> <suffix name="Default.OOBE" label="default picture, in OOBE"/>
<suffix name="Default.LoggedIn" label="default picture, after login"/> <suffix name="Default.LoggedIn" label="default picture, after login"/>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment