Chromium Code Reviews| Index: chrome/browser/metrics/signin_status_metrics_provider.cc |
| diff --git a/chrome/browser/metrics/signin_status_metrics_provider.cc b/chrome/browser/metrics/signin_status_metrics_provider.cc |
| index 70b94a41abbab73a1829f80adf9c567b0b3e8034..6fcd4388bbdfd87f390fc5cde29b4489f6c6daa9 100644 |
| --- a/chrome/browser/metrics/signin_status_metrics_provider.cc |
| +++ b/chrome/browser/metrics/signin_status_metrics_provider.cc |
| @@ -28,7 +28,8 @@ namespace { |
| // occurred during the function execution. |
| enum ComputeSigninStatus { |
| ENTERED_COMPUTE_SIGNIN_STATUS, |
| - ERROR_COMPUTE_SIGNIN_STATUS, |
| + ERROR_NO_PROFILE_FOUND, |
| + NO_BROWSER_OPENED, |
| COMPUTE_SIGNIN_STATUS_MAX, |
| }; |
| @@ -123,14 +124,24 @@ void SigninStatusMetricsProvider::GoogleSigninSucceeded( |
| const std::string& account_id, |
| const std::string& username, |
| const std::string& password) { |
| - if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) |
| + if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) { |
| signin_status_ = MIXED_SIGNIN_STATUS; |
| + } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { |
| + // There should have at least one browser opened if the user can sign in, so |
| + // signin_status_ value should not be unknown. |
| + signin_status_ = ERROR_GETTING_SIGNIN_STATUS; |
| + } |
| } |
| void SigninStatusMetricsProvider::GoogleSignedOut(const std::string& account_id, |
| const std::string& username) { |
| - if (signin_status_ == ALL_PROFILES_SIGNED_IN) |
| + if (signin_status_ == ALL_PROFILES_SIGNED_IN) { |
| signin_status_ = MIXED_SIGNIN_STATUS; |
| + } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { |
| + // There should have at least one browser opened if the user can sign out, |
| + // so signin_status_ value should not be unknown. |
| + signin_status_ = ERROR_GETTING_SIGNIN_STATUS; |
| + } |
| } |
| void SigninStatusMetricsProvider::Initialize() { |
| @@ -168,13 +179,8 @@ void SigninStatusMetricsProvider::Initialize() { |
| void SigninStatusMetricsProvider::UpdateInitialSigninStatus( |
| size_t total_count, |
| size_t signed_in_profiles_count) { |
| - RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS); |
| - |
| - if (total_count == 0) { |
| - // This should never happen. If it does, record it in histogram. |
| - RecordComputeSigninStatusHistogram(ERROR_COMPUTE_SIGNIN_STATUS); |
| - signin_status_ = UNKNOWN_SIGNIN_STATUS; |
| - } else if (signed_in_profiles_count == 0) { |
| + // total_count is known to be bigger than 0. |
| + if (signed_in_profiles_count == 0) { |
| signin_status_ = ALL_PROFILES_NOT_SIGNED_IN; |
| } else if (total_count == signed_in_profiles_count) { |
| signin_status_ = ALL_PROFILES_SIGNED_IN; |
| @@ -188,14 +194,15 @@ void SigninStatusMetricsProvider::UpdateStatusWhenBrowserAdded(bool signed_in) { |
| if ((signin_status_ == ALL_PROFILES_NOT_SIGNED_IN && signed_in) || |
| (signin_status_ == ALL_PROFILES_SIGNED_IN && !signed_in)) { |
| signin_status_ = MIXED_SIGNIN_STATUS; |
| + } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && signed_in) { |
| + signin_status_ = ALL_PROFILES_SIGNED_IN; |
| + } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && !signed_in) { |
| + signin_status_ = ALL_PROFILES_NOT_SIGNED_IN; |
| } |
| #endif |
| } |
| void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() { |
| - // Get the sign-in status of all currently open profiles. Sign-in status is |
| - // indicated by its username. When username is not empty, the profile is |
| - // signed-in. |
| ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| std::vector<Profile*> profile_list = profile_manager->GetLoadedProfiles(); |
| @@ -215,7 +222,20 @@ void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() { |
| if (manager && manager->IsAuthenticated()) |
| signed_in_profiles_count++; |
| } |
| - UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); |
| + |
| + RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS); |
| + if (profile_list.size() == 0) { |
|
Alexei Svitkine (slow)
2014/09/09 15:07:31
Nit: .empty()
yao
2014/09/09 16:39:52
Done.
|
| + // This should not happen. If it does, record it in histogram. |
| + RecordComputeSigninStatusHistogram(ERROR_NO_PROFILE_FOUND); |
| + signin_status_ = ERROR_GETTING_SIGNIN_STATUS; |
| + } else if (profile_list.size() > 0 && opened_profiles_count == 0) { |
|
Alexei Svitkine (slow)
2014/09/09 15:07:31
The profile_list.size() > 0 shouldn't be necessary
yao
2014/09/09 16:39:52
Done.
|
| + // The code indicates that Chrome is running in the background but no |
| + // browser window is opened. |
| + RecordComputeSigninStatusHistogram(NO_BROWSER_OPENED); |
| + signin_status_ = UNKNOWN_SIGNIN_STATUS; |
| + } else { |
| + UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); |
| + } |
| } |
| SigninStatusMetricsProvider::ProfilesSigninStatus |