Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/metrics/signin_status_metrics_provider.cc

Issue 554863002: Handles unknown signin status and collect more stats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments & add 2 more error situations to record Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
33 USER_SIGNIN_WHEN_STATUS_UNKNOWN,
34 USER_SIGNOUT_WHEN_STATUS_UNKNOWN,
32 COMPUTE_SIGNIN_STATUS_MAX, 35 COMPUTE_SIGNIN_STATUS_MAX,
33 }; 36 };
34 37
35 void RecordComputeSigninStatusHistogram(ComputeSigninStatus status) { 38 void RecordComputeSigninStatusHistogram(ComputeSigninStatus status) {
36 UMA_HISTOGRAM_ENUMERATION("UMA.ComputeCurrentSigninStatus", status, 39 UMA_HISTOGRAM_ENUMERATION("UMA.ComputeCurrentSigninStatus", status,
37 COMPUTE_SIGNIN_STATUS_MAX); 40 COMPUTE_SIGNIN_STATUS_MAX);
38 } 41 }
39 42
40 } // namespace 43 } // namespace
41 44
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void SigninStatusMetricsProvider::SigninManagerShutdown( 119 void SigninStatusMetricsProvider::SigninManagerShutdown(
117 SigninManagerBase* manager) { 120 SigninManagerBase* manager) {
118 if (scoped_observer_.IsObserving(manager)) 121 if (scoped_observer_.IsObserving(manager))
119 scoped_observer_.Remove(manager); 122 scoped_observer_.Remove(manager);
120 } 123 }
121 124
122 void SigninStatusMetricsProvider::GoogleSigninSucceeded( 125 void SigninStatusMetricsProvider::GoogleSigninSucceeded(
123 const std::string& account_id, 126 const std::string& account_id,
124 const std::string& username, 127 const std::string& username,
125 const std::string& password) { 128 const std::string& password) {
126 if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) 129 if (signin_status_ == ALL_PROFILES_NOT_SIGNED_IN) {
127 signin_status_ = MIXED_SIGNIN_STATUS; 130 signin_status_ = MIXED_SIGNIN_STATUS;
131 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) {
132 // There should have at least one browser opened if the user can sign in, so
133 // signin_status_ value should not be unknown.
134 signin_status_ = ERROR_GETTING_SIGNIN_STATUS;
135 RecordComputeSigninStatusHistogram(USER_SIGNIN_WHEN_STATUS_UNKNOWN);
136 }
128 } 137 }
129 138
130 void SigninStatusMetricsProvider::GoogleSignedOut(const std::string& account_id, 139 void SigninStatusMetricsProvider::GoogleSignedOut(const std::string& account_id,
131 const std::string& username) { 140 const std::string& username) {
132 if (signin_status_ == ALL_PROFILES_SIGNED_IN) 141 if (signin_status_ == ALL_PROFILES_SIGNED_IN) {
133 signin_status_ = MIXED_SIGNIN_STATUS; 142 signin_status_ = MIXED_SIGNIN_STATUS;
143 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS) {
144 // There should have at least one browser opened if the user can sign out,
145 // so signin_status_ value should not be unknown.
146 signin_status_ = ERROR_GETTING_SIGNIN_STATUS;
147 RecordComputeSigninStatusHistogram(USER_SIGNOUT_WHEN_STATUS_UNKNOWN);
148 }
134 } 149 }
135 150
136 void SigninStatusMetricsProvider::Initialize() { 151 void SigninStatusMetricsProvider::Initialize() {
137 // Add observers. 152 // Add observers.
138 #if !defined(OS_ANDROID) 153 #if !defined(OS_ANDROID)
139 // On Android, there is always only one profile in any situation, opening new 154 // 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 155 // windows (which is possible with only some Android devices) will not change
141 // the opened profiles signin status. 156 // the opened profiles signin status.
142 BrowserList::AddObserver(this); 157 BrowserList::AddObserver(this);
143 #endif 158 #endif
(...skipping 17 matching lines...) Expand all
161 if (profiles.empty()) { 176 if (profiles.empty()) {
162 signin_status_ = UNKNOWN_SIGNIN_STATUS; 177 signin_status_ = UNKNOWN_SIGNIN_STATUS;
163 } else { 178 } else {
164 ComputeCurrentSigninStatus(); 179 ComputeCurrentSigninStatus();
165 } 180 }
166 } 181 }
167 182
168 void SigninStatusMetricsProvider::UpdateInitialSigninStatus( 183 void SigninStatusMetricsProvider::UpdateInitialSigninStatus(
169 size_t total_count, 184 size_t total_count,
170 size_t signed_in_profiles_count) { 185 size_t signed_in_profiles_count) {
171 RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS); 186 // total_count is known to be bigger than 0.
172 187 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; 188 signin_status_ = ALL_PROFILES_NOT_SIGNED_IN;
179 } else if (total_count == signed_in_profiles_count) { 189 } else if (total_count == signed_in_profiles_count) {
180 signin_status_ = ALL_PROFILES_SIGNED_IN; 190 signin_status_ = ALL_PROFILES_SIGNED_IN;
181 } else { 191 } else {
182 signin_status_ = MIXED_SIGNIN_STATUS; 192 signin_status_ = MIXED_SIGNIN_STATUS;
183 } 193 }
184 } 194 }
185 195
186 void SigninStatusMetricsProvider::UpdateStatusWhenBrowserAdded(bool signed_in) { 196 void SigninStatusMetricsProvider::UpdateStatusWhenBrowserAdded(bool signed_in) {
187 #if !defined(OS_ANDROID) 197 #if !defined(OS_ANDROID)
188 if ((signin_status_ == ALL_PROFILES_NOT_SIGNED_IN && signed_in) || 198 if ((signin_status_ == ALL_PROFILES_NOT_SIGNED_IN && signed_in) ||
189 (signin_status_ == ALL_PROFILES_SIGNED_IN && !signed_in)) { 199 (signin_status_ == ALL_PROFILES_SIGNED_IN && !signed_in)) {
190 signin_status_ = MIXED_SIGNIN_STATUS; 200 signin_status_ = MIXED_SIGNIN_STATUS;
201 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && signed_in) {
Alexei Svitkine (slow) 2014/09/09 19:17:45 Nit: Combine the ifs and use a ?: } else if (sign
yao 2014/09/09 19:37:32 Done.
202 signin_status_ = ALL_PROFILES_SIGNED_IN;
203 } else if (signin_status_ == UNKNOWN_SIGNIN_STATUS && !signed_in) {
204 signin_status_ = ALL_PROFILES_NOT_SIGNED_IN;
191 } 205 }
192 #endif 206 #endif
193 } 207 }
194 208
195 void SigninStatusMetricsProvider::ComputeCurrentSigninStatus() { 209 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(); 210 ProfileManager* profile_manager = g_browser_process->profile_manager();
200 std::vector<Profile*> profile_list = profile_manager->GetLoadedProfiles(); 211 std::vector<Profile*> profile_list = profile_manager->GetLoadedProfiles();
201 212
202 size_t opened_profiles_count = 0; 213 size_t opened_profiles_count = 0;
203 size_t signed_in_profiles_count = 0; 214 size_t signed_in_profiles_count = 0;
204 215
205 for (size_t i = 0; i < profile_list.size(); ++i) { 216 for (size_t i = 0; i < profile_list.size(); ++i) {
206 #if !defined(OS_ANDROID) 217 #if !defined(OS_ANDROID)
207 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) { 218 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) {
208 // The profile is loaded, but there's no opened browser for this profile. 219 // The profile is loaded, but there's no opened browser for this profile.
209 continue; 220 continue;
210 } 221 }
211 #endif 222 #endif
212 opened_profiles_count++; 223 opened_profiles_count++;
213 SigninManager* manager = SigninManagerFactory::GetForProfile( 224 SigninManager* manager = SigninManagerFactory::GetForProfile(
214 profile_list[i]->GetOriginalProfile()); 225 profile_list[i]->GetOriginalProfile());
215 if (manager && manager->IsAuthenticated()) 226 if (manager && manager->IsAuthenticated())
216 signed_in_profiles_count++; 227 signed_in_profiles_count++;
217 } 228 }
218 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); 229
230 RecordComputeSigninStatusHistogram(ENTERED_COMPUTE_SIGNIN_STATUS);
231 if (profile_list.empty()) {
232 // This should not happen. If it does, record it in histogram.
233 RecordComputeSigninStatusHistogram(ERROR_NO_PROFILE_FOUND);
234 signin_status_ = ERROR_GETTING_SIGNIN_STATUS;
235 } else if (opened_profiles_count == 0) {
236 // The code indicates that Chrome is running in the background but no
237 // browser window is opened.
238 RecordComputeSigninStatusHistogram(NO_BROWSER_OPENED);
239 signin_status_ = UNKNOWN_SIGNIN_STATUS;
240 } else {
241 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count);
242 }
219 } 243 }
220 244
221 SigninStatusMetricsProvider::ProfilesSigninStatus 245 SigninStatusMetricsProvider::ProfilesSigninStatus
222 SigninStatusMetricsProvider::GetSigninStatusForTesting() { 246 SigninStatusMetricsProvider::GetSigninStatusForTesting() {
223 return signin_status_; 247 return signin_status_;
224 } 248 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/signin_status_metrics_provider.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698