summaryrefslogtreecommitdiffstats
path: root/extensions/browser/extension_prefs.cc
diff options
context:
space:
mode:
authortmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 14:10:16 +0000
committertmdiep@chromium.org <tmdiep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 14:10:16 +0000
commit657116ee6355f5d91d3ecc3e0762bd1678cdcb82 (patch)
treedd8c9ac0cfee72672b22ec07c1c93f7cd1ec61c0 /extensions/browser/extension_prefs.cc
parent44598b75a39ea0f166203d0fc7913532f5f1ba4c (diff)
downloadchromium_src-657116ee6355f5d91d3ecc3e0762bd1678cdcb82.zip
chromium_src-657116ee6355f5d91d3ecc3e0762bd1678cdcb82.tar.gz
chromium_src-657116ee6355f5d91d3ecc3e0762bd1678cdcb82.tar.bz2
Show a notification when an ephemeral app consumes excessive disk space
This patch introduces monitoring of the storage usage of extensions and apps that are granted unlimited storage. A notification is shown when persistent storage usage exceeds a threshold. Monitoring is implemented for all extensions and apps, but initially only enabled for ephemeral apps. Ephemeral apps have a lower threshold. BUG=347801 TEST=browser_tests (ExtensionStorageMonitor.*) Review URL: https://codereview.chromium.org/221933013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/extension_prefs.cc')
-rw-r--r--extensions/browser/extension_prefs.cc89
1 files changed, 77 insertions, 12 deletions
diff --git a/extensions/browser/extension_prefs.cc b/extensions/browser/extension_prefs.cc
index 7cbf38c..05b7702 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,