| OLD | NEW |
| 1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. */ | 3 * found in the LICENSE file. */ |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-prefs' exposes a singleton model of Chrome settings and | 7 * 'settings-prefs' exposes a singleton model of Chrome settings and |
| 8 * preferences, which listens to changes to Chrome prefs whitelisted in | 8 * preferences, which listens to changes to Chrome prefs whitelisted in |
| 9 * chrome.settingsPrivate. When changing prefs in this element's 'prefs' | 9 * chrome.settingsPrivate. When changing prefs in this element's 'prefs' |
| 10 * property via the UI, the singleton model tries to set those preferences in | 10 * property via the UI, the singleton model tries to set those preferences in |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 * 'search.suggest_enabled'. | 274 * 'search.suggest_enabled'. |
| 275 * @param {string} path | 275 * @param {string} path |
| 276 * @return {string} | 276 * @return {string} |
| 277 * @private | 277 * @private |
| 278 */ | 278 */ |
| 279 getPrefKeyFromPath_: function(path) { | 279 getPrefKeyFromPath_: function(path) { |
| 280 // Skip the first token, which refers to the member variable (this.prefs). | 280 // Skip the first token, which refers to the member variable (this.prefs). |
| 281 var parts = path.split('.'); | 281 var parts = path.split('.'); |
| 282 assert(parts.shift() == 'prefs', "Path doesn't begin with 'prefs'"); | 282 assert(parts.shift() == 'prefs', "Path doesn't begin with 'prefs'"); |
| 283 | 283 |
| 284 for (let i = 1; i <= parts.length; i++) { | 284 for (var i = 1; i <= parts.length; i++) { |
| 285 let key = parts.slice(0, i).join('.'); | 285 var key = parts.slice(0, i).join('.'); |
| 286 // The lastPrefValues_ keys match the pref keys. | 286 // The lastPrefValues_ keys match the pref keys. |
| 287 if (this.lastPrefValues_.hasOwnProperty(key)) | 287 if (this.lastPrefValues_.hasOwnProperty(key)) |
| 288 return key; | 288 return key; |
| 289 } | 289 } |
| 290 return ''; | 290 return ''; |
| 291 }, | 291 }, |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * Resets the element so it can be re-initialized with a new prefs state. | 294 * Resets the element so it can be re-initialized with a new prefs state. |
| 295 */ | 295 */ |
| 296 resetForTesting: function() { | 296 resetForTesting: function() { |
| 297 if (!this.initialized_) | 297 if (!this.initialized_) |
| 298 return; | 298 return; |
| 299 this.prefs = undefined; | 299 this.prefs = undefined; |
| 300 this.lastPrefValues_ = {}; | 300 this.lastPrefValues_ = {}; |
| 301 this.initialized_ = false; | 301 this.initialized_ = false; |
| 302 // Remove the listener added in initialize(). | 302 // Remove the listener added in initialize(). |
| 303 this.settingsApi_.onPrefsChanged.removeListener(this.boundPrefsChanged_); | 303 this.settingsApi_.onPrefsChanged.removeListener(this.boundPrefsChanged_); |
| 304 this.settingsApi_ = | 304 this.settingsApi_ = |
| 305 /** @type {SettingsPrivate} */(chrome.settingsPrivate); | 305 /** @type {SettingsPrivate} */(chrome.settingsPrivate); |
| 306 }, | 306 }, |
| 307 }); | 307 }); |
| 308 })(); | 308 })(); |
| OLD | NEW |