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

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

Issue 1346833003: Lazy init prefs in MD Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 | « chrome/browser/resources/settings/checkbox/checkbox.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.js
diff --git a/chrome/browser/resources/settings/prefs/prefs.js b/chrome/browser/resources/settings/prefs/prefs.js
index 98c82f78b5c4543a20fc1dd601e5bfabe98b010c..e2ac567c7cb42bbd2fb9a0aba1e182ed31f52529 100644
--- a/chrome/browser/resources/settings/prefs/prefs.js
+++ b/chrome/browser/resources/settings/prefs/prefs.js
@@ -87,7 +87,6 @@ function ListPrefWrapper(prefObj) {
*/
prefs: {
type: Object,
- value: function() { return {}; },
notify: true,
},
@@ -189,20 +188,26 @@ function ListPrefWrapper(prefObj) {
/**
* Updates the prefs model with the given prefs.
- * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs
+ * @param {!Array<!chrome.settingsPrivate.PrefObject>} newPrefs
* @private
*/
- updatePrefs_: function(prefs) {
- prefs.forEach(function(newPrefObj) {
+ updatePrefs_: function(newPrefs) {
+ // Use the existing prefs object or create it.
+ var prefs = this.prefs || {};
+ newPrefs.forEach(function(newPrefObj) {
// Use the PrefObject from settingsPrivate to create a PrefWrapper in
// prefWrappers_ at the pref's key.
this.prefWrappers_[newPrefObj.key] =
this.createPrefWrapper_(newPrefObj);
- // Set or update the pref in |prefs|. This triggers observers in the UI,
- // which update controls associated with the pref.
- this.setPref_(newPrefObj);
+ // Add the pref to |prefs|.
+ cr.exportPath(newPrefObj.key, newPrefObj, prefs);
+ // If this.prefs already exists, notify listeners of the change.
+ if (prefs == this.prefs)
+ this.notifyPath('prefs.' + newPrefObj.key, newPrefObj);
}, this);
+ if (!this.prefs)
+ this.prefs = prefs;
},
/**
@@ -229,27 +234,6 @@ function ListPrefWrapper(prefObj) {
},
/**
- * Sets or updates the pref denoted by newPrefObj.key in the publicy exposed
- * |prefs| property.
- * @param {chrome.settingsPrivate.PrefObject} newPrefObj The pref object to
- * update the pref with.
- * @private
- */
- setPref_: function(newPrefObj) {
- // Check if the pref exists already in the Polymer |prefs| object.
- if (this.get(newPrefObj.key, this.prefs)) {
- // Update just the value, notifying listeners of the change.
- this.set('prefs.' + newPrefObj.key + '.value', newPrefObj.value);
- } else {
- // Add the pref to |prefs|. cr.exportPath doesn't use Polymer.Base.set,
- // which is OK because the nested property update events aren't useful.
- cr.exportPath(newPrefObj.key, newPrefObj, this.prefs);
- // Notify listeners of the change at the preference key.
- this.notifyPath('prefs.' + newPrefObj.key, newPrefObj);
- }
- },
-
- /**
* Creates a PrefWrapper object from a chrome.settingsPrivate pref.
* @param {!chrome.settingsPrivate.PrefObject} prefObj
* PrefObject received from chrome.settingsPrivate.
« no previous file with comments | « chrome/browser/resources/settings/checkbox/checkbox.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698