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..dc0ad67f8f4fb8290498edc7ca2adda2b59de457 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,50 @@ size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) |
return icon_index; |
} |
+int ProfileInfoCache::GetStatisticOfProfileAtIndex(size_t index, |
+ const std::string& category) const { |
+ const base::DictionaryValue* statistics; |
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( |
+ kStatisticsKey, &statistics)) |
+ return 0; |
+ |
+ int out_value; |
+ return statistics->GetIntegerWithoutPathExpansion(category, &out_value) ? |
+ out_value : 0; |
+} |
+ |
+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; |
+} |
+ |
+scoped_ptr<base::DictionaryValue> |
+ ProfileInfoCache::GetAllStatisticsOfProfileAtIndexAsDictionaryValue( |
+ size_t index) const { |
+ const base::DictionaryValue* statistics; |
+ |
+ if (!GetInfoForProfileAtIndex(index)->GetDictionaryWithoutPathExpansion( |
+ kStatisticsKey, &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 +954,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_; |
} |