| Index: extensions/browser/extension_prefs.cc
|
| diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
|
| index 2850d418831f2a03453c96e09791a47289cdfa02..27ed323402a40c8c9fcb4570132487356181d82d 100644
|
| --- a/extensions/browser/extension_prefs.cc
|
| +++ b/extensions/browser/extension_prefs.cc
|
| @@ -190,6 +190,15 @@ const char kPrefInstallParam[] = "install_parameter";
|
| // A list of installed ids and a signature.
|
| const char kInstallSignature[] = "extensions.install_signature";
|
|
|
| +// A preference that stores the next threshold for displaying a notification
|
| +// when an extension or app consumes excessive disk space. This will not be
|
| +// set until the extension/app reaches the initial threshold.
|
| +const char kPrefNextStorageThreshold[] = "next_storage_threshold";
|
| +
|
| +// If this preference is set to true, notifications will be suppressed when an
|
| +// extension or app consumes excessive disk space.
|
| +const char kPrefDisableStorageNotifications[] = "disable_storage_notifications";
|
| +
|
| // Provider of write access to a dictionary storing extension prefs.
|
| class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
|
| public:
|
| @@ -873,28 +882,45 @@ bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const {
|
|
|
| namespace {
|
|
|
| +// Serializes a 64bit integer as a string value.
|
| +void SaveInt64(base::DictionaryValue* dictionary,
|
| + const char* key,
|
| + const int64 value) {
|
| + if (!dictionary)
|
| + return;
|
| +
|
| + std::string string_value = base::Int64ToString(value);
|
| + dictionary->SetString(key, string_value);
|
| +}
|
| +
|
| +// Deserializes a 64bit integer stored as a string value.
|
| +bool ReadInt64(const base::DictionaryValue* dictionary,
|
| + const char* key,
|
| + int64* value) {
|
| + if (!dictionary)
|
| + return false;
|
| +
|
| + std::string string_value;
|
| + if (!dictionary->GetString(key, &string_value))
|
| + return false;
|
| +
|
| + return base::StringToInt64(string_value, value);
|
| +}
|
| +
|
| // Serializes |time| as a string value mapped to |key| in |dictionary|.
|
| void SaveTime(base::DictionaryValue* dictionary,
|
| const char* key,
|
| const base::Time& time) {
|
| - if (!dictionary)
|
| - return;
|
| - std::string string_value = base::Int64ToString(time.ToInternalValue());
|
| - dictionary->SetString(key, string_value);
|
| + SaveInt64(dictionary, key, time.ToInternalValue());
|
| }
|
|
|
| // The opposite of SaveTime. If |key| is not found, this returns an empty Time
|
| // (is_null() will return true).
|
| base::Time ReadTime(const base::DictionaryValue* dictionary, const char* key) {
|
| - if (!dictionary)
|
| - return base::Time();
|
| - std::string string_value;
|
| int64 value;
|
| - if (dictionary->GetString(key, &string_value)) {
|
| - if (base::StringToInt64(string_value, &value)) {
|
| - return base::Time::FromInternalValue(value);
|
| - }
|
| - }
|
| + if (ReadInt64(dictionary, key, &value))
|
| + return base::Time::FromInternalValue(value);
|
| +
|
| return base::Time();
|
| }
|
|
|
| @@ -1877,6 +1903,45 @@ void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
|
| new base::StringValue(install_parameter));
|
| }
|
|
|
| +int64 ExtensionPrefs::GetNextStorageThreshold(
|
| + const std::string& extension_id) const {
|
| + int64 next_threshold;
|
| + if (ReadInt64(GetExtensionPref(extension_id),
|
| + kPrefNextStorageThreshold,
|
| + &next_threshold)) {
|
| + return next_threshold;
|
| + }
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +void ExtensionPrefs::SetNextStorageThreshold(const std::string& extension_id,
|
| + int64 next_threshold) {
|
| +
|
| + ScopedExtensionPrefUpdate update(prefs_, extension_id);
|
| + SaveInt64(update.Get(), kPrefNextStorageThreshold, next_threshold);
|
| +}
|
| +
|
| +bool ExtensionPrefs::StorageNotificationsEnabled(
|
| + const std::string& extension_id) const {
|
| + bool disable_notifications;
|
| + if (ReadPrefAsBoolean(extension_id,
|
| + kPrefDisableStorageNotifications,
|
| + &disable_notifications)) {
|
| + return !disable_notifications;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void ExtensionPrefs::SetStorageNotificationsEnabled(
|
| + const std::string& extension_id, bool enable_notifications) {
|
| + UpdateExtensionPref(
|
| + extension_id,
|
| + kPrefDisableStorageNotifications,
|
| + enable_notifications ? NULL : new base::FundamentalValue(true));
|
| +}
|
| +
|
| ExtensionPrefs::ExtensionPrefs(
|
| PrefService* prefs,
|
| const base::FilePath& root_dir,
|
|
|