Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/metrics/signin_status_metrics_provider.h" | 5 #include "chrome/browser/metrics/signin_status_metrics_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #if !defined(OS_ANDROID) | 21 #if !defined(OS_ANDROID) |
| 22 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // The event of calling function ComputeCurrentSigninStatus and the errors | 27 // The event of calling function ComputeCurrentSigninStatus and the errors |
| 28 // occurred during the function execution. | 28 // occurred during the function execution. |
| 29 enum ComputeSigninStatus { | 29 enum ComputeSigninStatus { |
| 30 ENTERED_COMPUTE_SIGNIN_STATUS, | 30 ENTERED_COMPUTE_SIGNIN_STATUS, |
| 31 ERROR_COMPUTE_SIGNIN_STATUS, | 31 ERROR_NO_PROFILE_FOUND, |
| 32 NO_BROWSER_OPENED, | |
| 32 COMPUTE_SIGNIN_STATUS_MAX, | 33 COMPUTE_SIGNIN_STATUS_MAX, |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 void RecordComputeSigninStatusHistogram(ComputeSigninStatus status) { | 36 void RecordComputeSigninStatusHistogram(ComputeSigninStatus status) { |
| 36 UMA_HISTOGRAM_ENUMERATION("UMA.ComputeCurrentSigninStatus", status, | 37 UMA_HISTOGRAM_ENUMERATION("UMA.ComputeCurrentSigninStatus", status, |
| 37 COMPUTE_SIGNIN_STATUS_MAX); | 38 COMPUTE_SIGNIN_STATUS_MAX); |
| 38 } | 39 } |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 void SigninStatusMetricsProvider::SigninManagerShutdown( | 117 void SigninStatusMetricsProvider::SigninManagerShutdown( |
| 117 SigninManagerBase* manager) { | 118 SigninManagerBase* manager) { |
| 118 if (scoped_observer_.IsObserving(manager)) | 119 if (scoped_observer_.IsObserving(manager)) |
| 119 scoped_observer_.Remove(manager); | 120 scoped_observer_.Remove(manager); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void SigninStatusMetricsProvider::GoogleSigninSucceeded( | 123 void SigninStatusMetricsProvider::GoogleSigninSucceeded( |
| 123 const std::string& account_id, | 124 const std::string& account_id, |
| 124 const std::string& username, | 125 const std::string& username, |
| 125 const std::string& password) { | 126 const std::string& password) { |
| 126 if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) | 127 if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) { |
| 127 signin_status_ = MIXED_SIGNIN_STATUS; | 128 signin_status_ = MIXED_SIGNIN_STATUS; |
| 129 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { | |
| 130 // There should have at least one browser opened if the user can sign in, so | |
| 131 // signin_status_ value should not be unknown. | |
| 132 signin_status_ = ERROR_GETTING_SIGNIN_STATUS; | |
| 133 } | |
| 128 } | 134 } |
| 129 | 135 |
| 130 void SigninStatusMetricsProvider::GoogleSignedOut(const std::string& account_id, | 136 void SigninStatusMetricsProvider::GoogleSignedOut(const std::string& account_id, |
| 131 const std::string& username) { | 137 const std::string& username) { |
| 132 if (signin_status_ == ALL_PROFILES_SIGNED_IN) | 138 if (signin_status_ == ALL_PROFILES_SIGNED_IN) { |
| 133 signin_status_ = MIXED_SIGNIN_STATUS; | 139 signin_status_ = MIXED_SIGNIN_STATUS; |
| 140 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { | |
| 141 // There should have at least one browser opened if the user can sign out, | |
| 142 // so signin_status_ value should not be unknown. | |
| 143 signin_status_ = ERROR_GETTING_SIGNIN_STATUS; | |
| 144 } | |
| 134 } | 145 } |
| 135 | 146 |
| 136 void SigninStatusMetricsProvider::Initialize() { | 147 void SigninStatusMetricsProvider::Initialize() { |
| 137 // Add observers. | 148 // Add observers. |
| 138 #if !defined(OS_ANDROID) | 149 #if !defined(OS_ANDROID) |
| 139 // On Android, there is always only one profile in any situation, opening new | 150 // On Android, there is always only one profile in any situation, opening new |
| 140 // windows (which is possible with only some Android devices) will not change | 151 // windows (which is possible with only some Android devices) will not change |
| 141 // the opened profiles signin status. | 152 // the opened profiles signin status. |
| 142 BrowserList::AddObserver(this); | 153 BrowserList::AddObserver(this); |
| 143 #endif | 154 #endif |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 161 if (profiles.empty()) { | 172 if (profiles.empty()) { |
| 162 signin_status_ = UNKNOWN_SIGNIN_STATUS; | 173 signin_status_ = UNKNOWN_SIGNIN_STATUS; |
| 163 } else { | 174 } else { |
| 164 ComputeCurrentSigninStatus(); | 175 ComputeCurrentSigninStatus(); |
| 165 } | 176 } |
| 166 } | 177 } |
| 167 | 178 |
| 168 void SigninStatusMetricsProvider::UpdateInitialSigninStatus( | 179 void SigninStatusMetricsProvider::UpdateInitialSigninStatus( |
| 169 size_t total_count, | 180 size_t total_count, |
| 170 size_t signed_in_profiles_count) { | 181 size_t signed_in_profiles_count) { |
| 171 RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS); | 182 // total_count is known to be bigger than 0. |
| 172 | 183 if (signed_in_profiles_count == 0) { |
| 173 if (total_count == 0) { | |
| 174 // This should never happen. If it does, record it in histogram. | |
| 175 RecordComputeSigninStatusHistogram(ERROR_COMPUTE_SIGNIN_STATUS); | |
| 176 signin_status_ = UNKNOWN_SIGNIN_STATUS; | |
| 177 } else if (signed_in_profiles_count == 0) { | |
| 178 signin_status_ = ALL_PROFILES_NOT_SIGNED_IN; | 184 signin_status_ = ALL_PROFILES_NOT_SIGNED_IN; |
| 179 } else if (total_count == signed_in_profiles_count) { | 185 } else if (total_count == signed_in_profiles_count) { |
| 180 signin_status_ = ALL_PROFILES_SIGNED_IN; | 186 signin_status_ = ALL_PROFILES_SIGNED_IN; |
| 181 } else { | 187 } else { |
| 182 signin_status_ = MIXED_SIGNIN_STATUS; | 188 signin_status_ = MIXED_SIGNIN_STATUS; |
| 183 } | 189 } |
| 184 } | 190 } |
| 185 | 191 |
| 186 void SigninStatusMetricsProvider::UpdateStatusWhenBrowserAdded(bool signed_in) { | 192 void SigninStatusMetricsProvider::UpdateStatusWhenBrowserAdded(bool signed_in) { |
| 187 #if !defined(OS_ANDROID) | 193 #if !defined(OS_ANDROID) |
| 188 if ((signin_status_ == ALL_PROFILES_NOT_SIGNED_IN && signed_in) || | 194 if ((signin_status_ == ALL_PROFILES_NOT_SIGNED_IN && signed_in) || |
| 189 (signin_status_ == ALL_PROFILES_SIGNED_IN && !signed_in)) { | 195 (signin_status_ == ALL_PROFILES_SIGNED_IN && !signed_in)) { |
| 190 signin_status_ = MIXED_SIGNIN_STATUS; | 196 signin_status_ = MIXED_SIGNIN_STATUS; |
| 197 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && signed_in) { | |
| 198 signin_status_ = ALL_PROFILES_SIGNED_IN; | |
| 199 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && !signed_in) { | |
| 200 signin_status_ = ALL_PROFILES_NOT_SIGNED_IN; | |
| 191 } | 201 } |
| 192 #endif | 202 #endif |
| 193 } | 203 } |
| 194 | 204 |
| 195 void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() { | 205 void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() { |
| 196 // Get the sign-in status of all currently open profiles. Sign-in status is | |
| 197 // indicated by its username. When username is not empty, the profile is | |
| 198 // signed-in. | |
| 199 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 206 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 200 std::vector<Profile*> profile_list = profile_manager->GetLoadedProfiles(); | 207 std::vector<Profile*> profile_list = profile_manager->GetLoadedProfiles(); |
| 201 | 208 |
| 202 size_t opened_profiles_count = 0; | 209 size_t opened_profiles_count = 0; |
| 203 size_t signed_in_profiles_count = 0; | 210 size_t signed_in_profiles_count = 0; |
| 204 | 211 |
| 205 for (size_t i = 0; i < profile_list.size(); ++i) { | 212 for (size_t i = 0; i < profile_list.size(); ++i) { |
| 206 #if !defined(OS_ANDROID) | 213 #if !defined(OS_ANDROID) |
| 207 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) { | 214 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) { |
| 208 // The profile is loaded, but there's no opened browser for this profile. | 215 // The profile is loaded, but there's no opened browser for this profile. |
| 209 continue; | 216 continue; |
| 210 } | 217 } |
| 211 #endif | 218 #endif |
| 212 opened_profiles_count++; | 219 opened_profiles_count++; |
| 213 SigninManager* manager = SigninManagerFactory::GetForProfile( | 220 SigninManager* manager = SigninManagerFactory::GetForProfile( |
| 214 profile_list[i]->GetOriginalProfile()); | 221 profile_list[i]->GetOriginalProfile()); |
| 215 if (manager && manager->IsAuthenticated()) | 222 if (manager && manager->IsAuthenticated()) |
| 216 signed_in_profiles_count++; | 223 signed_in_profiles_count++; |
| 217 } | 224 } |
| 218 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); | 225 |
| 226 RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS); | |
| 227 if (profile_list.size() == 0) { | |
|
Alexei Svitkine (slow)
2014/09/09 15:07:31
Nit: .empty()
yao
2014/09/09 16:39:52
Done.
| |
| 228 // This should not happen. If it does, record it in histogram. | |
| 229 RecordComputeSigninStatusHistogram(ERROR_NO_PROFILE_FOUND); | |
| 230 signin_status_ = ERROR_GETTING_SIGNIN_STATUS; | |
| 231 } 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.
| |
| 232 // The code indicates that Chrome is running in the background but no | |
| 233 // browser window is opened. | |
| 234 RecordComputeSigninStatusHistogram(NO_BROWSER_OPENED); | |
| 235 signin_status_ = UNKNOWN_SIGNIN_STATUS; | |
| 236 } else { | |
| 237 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); | |
| 238 } | |
| 219 } | 239 } |
| 220 | 240 |
| 221 SigninStatusMetricsProvider::ProfilesSigninStatus | 241 SigninStatusMetricsProvider::ProfilesSigninStatus |
| 222 SigninStatusMetricsProvider::GetSigninStatusForTesting() { | 242 SigninStatusMetricsProvider::GetSigninStatusForTesting() { |
| 223 return signin_status_; | 243 return signin_status_; |
| 224 } | 244 } |
| OLD | NEW |