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 * 'cr-settings-prefs' is an element which serves as a model for | 7 * 'cr-settings-prefs' is an element which serves as a model for |
8 * interaction with settings which are stored in Chrome's | 8 * interaction with settings which are stored in Chrome's |
9 * Preferences. | 9 * Preferences. |
10 * | 10 * |
(...skipping 26 matching lines...) Expand all Loading... |
37 created: function() { | 37 created: function() { |
38 CrSettingsPrefs.isInitialized = false; | 38 CrSettingsPrefs.isInitialized = false; |
39 | 39 |
40 chrome.settingsPrivate.onPrefsChanged.addListener( | 40 chrome.settingsPrivate.onPrefsChanged.addListener( |
41 this.onPrefsChanged_.bind(this)); | 41 this.onPrefsChanged_.bind(this)); |
42 chrome.settingsPrivate.getAllPrefs(this.onPrefsFetched_.bind(this)); | 42 chrome.settingsPrivate.getAllPrefs(this.onPrefsFetched_.bind(this)); |
43 }, | 43 }, |
44 | 44 |
45 /** | 45 /** |
46 * Called when prefs in the underlying Chrome pref store are changed. | 46 * Called when prefs in the underlying Chrome pref store are changed. |
47 * @param {!Array<!PrefObject>} prefs The prefs that changed. | 47 * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs The prefs that |
| 48 * changed. |
48 * @private | 49 * @private |
49 */ | 50 */ |
50 onPrefsChanged_: function(prefs) { | 51 onPrefsChanged_: function(prefs) { |
51 this.updatePrefs_(prefs, false); | 52 this.updatePrefs_(prefs, false); |
52 }, | 53 }, |
53 | 54 |
54 /** | 55 /** |
55 * Called when prefs are fetched from settingsPrivate. | 56 * Called when prefs are fetched from settingsPrivate. |
56 * @param {!Array<!PrefObject>} prefs | 57 * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs |
57 * @private | 58 * @private |
58 */ | 59 */ |
59 onPrefsFetched_: function(prefs) { | 60 onPrefsFetched_: function(prefs) { |
60 this.updatePrefs_(prefs, true); | 61 this.updatePrefs_(prefs, true); |
61 | 62 |
62 CrSettingsPrefs.isInitialized = true; | 63 CrSettingsPrefs.isInitialized = true; |
63 document.dispatchEvent(new Event(CrSettingsPrefs.INITIALIZED)); | 64 document.dispatchEvent(new Event(CrSettingsPrefs.INITIALIZED)); |
64 }, | 65 }, |
65 | 66 |
66 | 67 |
67 /** | 68 /** |
68 * Updates the settings model with the given prefs. | 69 * Updates the settings model with the given prefs. |
69 * @param {!Array<!PrefObject>} prefs | 70 * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs |
70 * @param {boolean} shouldObserve Whether each of the prefs should be | 71 * @param {boolean} shouldObserve Whether each of the prefs should be |
71 * observed. | 72 * observed. |
72 * @private | 73 * @private |
73 */ | 74 */ |
74 updatePrefs_: function(prefs, shouldObserve) { | 75 updatePrefs_: function(prefs, shouldObserve) { |
75 prefs.forEach(function(prefObj) { | 76 prefs.forEach(function(prefObj) { |
76 let root = this.prefStore; | 77 let root = this.prefStore; |
77 let tokens = prefObj.key.split('.'); | 78 let tokens = prefObj.key.split('.'); |
78 | 79 |
79 assert(tokens.length > 0); | 80 assert(tokens.length > 0); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 153 |
153 chrome.settingsPrivate.setPref( | 154 chrome.settingsPrivate.setPref( |
154 change.object['key'], | 155 change.object['key'], |
155 newValue, | 156 newValue, |
156 /* pageId */ '', | 157 /* pageId */ '', |
157 /* callback */ function() {}); | 158 /* callback */ function() {}); |
158 }); | 159 }); |
159 }, | 160 }, |
160 }); | 161 }); |
161 })(); | 162 })(); |
OLD | NEW |