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

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

Issue 1415223002: Add counts of User data to ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_info_cache.cc
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index f7e8b2b9dff8991e2583c48f556cf6a675e1d6ea..ff5e47056817865270936ed55d02fc90a3304b97 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -60,6 +60,7 @@ const char kSupervisedUserId[] = "managed_user_id";
const char kProfileIsEphemeral[] = "is_ephemeral";
const char kActiveTimeKey[] = "active_time";
const char kIsAuthErrorKey[] = "is_auth_error";
+const char kStatistics[] = "statistics";
anthonyvd 2015/10/23 15:53:13 nit: kStatisticsKey
lwchkg 2015/10/24 02:02:32 Acknowledged.
// First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME.
const int kDefaultNames[] = {
@@ -499,6 +500,49 @@ size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index)
return icon_index;
}
+
+bool ProfileInfoCache::GetStatisticOfProfileAtIndex(size_t index,
+ const std::string& category, int* out_value) const {
+ const base::DictionaryValue* statistics;
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion(
+ kStatistics, &statistics))
+ return false;
+
+ return statistics->GetIntegerWithoutPathExpansion(category, out_value);
+}
+
+std::map<std::string, int> ProfileInfoCache::GetAllStatisticOfProfileAtIndex(
+ size_t index) const {
+ const base::DictionaryValue* statistics;
+ std::map<std::string, int> out_value;
+
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion(
+ kStatistics, &statistics))
+ return out_value; // No statistics are set, so return an empty map.
+
+ for (base::DictionaryValue::Iterator it(*statistics); !it.IsAtEnd();
+ it.Advance()) {
+ int value;
+ if (it.value().GetAsInteger(&value)) {
+ out_value.insert(std::make_pair(it.key(), value));
+ }
+ }
+ return out_value;
+}
+
+scoped_ptr<base::DictionaryValue>
+ ProfileInfoCache::GetAllStatisticsOfProfileAtIndexAsDictionaryValue(
+ size_t index) const {
+ const base::DictionaryValue* statistics;
+
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion(
+ kStatistics, &statistics))
+ // No statistics are set, so return an empty map.
+ return make_scoped_ptr(new base::DictionaryValue()).Pass();
+
+ return statistics->CreateDeepCopy().Pass();
+}
+
void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) {
if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) <
base::TimeDelta::FromHours(1)) {
@@ -909,6 +953,27 @@ size_t ProfileInfoCache::ChooseAvatarIconIndexForNewProfile() const {
return 0;
}
+void ProfileInfoCache::SetStatisticOfProfileAtIndex(size_t index,
+ const std::string& category, int value) {
+ scoped_ptr<base::DictionaryValue> info(
+ GetInfoForProfileAtIndex(index)->DeepCopy());
+
+ base::DictionaryValue* statistics;
+ if (info->GetDictionaryWithoutPathExpansion(kStatistics, &statistics)) {
+ statistics = new base::DictionaryValue();
+ info->SetWithoutPathExpansion(kStatistics, make_scoped_ptr(statistics));
+ }
+
+ statistics->SetIntegerWithoutPathExpansion(category, value);
+ // This takes ownership of |info|.
+ SetInfoForProfileAtIndex(index, info.release());
+
+ base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+ FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+ observer_list_,
+ OnProfileSigninRequiredChanged(profile_path));
+}
+
const base::FilePath& ProfileInfoCache::GetUserDataDir() const {
return user_data_dir_;
}
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698