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 fd71e1779060269b5b2252fde7f7cb57e7becae7..3827b5af012ce5d0430056620643dd004e9a9b1e 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 kStatisticsKey[] = "statistics"; |
// First eight are generic icons, which use IDS_NUMBERED_PROFILE_NAME. |
const int kDefaultNames[] = { |
@@ -499,6 +500,35 @@ 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( |
+ kStatisticsKey, &statistics)) |
+ return false; |
+ |
+ return statistics->GetIntegerWithoutPathExpansion(category, out_value); |
+} |
+ |
+std::map<std::string, int> ProfileInfoCache::GetAllStatisticsOfProfileAtIndex( |
+ size_t index) const { |
+ const base::DictionaryValue* statistics; |
+ std::map<std::string, int> out_value; |
+ |
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( |
+ kStatisticsKey, &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[it.key()] = value; |
+ } |
+ } |
+ return out_value; |
+} |
+ |
void ProfileInfoCache::SetProfileActiveTimeAtIndex(size_t index) { |
if (base::Time::Now() - GetProfileActiveTimeAtIndex(index) < |
base::TimeDelta::FromHours(1)) { |
@@ -909,6 +939,21 @@ 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(kStatisticsKey, &statistics)) { |
+ statistics = new base::DictionaryValue(); |
+ info->SetWithoutPathExpansion(kStatisticsKey, make_scoped_ptr(statistics)); |
+ } |
+ |
+ statistics->SetIntegerWithoutPathExpansion(category, value); |
+ // This takes ownership of |info|. |
+ SetInfoForProfileAtIndex(index, info.release()); |
+} |
+ |
const base::FilePath& ProfileInfoCache::GetUserDataDir() const { |
return user_data_dir_; |
} |