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