Commit aefbc80f authored by rbpotter's avatar rbpotter Committed by Commit Bot

Settings: Remove usage of exportPath

- Replace exportPath() with updatePrefPath_() in prefs.js
- Make exportPath() fully private in cr.js and remove parameters that
  are only used from prefs.js.

Bug: 1026426
Change-Id: I58e1da64902ee07ad4298060544056d16cce3413
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056609Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741701}
parent e79fc8e1
......@@ -25,7 +25,6 @@ js_library("prefs") {
":pref_util",
":prefs_behavior",
":prefs_types",
"//ui/webui/resources/js:cr",
]
externs_list = [ "$externs_path/settings_private.js" ]
extra_sources = [ "$interfaces_path/settings_private_interface.js" ]
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/html/assert.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="prefs_types.html">
<script src="prefs.js"></script>
......@@ -265,6 +265,31 @@ Polymer({
});
},
/**
* Builds an object structure for the provided |path| within |prefsObject|,
* ensuring that names that already exist are not overwritten. For example:
* "a.b.c" -> a = {};a.b={};a.b.c={};
* @param {string} path Path to the new pref value.
* @param {*} value The value to expose at the end of the path.
* @param {Object} prefsObject The prefs object to add the path to.
* @private
*/
updatePrefPath_(path, value, prefsObject) {
const parts = path.split('.');
let cur = prefsObject;
for (let part; parts.length && (part = parts.shift());) {
if (!parts.length) {
// last part, set the value.
cur[part] = value;
} else if (part in cur) {
cur = cur[part];
} else {
cur = cur[part] = {};
}
}
},
/**
* Updates the prefs model with the given prefs.
* @param {!Array<!chrome.settingsPrivate.PrefObject>} newPrefs
......@@ -280,7 +305,7 @@ Polymer({
if (!deepEqual(this.get(newPrefObj.key, prefs), newPrefObj)) {
// Add the pref to |prefs|.
cr.exportPath(newPrefObj.key, newPrefObj, prefs);
this.updatePrefPath_(newPrefObj.key, newPrefObj, prefs);
// If this.prefs already exists, notify listeners of the change.
if (prefs == this.prefs) {
this.notifyPath('prefs.' + newPrefObj.key, newPrefObj);
......
......@@ -17,22 +17,16 @@ var cr = cr || function(global) {
* example:
* "a.b.c" -> a = {};a.b={};a.b.c={};
* @param {string} name Name of the object that this file defines.
* @param {*=} opt_object The object to expose at the end of the path.
* @param {Object=} opt_objectToExportTo The object to add the path to;
* default is {@code global}.
* @return {!Object} The last object exported (i.e. exportPath('cr.ui')
* returns a reference to the ui property of window.cr).
* @private
*/
function exportPath(name, opt_object, opt_objectToExportTo) {
function exportPath(name) {
const parts = name.split('.');
let cur = opt_objectToExportTo || global;
let cur = global;
for (let part; parts.length && (part = parts.shift());) {
if (!parts.length && opt_object !== undefined) {
// last part and we have an object; use it
cur[part] = opt_object;
} else if (part in cur) {
if (part in cur) {
cur = cur[part];
} else {
cur = cur[part] = {};
......@@ -423,7 +417,6 @@ var cr = cr || function(global) {
defineProperty: defineProperty,
dispatchPropertyChange: dispatchPropertyChange,
dispatchSimpleEvent: dispatchSimpleEvent,
exportPath: exportPath,
PropertyKind: PropertyKind,
// C++ <-> JS communication related methods.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment