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