Chromium Code Reviews| Index: chrome/browser/profiles/profile_statistics.cc |
| diff --git a/chrome/browser/profiles/profile_statistics.cc b/chrome/browser/profiles/profile_statistics.cc |
| index 88b48f933b5e55983e991439d07c35d720664c00..0ffa749700272be132851ec244f39c5b98263cdc 100644 |
| --- a/chrome/browser/profiles/profile_statistics.cc |
| +++ b/chrome/browser/profiles/profile_statistics.cc |
| @@ -10,8 +10,13 @@ |
| #include "base/task_runner.h" |
| #include "base/time/time.h" |
| #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/history/history_service_factory.h" |
| #include "chrome/browser/password_manager/password_store_factory.h" |
| +#include "chrome/browser/profiles/profile_attributes_entry.h" |
| +#include "chrome/browser/profiles/profile_attributes_storage.h" |
| +#include "chrome/browser/profiles/profile_info_cache.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| #include "components/bookmarks/browser/bookmark_model.h" |
| #include "components/history/core/browser/history_service.h" |
| #include "components/password_manager/core/browser/password_store.h" |
| @@ -24,7 +29,7 @@ namespace { |
| struct ProfileStatValue { |
| int count; |
| - bool success; // false means the statistics failed to load |
| + bool success; // false means the statistics failed to load |
| }; |
| int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { |
| @@ -263,4 +268,63 @@ void GetProfileStatistics(Profile* profile, |
| new ProfileStatisticsAggregator(profile, callback, tracker); |
| } |
| +ProfileCategoryStats GetProfileStatisticsFromCache(Profile* profile) { |
| + DCHECK(profile); |
| + |
| + ProfileInfoCache& profile_info_cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
|
lwchkg
2015/11/18 17:34:53
Wrong indent. Done.
|
| + ProfileAttributesEntry* entry = nullptr; |
| + bool has_entry = profile_info_cache. |
| + GetProfileAttributesWithPath(profile->GetPath(), &entry); |
| + |
| + ProfileCategoryStats stats; |
| + ProfileCategoryStat stat; |
| + |
| + stat.category = kProfileStatisticsBrowsingHistory; |
| + stat.success = has_entry ? entry->HasStatsBrowsingHistory() : false; |
| + stat.count = stat.success ? entry->GetStatsBrowsingHistory() : 0; |
| + stats.push_back(stat); |
| + |
| + stat.category = kProfileStatisticsPasswords; |
| + stat.success = has_entry ? entry->HasStatsPasswords() : false; |
| + stat.count = stat.success ? entry->GetStatsPasswords() : 0; |
| + stats.push_back(stat); |
| + |
| + stat.category = kProfileStatisticsBookmarks; |
| + stat.success = has_entry ? entry->HasStatsBookmarks() : false; |
| + stat.count = stat.success ? entry->GetStatsBookmarks() : 0; |
| + stats.push_back(stat); |
| + |
| + stat.category = kProfileStatisticsSettings; |
| + stat.success = has_entry ? entry->HasStatsSettings() : false; |
| + stat.count = stat.success ? entry->GetStatsSettings() : 0; |
| + stats.push_back(stat); |
| + |
| + return stats; |
| +} |
| + |
| +void StoreProfileStatisticsToCache(Profile* profile, |
| + const std::string& category, int count) { |
| + DCHECK(profile); |
| + |
| + ProfileInfoCache& profile_info_cache = |
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
|
lwchkg
2015/11/18 17:34:53
Wrong indent. Done.
|
| + ProfileAttributesEntry* entry = nullptr; |
| + if (!profile_info_cache.GetProfileAttributesWithPath( |
| + profile->GetPath(), &entry)) |
| + return; |
| + |
| + if (category == kProfileStatisticsBrowsingHistory) { |
| + entry->SetStatsBrowsingHistory(count); |
| + } else if (category == kProfileStatisticsPasswords) { |
| + entry->SetStatsPasswords(count); |
| + } else if (category == kProfileStatisticsBookmarks) { |
| + entry->SetStatsBookmarks(count); |
| + } else if (category == kProfileStatisticsSettings) { |
| + entry->SetStatsSettings(count); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| } // namespace profiles |