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

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

Issue 1333473002: Support lists in <cr-settings-pref> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PrefsTests
Patch Set: Now with 100% more correctness 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 | « no previous file | chrome/test/data/webui/polymer_browser_test_base.js » ('j') | 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 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,
« no previous file with comments | « no previous file | chrome/test/data/webui/polymer_browser_test_base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698