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" | |
|
Mike Lerman
2015/01/27 15:28:26
You can remove browser.h.
| |
| 16 #include "chrome/browser/ui/browser_finder.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 | |
| 29 // Enum for tracking the state of profiles being switched to. | |
| 30 enum ProfileOpenState { | |
| 31 // Profile being switched to is already opened and has browsers opened. | |
| 32 PROFILE_OPENED = 0, | |
| 33 // Profile being switched to is already opened but has no browsers opened. | |
| 34 PROFILE_OPENED_NO_BROWSER, | |
| 35 // Profile being switched to is not opened. | |
| 36 PROFILE_UNOPENED | |
| 37 }; | |
| 38 | |
| 39 ProfileOpenState GetProfileOpenState( | |
| 40 ProfileManager* manager, | |
| 41 const base::FilePath& path) { | |
| 42 Profile* profile_switched_to = manager->GetProfileByPath(path); | |
| 43 | |
| 44 if (!profile_switched_to) { | |
| 45 return PROFILE_UNOPENED; | |
| 46 } | |
| 47 | |
| 48 if (chrome::GetTotalBrowserCountForProfile(profile_switched_to) > 0) { | |
| 49 return PROFILE_OPENED; | |
| 50 } | |
| 51 | |
| 52 return PROFILE_OPENED_NO_BROWSER; | |
| 53 } | |
| 54 | |
| 25 ProfileMetrics::ProfileType GetProfileType( | 55 ProfileMetrics::ProfileType GetProfileType( |
| 26 const base::FilePath& profile_path) { | 56 const base::FilePath& profile_path) { |
| 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 28 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; | 58 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; |
| 29 ProfileManager* manager = g_browser_process->profile_manager(); | 59 ProfileManager* manager = g_browser_process->profile_manager(); |
| 30 base::FilePath user_data_dir; | 60 base::FilePath user_data_dir; |
| 31 // In unittests, we do not always have a profile_manager so check. | 61 // In unittests, we do not always have a profile_manager so check. |
| 32 if (manager) { | 62 if (manager) { |
| 33 user_data_dir = manager->user_data_dir(); | 63 user_data_dir = manager->user_data_dir(); |
| 34 } | 64 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if (info_cache.IsUsingGAIAPictureOfProfileAtIndex(i)) | 170 if (info_cache.IsUsingGAIAPictureOfProfileAtIndex(i)) |
| 141 counts->gaia_icon++; | 171 counts->gaia_icon++; |
| 142 if (info_cache.ProfileIsAuthErrorAtIndex(i)) | 172 if (info_cache.ProfileIsAuthErrorAtIndex(i)) |
| 143 counts->auth_errors++; | 173 counts->auth_errors++; |
| 144 } | 174 } |
| 145 } | 175 } |
| 146 } | 176 } |
| 147 return true; | 177 return true; |
| 148 } | 178 } |
| 149 | 179 |
| 150 | |
| 151 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { | 180 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { |
| 152 ProfileCounts counts; | 181 ProfileCounts counts; |
| 153 if (CountProfileInformation(manager, &counts)) { | 182 if (CountProfileInformation(manager, &counts)) { |
| 154 int limited_total = counts.total; | 183 int limited_total = counts.total; |
| 155 int limited_signedin = counts.signedin; | 184 int limited_signedin = counts.signedin; |
| 156 if (limited_total > kMaximumReportedProfileCount) { | 185 if (limited_total > kMaximumReportedProfileCount) { |
| 157 limited_total = kMaximumReportedProfileCount + 1; | 186 limited_total = kMaximumReportedProfileCount + 1; |
| 158 limited_signedin = | 187 limited_signedin = |
| 159 (int)((float)(counts.signedin * limited_total) | 188 (int)((float)(counts.signedin * limited_total) |
| 160 / counts.total + 0.5); | 189 / counts.total + 0.5); |
| 161 } | 190 } |
| 162 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); | 191 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); |
| 163 } | 192 } |
| 164 } | 193 } |
| 165 | 194 |
| 195 void ProfileMetrics::LogNumberOfProfileSwitches() { | |
| 196 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSwitches", | |
| 197 number_of_profile_switches_); | |
| 198 } | |
| 199 | |
| 166 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { | 200 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { |
| 167 ProfileCounts counts; | 201 ProfileCounts counts; |
| 168 bool success = CountProfileInformation(manager, &counts); | 202 bool success = CountProfileInformation(manager, &counts); |
| 169 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total); | 203 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfProfiles", counts.total); |
| 170 | 204 |
| 171 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests. | 205 // Ignore other metrics if we have no profiles, e.g. in Chrome Frame tests. |
| 172 if (success) { | 206 if (success) { |
| 173 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles", | 207 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfManagedProfiles", |
| 174 counts.supervised); | 208 counts.supervised); |
| 175 UMA_HISTOGRAM_COUNTS_100("Profile.PercentageOfManagedProfiles", | 209 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, | 333 UMA_HISTOGRAM_ENUMERATION("Profile.NetUserCount", PROFILE_DELETED, |
| 300 NUM_PROFILE_NET_METRICS); | 334 NUM_PROFILE_NET_METRICS); |
| 301 } | 335 } |
| 302 | 336 |
| 303 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { | 337 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { |
| 304 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | 338 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); |
| 305 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, | 339 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, |
| 306 NUM_PROFILE_OPEN_METRICS); | 340 NUM_PROFILE_OPEN_METRICS); |
| 307 } | 341 } |
| 308 | 342 |
| 343 void ProfileMetrics::LogProfileSwitch( | |
| 344 ProfileOpen metric, | |
| 345 ProfileManager* manager, | |
| 346 const base::FilePath& profile_path) { | |
| 347 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | |
| 348 ProfileOpenState open_state = GetProfileOpenState(manager, profile_path); | |
| 349 switch (open_state) { | |
| 350 case PROFILE_OPENED: | |
| 351 UMA_HISTOGRAM_ENUMERATION( | |
| 352 "Profile.OpenMethod.ToOpenedProfile", | |
| 353 metric, | |
| 354 NUM_PROFILE_OPEN_METRICS); | |
| 355 break; | |
| 356 case PROFILE_OPENED_NO_BROWSER: | |
| 357 UMA_HISTOGRAM_ENUMERATION( | |
| 358 "Profile.OpenMethod.ToOpenedProfileWithoutBrowser", | |
| 359 metric, | |
| 360 NUM_PROFILE_OPEN_METRICS); | |
| 361 break; | |
| 362 case PROFILE_UNOPENED: | |
| 363 UMA_HISTOGRAM_ENUMERATION( | |
| 364 "Profile.OpenMethod.ToUnopenedProfile", | |
| 365 metric, | |
| 366 NUM_PROFILE_OPEN_METRICS); | |
| 367 break; | |
| 368 default: | |
| 369 // There are no other possible values. | |
| 370 NOTREACHED(); | |
| 371 break; | |
| 372 } | |
| 373 | |
| 374 ++number_of_profile_switches_; | |
| 375 // The LogOpenMethod histogram aggregates data from profile switches as well | |
| 376 // as opening of profile related UI elements. | |
| 377 LogProfileOpenMethod(metric); | |
| 378 } | |
| 379 | |
| 309 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { | 380 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { |
| 310 if (metric == GAIA_OPT_IN) | 381 if (metric == GAIA_OPT_IN) |
| 311 LogProfileAvatarSelection(AVATAR_GAIA); | 382 LogProfileAvatarSelection(AVATAR_GAIA); |
| 312 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", | 383 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", |
| 313 metric, | 384 metric, |
| 314 NUM_PROFILE_GAIA_METRICS); | 385 NUM_PROFILE_GAIA_METRICS); |
| 315 } | 386 } |
| 316 | 387 |
| 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) { | 388 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { |
| 324 DCHECK(metric < NUM_PROFILE_SYNC_METRICS); | 389 DCHECK(metric < NUM_PROFILE_SYNC_METRICS); |
| 325 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric, | 390 UMA_HISTOGRAM_ENUMERATION("Profile.SyncCustomize", metric, |
| 326 NUM_PROFILE_SYNC_METRICS); | 391 NUM_PROFILE_SYNC_METRICS); |
| 327 } | 392 } |
| 328 | 393 |
| 329 void ProfileMetrics::LogProfileAuthResult(ProfileAuth metric) { | 394 void ProfileMetrics::LogProfileAuthResult(ProfileAuth metric) { |
| 330 UMA_HISTOGRAM_ENUMERATION("Profile.AuthResult", metric, | 395 UMA_HISTOGRAM_ENUMERATION("Profile.AuthResult", metric, |
| 331 NUM_PROFILE_AUTH_METRICS); | 396 NUM_PROFILE_AUTH_METRICS); |
| 332 } | 397 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", | 529 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", |
| 465 GetProfileType(profile_path), | 530 GetProfileType(profile_path), |
| 466 NUM_PROFILE_TYPE_METRICS); | 531 NUM_PROFILE_TYPE_METRICS); |
| 467 } | 532 } |
| 468 | 533 |
| 469 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { | 534 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { |
| 470 UMA_HISTOGRAM_ENUMERATION("Profile.Update", | 535 UMA_HISTOGRAM_ENUMERATION("Profile.Update", |
| 471 GetProfileType(profile_path), | 536 GetProfileType(profile_path), |
| 472 NUM_PROFILE_TYPE_METRICS); | 537 NUM_PROFILE_TYPE_METRICS); |
| 473 } | 538 } |
| OLD | NEW |