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 Common prefs behavior. | 6 * @fileoverview Common prefs behavior. |
7 */ | 7 */ |
8 | 8 |
9 /** @polymerBehavior */ | 9 /** @polymerBehavior */ |
10 var PrefsBehavior = { | 10 var PrefsBehavior = { |
11 properties: { | 11 properties: { |
12 /** Preferences state. */ | 12 /** Preferences state. */ |
13 prefs: { | 13 prefs: { |
14 type: Object, | 14 type: Object, |
15 notify: true, | 15 notify: true, |
16 }, | 16 }, |
17 }, | 17 }, |
18 | 18 |
19 /** | 19 /** |
20 * Gets the pref at the given prefPath. Throws if the pref is not found. | 20 * Gets the pref at the given prefPath. Throws if the pref is not found. |
21 * @param {string} prefPath | 21 * @param {string} prefPath |
22 * @return {!chrome.settingsPrivate.PrefObject} | 22 * @return {!chrome.settingsPrivate.PrefObject} |
23 * @protected | 23 * @protected |
24 */ | 24 */ |
25 getPref: function(prefPath) { | 25 getPref: function(prefPath) { |
26 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */( | 26 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */ ( |
27 this.get(prefPath, this.prefs)); | 27 this.get(prefPath, this.prefs)); |
28 assert(typeof pref != 'undefined', 'Pref is missing: ' + prefPath); | 28 assert(typeof pref != 'undefined', 'Pref is missing: ' + prefPath); |
29 return pref; | 29 return pref; |
30 }, | 30 }, |
31 | 31 |
32 /** | 32 /** |
33 * Sets the value of the pref at the given prefPath. Throws if the pref is not | 33 * Sets the value of the pref at the given prefPath. Throws if the pref is not |
34 * found. | 34 * found. |
35 * @param {string} prefPath | 35 * @param {string} prefPath |
36 * @param {*} value | 36 * @param {*} value |
(...skipping 24 matching lines...) Expand all Loading... |
61 * Asserts if the pref itself is not found or is not an Array type. | 61 * Asserts if the pref itself is not found or is not an Array type. |
62 * @param {string} key | 62 * @param {string} key |
63 * @param {*} item | 63 * @param {*} item |
64 * @protected | 64 * @protected |
65 */ | 65 */ |
66 deletePrefListItem: function(key, item) { | 66 deletePrefListItem: function(key, item) { |
67 assert(this.getPref(key).type == chrome.settingsPrivate.PrefType.LIST); | 67 assert(this.getPref(key).type == chrome.settingsPrivate.PrefType.LIST); |
68 this.arrayDelete('prefs.' + key + '.value', item); | 68 this.arrayDelete('prefs.' + key + '.value', item); |
69 }, | 69 }, |
70 }; | 70 }; |
OLD | NEW |