summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_prefs.cc
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 19:27:04 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 19:27:04 +0000
commit4033bd98373cff89138c81b14628eae592660336 (patch)
tree4f217064361298d5da8e0cc49e9f72be24493b93 /chrome/browser/extensions/extension_prefs.cc
parent8368e3c097978a1424e13786efceead3ffc6c385 (diff)
downloadchromium_src-4033bd98373cff89138c81b14628eae592660336.zip
chromium_src-4033bd98373cff89138c81b14628eae592660336.tar.gz
chromium_src-4033bd98373cff89138c81b14628eae592660336.tar.bz2
Send active ping days along with the rollcall ping days parameter.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6633003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_prefs.cc')
-rw-r--r--chrome/browser/extensions/extension_prefs.cc91
1 files changed, 64 insertions, 27 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 745d9fd..bf5a776 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -51,6 +51,12 @@ const char kExtensionToolbar[] = "extensions.toolbar";
// its update check.
const char kLastPingDay[] = "lastpingday";
+// Similar to kLastPingDay, but for "active" instead of "rollcall" pings.
+const char kLastActivePingDay[] = "last_active_pingday";
+
+// A bit we use to keep track of whether we need to do an "active" ping.
+const char kActiveBit[] = "active_bit";
+
// Path for settings specific to blacklist update.
const char kExtensionsBlacklistUpdate[] = "extensions.blacklistupdate";
@@ -464,11 +470,24 @@ void ExtensionPrefs::UpdateBlacklist(
return;
}
-Time ExtensionPrefs::LastPingDayImpl(const DictionaryValue* dictionary) const {
- if (dictionary && dictionary->HasKey(kLastPingDay)) {
- std::string string_value;
- int64 value;
- dictionary->GetString(kLastPingDay, &string_value);
+namespace {
+
+// Serializes |time| as a string value mapped to |key| in |dictionary|.
+void SaveTime(DictionaryValue* dictionary, const char* key, const Time& time) {
+ if (!dictionary)
+ return;
+ std::string string_value = base::Int64ToString(time.ToInternalValue());
+ dictionary->SetString(key, string_value);
+}
+
+// The opposite of SaveTime. If |key| is not found, this returns an empty Time
+// (is_null() will return true).
+Time ReadTime(const DictionaryValue* dictionary, const char* key) {
+ if (!dictionary)
+ return Time();
+ std::string string_value;
+ int64 value;
+ if (dictionary->GetString(key, &string_value)) {
if (base::StringToInt64(string_value, &value)) {
return Time::FromInternalValue(value);
}
@@ -476,35 +495,55 @@ Time ExtensionPrefs::LastPingDayImpl(const DictionaryValue* dictionary) const {
return Time();
}
-void ExtensionPrefs::SetLastPingDayImpl(const Time& time,
- DictionaryValue* dictionary) {
- if (!dictionary) {
- NOTREACHED();
- return;
- }
- std::string value = base::Int64ToString(time.ToInternalValue());
- dictionary->SetString(kLastPingDay, value);
- SavePrefsAndNotify();
-}
+} // namespace
Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const {
DCHECK(Extension::IdIsValid(extension_id));
- return LastPingDayImpl(GetExtensionPref(extension_id));
-}
-
-Time ExtensionPrefs::BlacklistLastPingDay() const {
- return LastPingDayImpl(prefs_->GetDictionary(kExtensionsBlacklistUpdate));
+ return ReadTime(GetExtensionPref(extension_id), kLastPingDay);
}
void ExtensionPrefs::SetLastPingDay(const std::string& extension_id,
const Time& time) {
DCHECK(Extension::IdIsValid(extension_id));
- SetLastPingDayImpl(time, GetExtensionPref(extension_id));
+ SaveTime(GetExtensionPref(extension_id), kLastPingDay, time);
+}
+
+Time ExtensionPrefs::BlacklistLastPingDay() const {
+ return ReadTime(prefs_->GetDictionary(kExtensionsBlacklistUpdate),
+ kLastPingDay);
}
void ExtensionPrefs::SetBlacklistLastPingDay(const Time& time) {
- SetLastPingDayImpl(time,
- prefs_->GetMutableDictionary(kExtensionsBlacklistUpdate));
+ SaveTime(prefs_->GetMutableDictionary(kExtensionsBlacklistUpdate),
+ kLastPingDay,
+ time);
+}
+
+Time ExtensionPrefs::LastActivePingDay(const std::string& extension_id) {
+ DCHECK(Extension::IdIsValid(extension_id));
+ return ReadTime(GetExtensionPref(extension_id), kLastActivePingDay);
+}
+
+void ExtensionPrefs::SetLastActivePingDay(const std::string& extension_id,
+ const base::Time& time) {
+ DCHECK(Extension::IdIsValid(extension_id));
+ SaveTime(GetExtensionPref(extension_id), kLastActivePingDay, time);
+}
+
+bool ExtensionPrefs::GetActiveBit(const std::string& extension_id) {
+ DictionaryValue* dictionary = GetExtensionPref(extension_id);
+ bool result = false;
+ if (dictionary && dictionary->GetBoolean(kActiveBit, &result))
+ return result;
+ return false;
+}
+
+void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
+ bool active) {
+ DictionaryValue* dictionary = GetExtensionPref(extension_id);
+ if (!dictionary)
+ return;
+ dictionary->SetBoolean(kActiveBit, active);
}
bool ExtensionPrefs::GetGrantedPermissions(
@@ -1139,8 +1178,7 @@ void ExtensionPrefs::SetAppLauncherOrder(
NotificationService::NoDetails());
}
-int ExtensionPrefs::GetPageIndex(const std::string& extension_id)
-{
+int ExtensionPrefs::GetPageIndex(const std::string& extension_id) {
int value;
if (ReadExtensionPrefInteger(extension_id, kPrefPageIndex, &value))
return value;
@@ -1148,8 +1186,7 @@ int ExtensionPrefs::GetPageIndex(const std::string& extension_id)
return -1;
}
-void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index)
-{
+void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) {
CHECK_GE(index, 0);
UpdateExtensionPref(extension_id, kPrefPageIndex,
Value::CreateIntegerValue(index));