| 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/chrome_signin_helper.h" | 14 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/installer/util/google_update_settings.h" | 17 #include "chrome/installer/util/google_update_settings.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 #if defined(OS_WIN) || defined(OS_MACOSX) | 23 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 24 const int kMaximumReportedProfileCount = 5; | 24 const int kMaximumReportedProfileCount = 5; |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks. | 27 const int kMaximumDaysOfDisuse = 4 * 7; // Should be integral number of weeks. |
| 28 | 28 |
| 29 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 29 size_t number_of_profile_switches_ = 0; | 30 size_t number_of_profile_switches_ = 0; |
| 31 #endif |
| 30 | 32 |
| 31 // Enum for tracking the state of profiles being switched to. | 33 // Enum for tracking the state of profiles being switched to. |
| 32 enum ProfileOpenState { | 34 enum ProfileOpenState { |
| 33 // Profile being switched to is already opened and has browsers opened. | 35 // Profile being switched to is already opened and has browsers opened. |
| 34 PROFILE_OPENED = 0, | 36 PROFILE_OPENED = 0, |
| 35 // Profile being switched to is already opened but has no browsers opened. | 37 // Profile being switched to is already opened but has no browsers opened. |
| 36 PROFILE_OPENED_NO_BROWSER, | 38 PROFILE_OPENED_NO_BROWSER, |
| 37 // Profile being switched to is not opened. | 39 // Profile being switched to is not opened. |
| 38 PROFILE_UNOPENED | 40 PROFILE_UNOPENED |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 41 ProfileOpenState GetProfileOpenState( | 44 ProfileOpenState GetProfileOpenState( |
| 42 ProfileManager* manager, | 45 ProfileManager* manager, |
| 43 const base::FilePath& path) { | 46 const base::FilePath& path) { |
| 44 Profile* profile_switched_to = manager->GetProfileByPath(path); | 47 Profile* profile_switched_to = manager->GetProfileByPath(path); |
| 48 if (!profile_switched_to) |
| 49 return PROFILE_UNOPENED; |
| 45 | 50 |
| 46 if (!profile_switched_to) { | 51 if (chrome::GetTotalBrowserCountForProfile(profile_switched_to) > 0) |
| 47 return PROFILE_UNOPENED; | |
| 48 } | |
| 49 | |
| 50 if (chrome::GetTotalBrowserCountForProfile(profile_switched_to) > 0) { | |
| 51 return PROFILE_OPENED; | 52 return PROFILE_OPENED; |
| 52 } | |
| 53 | 53 |
| 54 return PROFILE_OPENED_NO_BROWSER; | 54 return PROFILE_OPENED_NO_BROWSER; |
| 55 } | 55 } |
| 56 #endif |
| 56 | 57 |
| 57 ProfileMetrics::ProfileType GetProfileType( | 58 ProfileMetrics::ProfileType GetProfileType( |
| 58 const base::FilePath& profile_path) { | 59 const base::FilePath& profile_path) { |
| 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 60 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; | 61 ProfileMetrics::ProfileType metric = ProfileMetrics::SECONDARY; |
| 61 ProfileManager* manager = g_browser_process->profile_manager(); | 62 ProfileManager* manager = g_browser_process->profile_manager(); |
| 62 base::FilePath user_data_dir; | 63 base::FilePath user_data_dir; |
| 63 // In unittests, we do not always have a profile_manager so check. | 64 // In unittests, we do not always have a profile_manager so check. |
| 64 if (manager) { | 65 if (manager) { |
| 65 user_data_dir = manager->user_data_dir(); | 66 user_data_dir = manager->user_data_dir(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 limited_total = kMaximumReportedProfileCount + 1; | 184 limited_total = kMaximumReportedProfileCount + 1; |
| 184 limited_signedin = | 185 limited_signedin = |
| 185 (int)((float)(counts.signedin * limited_total) | 186 (int)((float)(counts.signedin * limited_total) |
| 186 / counts.total + 0.5); | 187 / counts.total + 0.5); |
| 187 } | 188 } |
| 188 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); | 189 UpdateReportedOSProfileStatistics(limited_total, limited_signedin); |
| 189 } | 190 } |
| 190 #endif | 191 #endif |
| 191 } | 192 } |
| 192 | 193 |
| 194 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 193 void ProfileMetrics::LogNumberOfProfileSwitches() { | 195 void ProfileMetrics::LogNumberOfProfileSwitches() { |
| 194 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSwitches", | 196 UMA_HISTOGRAM_COUNTS_100("Profile.NumberOfSwitches", |
| 195 number_of_profile_switches_); | 197 number_of_profile_switches_); |
| 196 } | 198 } |
| 199 #endif |
| 197 | 200 |
| 198 // The OS_MACOSX implementation of this function is in profile_metrics_mac.mm. | 201 // The OS_MACOSX implementation of this function is in profile_metrics_mac.mm. |
| 199 #if defined(OS_WIN) | 202 #if defined(OS_WIN) |
| 200 void ProfileMetrics::UpdateReportedOSProfileStatistics( | 203 void ProfileMetrics::UpdateReportedOSProfileStatistics( |
| 201 size_t active, size_t signedin) { | 204 size_t active, size_t signedin) { |
| 202 GoogleUpdateSettings::UpdateProfileCounts(active, signedin); | 205 GoogleUpdateSettings::UpdateProfileCounts(active, signedin); |
| 203 } | 206 } |
| 204 #endif | 207 #endif |
| 205 | 208 |
| 206 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { | 209 void ProfileMetrics::LogNumberOfProfiles(ProfileManager* manager) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 NUM_PROFILE_NET_METRICS); | 349 NUM_PROFILE_NET_METRICS); |
| 347 } | 350 } |
| 348 } | 351 } |
| 349 | 352 |
| 350 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { | 353 void ProfileMetrics::LogProfileOpenMethod(ProfileOpen metric) { |
| 351 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | 354 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); |
| 352 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, | 355 UMA_HISTOGRAM_ENUMERATION("Profile.OpenMethod", metric, |
| 353 NUM_PROFILE_OPEN_METRICS); | 356 NUM_PROFILE_OPEN_METRICS); |
| 354 } | 357 } |
| 355 | 358 |
| 359 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 356 void ProfileMetrics::LogProfileSwitch( | 360 void ProfileMetrics::LogProfileSwitch( |
| 357 ProfileOpen metric, | 361 ProfileOpen metric, |
| 358 ProfileManager* manager, | 362 ProfileManager* manager, |
| 359 const base::FilePath& profile_path) { | 363 const base::FilePath& profile_path) { |
| 360 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); | 364 DCHECK(metric < NUM_PROFILE_OPEN_METRICS); |
| 361 ProfileOpenState open_state = GetProfileOpenState(manager, profile_path); | 365 ProfileOpenState open_state = GetProfileOpenState(manager, profile_path); |
| 362 switch (open_state) { | 366 switch (open_state) { |
| 363 case PROFILE_OPENED: | 367 case PROFILE_OPENED: |
| 364 UMA_HISTOGRAM_ENUMERATION( | 368 UMA_HISTOGRAM_ENUMERATION( |
| 365 "Profile.OpenMethod.ToOpenedProfile", | 369 "Profile.OpenMethod.ToOpenedProfile", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 382 // There are no other possible values. | 386 // There are no other possible values. |
| 383 NOTREACHED(); | 387 NOTREACHED(); |
| 384 break; | 388 break; |
| 385 } | 389 } |
| 386 | 390 |
| 387 ++number_of_profile_switches_; | 391 ++number_of_profile_switches_; |
| 388 // The LogOpenMethod histogram aggregates data from profile switches as well | 392 // The LogOpenMethod histogram aggregates data from profile switches as well |
| 389 // as opening of profile related UI elements. | 393 // as opening of profile related UI elements. |
| 390 LogProfileOpenMethod(metric); | 394 LogProfileOpenMethod(metric); |
| 391 } | 395 } |
| 396 #endif |
| 392 | 397 |
| 393 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { | 398 void ProfileMetrics::LogProfileSwitchGaia(ProfileGaia metric) { |
| 394 if (metric == GAIA_OPT_IN) | 399 if (metric == GAIA_OPT_IN) |
| 395 LogProfileAvatarSelection(AVATAR_GAIA); | 400 LogProfileAvatarSelection(AVATAR_GAIA); |
| 396 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", | 401 UMA_HISTOGRAM_ENUMERATION("Profile.SwitchGaiaPhotoSettings", |
| 397 metric, | 402 metric, |
| 398 NUM_PROFILE_GAIA_METRICS); | 403 NUM_PROFILE_GAIA_METRICS); |
| 399 } | 404 } |
| 400 | 405 |
| 401 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { | 406 void ProfileMetrics::LogProfileSyncInfo(ProfileSync metric) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", | 552 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", |
| 548 GetProfileType(profile_path), | 553 GetProfileType(profile_path), |
| 549 NUM_PROFILE_TYPE_METRICS); | 554 NUM_PROFILE_TYPE_METRICS); |
| 550 } | 555 } |
| 551 | 556 |
| 552 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { | 557 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { |
| 553 UMA_HISTOGRAM_ENUMERATION("Profile.Update", | 558 UMA_HISTOGRAM_ENUMERATION("Profile.Update", |
| 554 GetProfileType(profile_path), | 559 GetProfileType(profile_path), |
| 555 NUM_PROFILE_TYPE_METRICS); | 560 NUM_PROFILE_TYPE_METRICS); |
| 556 } | 561 } |
| OLD | NEW |