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

Unified Diff: extensions/browser/extension_prefs.cc

Issue 221933013: Show a notification when an ephemeral app consumes excessive disk space (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkit_storage_monitor
Patch Set: Fix test failures Created 6 years, 8 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 | « extensions/browser/extension_prefs.h ('k') | ui/message_center/notification_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/extension_prefs.cc
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index 7cbf38cdce1f8697868a1719cbde3fc81561a8ee..05b7702c3b9b42d604ac22743499f4f57d15e368 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();
}
@@ -1875,6 +1901,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::IsStorageNotificationEnabled(
+ const std::string& extension_id) const {
+ bool disable_notifications;
+ if (ReadPrefAsBoolean(extension_id,
+ kPrefDisableStorageNotifications,
+ &disable_notifications)) {
+ return !disable_notifications;
+ }
+
+ return true;
+}
+
+void ExtensionPrefs::SetStorageNotificationEnabled(
+ 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,
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | ui/message_center/notification_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698