Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_metrics.h" | 5 #include "chrome/browser/profiles/profile_metrics.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/signin/signin_header_helper.h" | 14 #include "chrome/browser/signin/signin_header_helper.h" |
| 15 #include "chrome/browser/ui/browser.h" | |
| 16 #include "chrome/browser/ui/browser_iterator.h" | |
| 15 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/installer/util/google_update_settings.h" | 18 #include "chrome/installer/util/google_update_settings.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const int kMaximumReportedProfileCount = 5; | 24 const int kMaximumReportedProfileCount = 5; |
| 23 const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks. | 25 const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks. |
| 24 | 26 |
| 27 size_t number_of_profile_switches_ = 0; | |
| 28 | |
| 25 ProfileMetrics::ProfileType GetProfileType( | 29 ProfileMetrics::ProfileType GetProfileType( |
| 26 const base::FilePath& profile_path) { | 30 const base::FilePath& profile_path) { |
| 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 28 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; | 32 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; |
| 29 ProfileManager* manager = g_browser_process->profile_manager(); | 33 ProfileManager* manager = g_browser_process->profile_manager(); |
| 30 base::FilePath user_data_dir; | 34 base::FilePath user_data_dir; |
| 31 // In unittests, we do not always have a profile_manager so check. | 35 // In unittests, we do not always have a profile_manager so check. |
| 32 if (manager) { | 36 if (manager) { |
| 33 user_data_dir = manager->user_data_dir(); | 37 user_data_dir = manager->user_data_dir(); |
| 34 } | 38 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if (info_cache.IsUsingGAIAPictureOfProfileAtIndex(i)) | 144 if (info_cache.IsUsingGAIAPictureOfProfileAtIndex(i)) |
| 141 counts->gaia_icon++; | 145 counts->gaia_icon++; |
| 142 if (info_cache.ProfileIsAuthErrorAtIndex(i)) | 146 if (info_cache.ProfileIsAuthErrorAtIndex(i)) |
| 143 counts->auth_errors++; | 147 counts->auth_errors++; |
| 144 } | 148 } |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 return true; | 151 return true; |
| 148 } | 152 } |
| 149 | 153 |
| 154 ProfileMetrics::ProfileOpenState ProfileMetrics::GetProfileOpenState( | |
| 155 ProfileManager* manager, | |
| 156 const base::FilePath& path) { | |
| 157 Profile* profile_switched_to = manager->GetProfileByPath(path); | |
| 158 ProfileMetrics::ProfileOpenState profile_open_state = PROFILE_UNOPENED; | |
| 159 | |
| 160 if (profile_switched_to) { | |
| 161 profile_open_state = PROFILE_OPENED_NO_BROWSER; | |
| 162 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
| 163 if (it->profile()->GetOriginalProfile() == | |
| 164 profile_switched_to->GetOriginalProfile()) { | |
| 165 profile_open_state = PROFILE_OPENED; | |
|
Mike Lerman
2015/01/23 19:46:14
Perhaps you can just return PROFILE_OPENED; no nee
anthonyvd
2015/01/26 16:07:48
Done.
| |
| 166 break; | |
| 167 } | |
| 168 } | |
| 169 } | |
| 170 return profile_open_state; | |
|
Mike Lerman
2015/01/23 19:46:14
Flip your condition around, and return early. So w
anthonyvd
2015/01/26 16:07:48
Done.
| |
| 171 } | |
| 150 | 172 |
| 151 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { | 173 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { |
| 152 ProfileCounts counts; | 174 ProfileCounts counts; |
| 153 if (CountProfileInformation(manager, &counts)) { | 175 if (CountProfileInformation(manager, &counts)) { |
| 154 int limited_total = counts.total; | 176 int limited_total = counts.total; |
| 155 int limited_signedin = counts.signedin; | 177 int limited_signedin = counts.signedin; |
| 156 if (limited_total > kMaximumReportedProfileCount) { | 178 if (limited_total > kMaximumReportedProfileCount) { |
| 157 limited_total = kMaximumReportedProfileCount + 1; | 179 limited_total = kMaximumReportedProfileCount + 1; |
| 158 limited_signedin = | 180 limited_signedin = |
| 159 (int)((float)(counts.signedin * limited_total) | 181 (int)((float)(counts.signedin * limited_total) |
| 160 / counts.total + 0.5); | 182 / counts.total + 0.5); |
| 161 } | 183 } |
| 162 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); | 184 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); |
| 163 } | 185 } |
| 164 } | 186 } |
| 165 | 187 |
| 188 void ProfileMetrics::LogNumberOfProfileSwitches() { | |
| 189 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSwitches", | |
| 190 number_of_profile_switches_); | |
| 191 } | |
| 192 | |
| 166 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { | 193 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { |
| 167 ProfileCounts counts; | 194 ProfileCounts counts; |
| 168 bool success = CountProfileInformation(manager, &counts); | 195 bool success = CountProfileInformation(manager, &counts); |
| 169 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total); | 196 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total); |
| 170 | 197 |
| 171 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests. | 198 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests. |
| 172 if (success) { | 199 if (success) { |
| 173 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles", | 200 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles", |
| 174 counts.supervised); | 201 counts.supervised); |
| 175 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles", | 202 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles", |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", PROFILE_DELETED, | 326 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", PROFILE_DELETED, |
| 300 NUM_PROFILE_NET_METRICS); | 327 NUM_PROFILE_NET_METRICS); |
| 301 } | 328 } |
| 302 | 329 |
| 303 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { | 330 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { |
| 304 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | 331 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); |
| 305 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, | 332 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, |
| 306 NUM_PROFILE_OPEN_METRICS); | 333 NUM_PROFILE_OPEN_METRICS); |
| 307 } | 334 } |
| 308 | 335 |
| 336 void ProfileMetrics::LogProfileSwitch( | |
| 337 ProfileOpen metric, | |
| 338 ProfileManager* manager, | |
| 339 const base::FilePath& profile_path) { | |
| 340 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | |
| 341 ProfileOpenState open_state = GetProfileOpenState(manager, profile_path); | |
| 342 switch (open_state) { | |
| 343 case PROFILE_OPENED: | |
| 344 UMA_HISTOGRAM_ENUMERATION( | |
| 345 "Profile.OpenMethod.ToOpenedProfile", | |
| 346 metric, | |
| 347 NUM_PROFILE_OPEN_METRICS); | |
| 348 break; | |
| 349 case PROFILE_OPENED_NO_BROWSER: | |
| 350 UMA_HISTOGRAM_ENUMERATION( | |
| 351 "Profile.OpenMethod.ToOpenedProfileWithoutBrowser", | |
| 352 metric, | |
| 353 NUM_PROFILE_OPEN_METRICS); | |
| 354 break; | |
| 355 case PROFILE_UNOPENED: | |
| 356 UMA_HISTOGRAM_ENUMERATION( | |
| 357 "Profile.OpenMethod.ToUnopenedProfile", | |
| 358 metric, | |
| 359 NUM_PROFILE_OPEN_METRICS); | |
| 360 break; | |
| 361 default: | |
| 362 // There are no other possible values. | |
| 363 NOTREACHED(); | |
| 364 break; | |
| 365 } | |
| 366 | |
| 367 ++number_of_profile_switches_; | |
| 368 // The LogOpenMethod histogram aggregates data from profile switches as well | |
| 369 // as opening of profile related UI elements. | |
| 370 LogProfileOpenMethod(metric); | |
| 371 } | |
| 372 | |
| 309 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { | 373 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { |
| 310 if (metric == GAIA_OPT_IN) | 374 if (metric == GAIA_OPT_IN) |
| 311 LogProfileAvatarSelection(AVATAR_GAIA); | 375 LogProfileAvatarSelection(AVATAR_GAIA); |
| 312 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", | 376 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", |
| 313 metric, | 377 metric, |
| 314 NUM_PROFILE_GAIA_METRICS); | 378 NUM_PROFILE_GAIA_METRICS); |
| 315 } | 379 } |
| 316 | 380 |
| 317 void ProfileMetrics::LogProfileSwitchUser(ProfileOpen metric) { | |
| 318 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | |
| 319 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, | |
| 320 NUM_PROFILE_OPEN_METRICS); | |
| 321 } | |
| 322 | |
| 323 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { | 381 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { |
| 324 DCHECK(metric < NUM_PROFILE_SYNC_METRICS); | 382 DCHECK(metric < NUM_PROFILE_SYNC_METRICS); |
| 325 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric, | 383 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric, |
| 326 NUM_PROFILE_SYNC_METRICS); | 384 NUM_PROFILE_SYNC_METRICS); |
| 327 } | 385 } |
| 328 | 386 |
| 329 void ProfileMetrics::LogProfileAuthResult(ProfileAuth metric) { | 387 void ProfileMetrics::LogProfileAuthResult(ProfileAuth metric) { |
| 330 UMA_HISTOGRAM_ENUMERATION("Profile.AuthResult", metric, | 388 UMA_HISTOGRAM_ENUMERATION("Profile.AuthResult", metric, |
| 331 NUM_PROFILE_AUTH_METRICS); | 389 NUM_PROFILE_AUTH_METRICS); |
| 332 } | 390 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", | 522 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", |
| 465 GetProfileType(profile_path), | 523 GetProfileType(profile_path), |
| 466 NUM_PROFILE_TYPE_METRICS); | 524 NUM_PROFILE_TYPE_METRICS); |
| 467 } | 525 } |
| 468 | 526 |
| 469 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { | 527 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { |
| 470 UMA_HISTOGRAM_ENUMERATION("Profile.Update", | 528 UMA_HISTOGRAM_ENUMERATION("Profile.Update", |
| 471 GetProfileType(profile_path), | 529 GetProfileType(profile_path), |
| 472 NUM_PROFILE_TYPE_METRICS); | 530 NUM_PROFILE_TYPE_METRICS); |
| 473 } | 531 } |
| OLD | NEW |