| 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 <vector> |
| 8 |
| 7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 16 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/signin/chrome_signin_helper.h" | 18 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/installer/util/google_update_settings.h" | 21 #include "chrome/installer/util/google_update_settings.h" |
| 19 #include "components/profile_metrics/counts.h" | 22 #include "components/profile_metrics/counts.h" |
| 20 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 if (manager) { | 70 if (manager) { |
| 68 user_data_dir = manager->user_data_dir(); | 71 user_data_dir = manager->user_data_dir(); |
| 69 } | 72 } |
| 70 if (profile_path == user_data_dir.AppendASCII(chrome::kInitialProfile)) { | 73 if (profile_path == user_data_dir.AppendASCII(chrome::kInitialProfile)) { |
| 71 metric = ProfileMetrics::ORIGINAL; | 74 metric = ProfileMetrics::ORIGINAL; |
| 72 } | 75 } |
| 73 return metric; | 76 return metric; |
| 74 } | 77 } |
| 75 | 78 |
| 76 void LogLockedProfileInformation(ProfileManager* manager) { | 79 void LogLockedProfileInformation(ProfileManager* manager) { |
| 77 const ProfileInfoCache& info_cache = manager->GetProfileInfoCache(); | |
| 78 size_t number_of_profiles = info_cache.GetNumberOfProfiles(); | |
| 79 | |
| 80 base::Time now = base::Time::Now(); | 80 base::Time now = base::Time::Now(); |
| 81 const int kMinutesInProfileValidDuration = | 81 const int kMinutesInProfileValidDuration = |
| 82 base::TimeDelta::FromDays(28).InMinutes(); | 82 base::TimeDelta::FromDays(28).InMinutes(); |
| 83 for (size_t i = 0; i < number_of_profiles; ++i) { | 83 std::vector<ProfileAttributesEntry*> entries = |
| 84 manager->GetProfileAttributesStorage().GetAllProfilesAttributes(); |
| 85 for (ProfileAttributesEntry* entry : entries) { |
| 84 // Find when locked profiles were locked | 86 // Find when locked profiles were locked |
| 85 if (info_cache.ProfileIsSigninRequiredAtIndex(i)) { | 87 if (entry->IsSigninRequired()) { |
| 86 base::TimeDelta time_since_lock = now - | 88 base::TimeDelta time_since_lock = now - entry->GetActiveTime(); |
| 87 info_cache.GetProfileActiveTimeAtIndex(i); | |
| 88 // Specifying 100 buckets for the histogram to get a higher level of | 89 // Specifying 100 buckets for the histogram to get a higher level of |
| 89 // granularity in the reported data, given the large number of possible | 90 // granularity in the reported data, given the large number of possible |
| 90 // values (kMinutesInProfileValidDuration > 40,000). | 91 // values (kMinutesInProfileValidDuration > 40,000). |
| 91 UMA_HISTOGRAM_CUSTOM_COUNTS("Profile.LockedProfilesDuration", | 92 UMA_HISTOGRAM_CUSTOM_COUNTS("Profile.LockedProfilesDuration", |
| 92 time_since_lock.InMinutes(), | 93 time_since_lock.InMinutes(), |
| 93 1, | 94 1, |
| 94 kMinutesInProfileValidDuration, | 95 kMinutesInProfileValidDuration, |
| 95 100); | 96 100); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool HasProfileAtIndexBeenActiveSince(const ProfileInfoCache& info_cache, | 101 bool HasProfileBeenActiveSince(const ProfileAttributesEntry* entry, |
| 101 int index, | 102 const base::Time& active_limit) { |
| 102 const base::Time& active_limit) { | |
| 103 #if !defined(OS_ANDROID) | 103 #if !defined(OS_ANDROID) |
| 104 // TODO(mlerman): iOS and Android should set an ActiveTime in the | 104 // TODO(mlerman): iOS and Android should set an ActiveTime in the |
| 105 // ProfileInfoCache. (see ProfileManager::OnBrowserSetLastActive) | 105 // ProfileAttributesStorage. (see ProfileManager::OnBrowserSetLastActive) |
| 106 if (info_cache.GetProfileActiveTimeAtIndex(index) < active_limit) | 106 if (entry->GetActiveTime() < active_limit) |
| 107 return false; | 107 return false; |
| 108 #endif | 108 #endif |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 enum ProfileAvatar { | 114 enum ProfileAvatar { |
| 115 AVATAR_GENERIC = 0, // The names for avatar icons | 115 AVATAR_GENERIC = 0, // The names for avatar icons |
| 116 AVATAR_GENERIC_AQUA, | 116 AVATAR_GENERIC_AQUA, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 139 AVATAR_NOTE, | 139 AVATAR_NOTE, |
| 140 AVATAR_SUN_CLOUD, | 140 AVATAR_SUN_CLOUD, |
| 141 AVATAR_PLACEHOLDER, | 141 AVATAR_PLACEHOLDER, |
| 142 AVATAR_UNKNOWN, // 27 | 142 AVATAR_UNKNOWN, // 27 |
| 143 AVATAR_GAIA, // 28 | 143 AVATAR_GAIA, // 28 |
| 144 NUM_PROFILE_AVATAR_METRICS | 144 NUM_PROFILE_AVATAR_METRICS |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 bool ProfileMetrics::CountProfileInformation(ProfileManager* manager, | 147 bool ProfileMetrics::CountProfileInformation(ProfileManager* manager, |
| 148 profile_metrics::Counts* counts) { | 148 profile_metrics::Counts* counts) { |
| 149 const ProfileInfoCache& info_cache = manager->GetProfileInfoCache(); | 149 ProfileAttributesStorage& storage = manager->GetProfileAttributesStorage(); |
| 150 size_t number_of_profiles = info_cache.GetNumberOfProfiles(); | 150 size_t number_of_profiles = storage.GetNumberOfProfiles(); |
| 151 counts->total = number_of_profiles; | 151 counts->total = number_of_profiles; |
| 152 | 152 |
| 153 // Ignore other metrics if we have no profiles. | 153 // Ignore other metrics if we have no profiles. |
| 154 if (!number_of_profiles) | 154 if (!number_of_profiles) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 // Maximum age for "active" profile is 4 weeks. | 157 // Maximum age for "active" profile is 4 weeks. |
| 158 base::Time oldest = base::Time::Now() - | 158 base::Time oldest = base::Time::Now() - |
| 159 base::TimeDelta::FromDays(kMaximumDaysOfDisuse); | 159 base::TimeDelta::FromDays(kMaximumDaysOfDisuse); |
| 160 | 160 |
| 161 for (size_t i = 0; i < number_of_profiles; ++i) { | 161 std::vector<ProfileAttributesEntry*> entries = |
| 162 if (!HasProfileAtIndexBeenActiveSince(info_cache, i, oldest)) { | 162 storage.GetAllProfilesAttributes(); |
| 163 for (ProfileAttributesEntry* entry : entries) { |
| 164 if (!HasProfileBeenActiveSince(entry, oldest)) { |
| 163 counts->unused++; | 165 counts->unused++; |
| 164 } else { | 166 } else { |
| 165 if (info_cache.ProfileIsSupervisedAtIndex(i)) | 167 if (entry->IsSupervised()) |
| 166 counts->supervised++; | 168 counts->supervised++; |
| 167 if (info_cache.ProfileIsAuthenticatedAtIndex(i)) { | 169 if (entry->IsAuthenticated()) { |
| 168 counts->signedin++; | 170 counts->signedin++; |
| 169 if (info_cache.IsUsingGAIAPictureOfProfileAtIndex(i)) | 171 if (entry->IsUsingGAIAPicture()) |
| 170 counts->gaia_icon++; | 172 counts->gaia_icon++; |
| 171 if (info_cache.ProfileIsAuthErrorAtIndex(i)) | 173 if (entry->IsAuthError()) |
| 172 counts->auth_errors++; | 174 counts->auth_errors++; |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 } | 177 } |
| 176 return true; | 178 return true; |
| 177 } | 179 } |
| 178 | 180 |
| 179 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { | 181 void ProfileMetrics::UpdateReportedProfilesStatistics(ProfileManager* manager) { |
| 180 #if defined(OS_WIN) || defined(OS_MACOSX) | 182 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 181 profile_metrics::Counts counts; | 183 profile_metrics::Counts counts; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", | 544 UMA_HISTOGRAM_ENUMERATION("Profile.SyncSignIn", |
| 543 GetProfileType(profile_path), | 545 GetProfileType(profile_path), |
| 544 NUM_PROFILE_TYPE_METRICS); | 546 NUM_PROFILE_TYPE_METRICS); |
| 545 } | 547 } |
| 546 | 548 |
| 547 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { | 549 void ProfileMetrics::LogProfileUpdate(const base::FilePath& profile_path) { |
| 548 UMA_HISTOGRAM_ENUMERATION("Profile.Update", | 550 UMA_HISTOGRAM_ENUMERATION("Profile.Update", |
| 549 GetProfileType(profile_path), | 551 GetProfileType(profile_path), |
| 550 NUM_PROFILE_TYPE_METRICS); | 552 NUM_PROFILE_TYPE_METRICS); |
| 551 } | 553 } |
| OLD | NEW |