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

Unified Diff: chrome/browser/resources/settings/prefs/prefs_behavior.js

Issue 1408753005: MD Settings: Factor out some pref manipulation into the PrefsBehavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@LanguagePage6LanguageHelper
Patch Set: rebase Created 5 years 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 | « chrome/browser/resources/settings/languages_page/languages.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/prefs/prefs_behavior.js
diff --git a/chrome/browser/resources/settings/prefs/prefs_behavior.js b/chrome/browser/resources/settings/prefs/prefs_behavior.js
index 5a4c15d379b9112b08205b1b528a410c0024dc50..8c9446000eff99dfe1d3c4ef2970328a52305880 100644
--- a/chrome/browser/resources/settings/prefs/prefs_behavior.js
+++ b/chrome/browser/resources/settings/prefs/prefs_behavior.js
@@ -32,4 +32,31 @@ var PrefsBehavior = {
this.getPref(prefPath); // Ensures we throw if the pref is not found.
this.set('prefs.' + prefPath + '.value', value);
},
+
+ /**
+ * Appends the item to the pref list at the given key if the item is not
+ * already in the list. Asserts if the pref itself is not found or is not an
+ * Array type.
+ * @param {string} key
+ * @param {*} item
+ * @protected
+ */
+ appendPrefListItem: function(key, item) {
+ var pref = this.getPref(key);
+ assert(pref && pref.type == chrome.settingsPrivate.PrefType.LIST);
+ if (pref.value.indexOf(item) == -1)
+ this.push('prefs.' + key + '.value', item);
+ },
+
+ /**
+ * Deletes the given item from the pref at the given key if the item is found.
+ * Asserts if the pref itself is not found or is not an Array type.
+ * @param {string} key
+ * @param {*} item
+ * @protected
+ */
+ deletePrefListItem: function(key, item) {
+ assert(this.getPref(key).type == chrome.settingsPrivate.PrefType.LIST);
+ this.arrayDelete('prefs.' + key + '.value', item);
+ },
};
« no previous file with comments | « chrome/browser/resources/settings/languages_page/languages.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698