Chromium Code Reviews| Index: chrome/browser/resources/settings/prefs/prefs_behavior.js |
| diff --git a/chrome/browser/resources/settings/prefs/prefs_behavior.js b/chrome/browser/resources/settings/prefs/prefs_behavior.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2a96d75c78bdaa3c8c2d908ebd037e354e895550 |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/prefs/prefs_behavior.js |
| @@ -0,0 +1,35 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Common prefs behavior. |
| + */ |
| + |
| +/** @polymerBehavior */ |
| +var PrefsBehavior = { |
| + /** |
| + * Gets the pref at the given prefPath. Throws if the pref is not found. |
| + * @param {string} prefPath |
| + * @return {!chrome.settingsPrivate.PrefObject} |
| + * @private |
| + */ |
| + getPref_: function(prefPath) { |
| + var pref = /** @type {!chrome.settingsPrivate.PrefObject} */( |
| + this.get(prefPath, this.prefs)); |
| + assert(typeof pref != 'undefined', 'Pref is missing: ' + prefPath); |
| + return pref; |
| + }, |
| + |
| + /** |
| + * Sets the value of the pref at the given prefPath. Throws if the pref is not |
| + * found. |
| + * @param {string} prefPath |
| + * @param {*} value |
| + * @private |
| + */ |
| + setPrefValue_: function(prefPath, value) { |
|
Dan Beam
2015/10/29 21:10:39
these should be @protected or public
Finnur
2015/10/30 12:13:46
Sure. Protected kind of makes sense in this contex
|
| + this.getPref_(prefPath); // Ensures we throw if the pref is not found. |
| + this.set('prefs.' + prefPath + '.value', value); |
| + }, |
| +}; |