Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1770)

Unified Diff: chrome/browser/profiles/profile_statistics.cc

Issue 1415223002: Add counts of User data to ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added methods in profile_statistics.cc to access ProfileInfoCache, fixed a few style errors Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698