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 9b311e84aa6336970fb326524d2f41cabd38ce0b..6c9c462bdc7b7e54b2bec78cfe158e4b48bf7597 100644 |
--- a/chrome/browser/resources/settings/prefs/prefs.js |
+++ b/chrome/browser/resources/settings/prefs/prefs.js |
@@ -52,7 +52,8 @@ PrefWrapper.prototype.equals = function(other) { |
function ListPrefWrapper(prefObj) { |
// Copy the array so changes to prefObj aren't reflected in this.value_. |
// TODO(michaelpg): Do a deep copy to support nested lists and objects. |
- this.value_ = prefObj.value.slice(); |
+ this.value_ = PrefWrapper.deepCopy(prefObj.value); |
+// this.value_ = prefObj.value.slice(); |
} |
ListPrefWrapper.prototype = { |
@@ -63,20 +64,85 @@ function ListPrefWrapper(prefObj) { |
* @override |
*/ |
equals: function(other) { |
- 'use strict'; |
assert(this.key_ == other.key_); |
- if (this.value_.length != other.value_.length) |
+ return PrefWrapper.objectsEqual(this.value_, other.value_); |
+ }, |
+}; |
+ |
+/** |
+ * @constructor |
+ * @extends {PrefWrapper} |
+ * @param {!chrome.settingsPrivate.PrefObject} prefObj |
+ */ |
+function DictPrefWrapper(prefObj) { |
+ // Copy the object so changes to prefObj aren't reflected in this.value_. |
+ // TODO(michaelpg): Do a deep copy to support nested lists and objects. |
+ this.value_ = prefObj.value.slice(); |
+} |
+ |
+ DictPrefWrapper.prototype = { |
+ __proto__: PrefWrapper.prototype, |
+ |
+ /** |
+ * Tests whether two DictPrefWrapper values contain the same list items. |
+ * @override |
+ */ |
+ equals: function(other) { |
+ assert(this.key_ == other.key_); |
+ return PrefWrapper.objectsEqual(this.value_, other.value_); |
+ }, |
+}; |
+ |
+(function() { |
+'use strict'; |
+ |
+PrefWrapper.objectsEqual = function(obj1, obj2) { |
+ if (Array.isArray(obj1)) { |
+ if (!Array.isArray(obj2)) |
+ return false; |
+ if (obj1.length != obj2.length) |
return false; |
- for (let i = 0; i < this.value_.length; i++) { |
- if (this.value_[i] != other.value_[i]) |
+ if (obj1 == obj2) { |
+ return true; |
+ } |
+ for (var i = 0; i < obj1.length; i++) { |
+ if (!PrefWrapper.objectsEqual(obj1[i], obj2[i])) { |
return false; |
+ } |
+ else if (typeof obj1[i] == 'object') { |
+ } |
} |
return true; |
- }, |
+ } |
+ if (typeof obj1 == 'object') { |
+ var props1 = Object.keys(obj1); |
+ var props2 = Object.keys(obj2); |
+ if (props1.length != props2.length) |
+ return false; |
+ for (var prop of props1) { |
+ if (!PrefWrapper.objectsEqual(obj1[prop], obj2[prop])) |
+ return false; |
+ } |
+ return true; |
+ } |
+ return obj1 == obj2; |
+}; |
+ |
+PrefWrapper.deepCopy = function(obj) { |
+ if (Array.isArray(obj)) { |
+ var copy = []; |
+ for (let el of obj) |
+ copy.push(PrefWrapper.deepCopy(el)); |
+ return copy; |
+ } |
+ if (typeof obj == 'object') { |
+ var copy = {}; |
+ for (let prop in obj) |
+ copy[prop] = PrefWrapper.deepCopy(obj[prop]); |
+ } |
+ return obj; |
}; |
-(function() { |
- 'use strict'; |
Polymer({ |
is: 'cr-settings-prefs', |
@@ -146,8 +212,11 @@ function ListPrefWrapper(prefObj) { |
// If settingsPrivate already has this value, do nothing. (Otherwise, |
// a change event from settingsPrivate could make us call |
// settingsPrivate.setPref and potentially trigger an IPC loop.) |
- if (prefWrapper.equals(this.createPrefWrapper_(prefObj))) |
+ // |
+ // this copy is a waste |
+ if (PrefWrapper.objectsEqual(prefWrapper.value_, this.createPrefWrapper_(prefObj).value_)) { |
return; |
+ } |
this.settingsApi_.setPref( |
key, |