| 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..961e4ccf527a81cd8588a63fe0a2cb5bcbc89b69 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(
|
| + const base::FilePath& profile_path) {
|
| + ProfileInfoCache& profile_info_cache =
|
| + g_browser_process->profile_manager()->GetProfileInfoCache();
|
| + ProfileAttributesEntry* entry = nullptr;
|
| + bool has_entry = profile_info_cache.
|
| + GetProfileAttributesWithPath(profile_path, &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 SetProfileStatisticsInCache(const base::FilePath& profile_path,
|
| + const std::string& category, int count) {
|
| + // If local_state() is null, profile_manager() will seg-fault.
|
| + if (!g_browser_process || !g_browser_process->local_state())
|
| + return;
|
| +
|
| + ProfileInfoCache& profile_info_cache =
|
| + g_browser_process->profile_manager()->GetProfileInfoCache();
|
| + ProfileAttributesEntry* entry = nullptr;
|
| + if (!profile_info_cache.GetProfileAttributesWithPath(profile_path, &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
|
|
|