| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.Settings = class { | 34 WebInspector.Settings = class { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.SettingsStorage} storage | 36 * @param {!WebInspector.SettingsStorage} globalStorage |
| 37 * @param {!WebInspector.SettingsStorage} localStorage |
| 37 */ | 38 */ |
| 38 constructor(storage) { | 39 constructor(globalStorage, localStorage) { |
| 39 this._settingsStorage = storage; | 40 this._settingsStorage = globalStorage; |
| 40 var clearLocalStorage = window.localStorage ? window.localStorage.clear.bind
(window.localStorage) : undefined; | 41 this._localStorage = localStorage; |
| 41 this._localStorage = | |
| 42 new WebInspector.SettingsStorage(window.localStorage || {}, undefined, u
ndefined, clearLocalStorage); | |
| 43 | 42 |
| 44 this._eventSupport = new WebInspector.Object(); | 43 this._eventSupport = new WebInspector.Object(); |
| 45 /** @type {!Map<string, !WebInspector.Setting>} */ | 44 /** @type {!Map<string, !WebInspector.Setting>} */ |
| 46 this._registry = new Map(); | 45 this._registry = new Map(); |
| 47 /** @type {!Map<string, !WebInspector.Setting>} */ | 46 /** @type {!Map<string, !WebInspector.Setting>} */ |
| 48 this._moduleSettings = new Map(); | 47 this._moduleSettings = new Map(); |
| 49 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind(
this)); | 48 self.runtime.extensions('setting').forEach(this._registerModuleSetting.bind(
this)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 /** | 51 /** |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 133 |
| 135 /** | 134 /** |
| 136 * @unrestricted | 135 * @unrestricted |
| 137 */ | 136 */ |
| 138 WebInspector.SettingsStorage = class { | 137 WebInspector.SettingsStorage = class { |
| 139 /** | 138 /** |
| 140 * @param {!Object} object | 139 * @param {!Object} object |
| 141 * @param {function(string, string)=} setCallback | 140 * @param {function(string, string)=} setCallback |
| 142 * @param {function(string)=} removeCallback | 141 * @param {function(string)=} removeCallback |
| 143 * @param {function(string)=} removeAllCallback | 142 * @param {function(string)=} removeAllCallback |
| 143 * @param {string=} storagePrefix |
| 144 */ | 144 */ |
| 145 constructor(object, setCallback, removeCallback, removeAllCallback) { | 145 constructor(object, setCallback, removeCallback, removeAllCallback, storagePre
fix) { |
| 146 this._object = object; | 146 this._object = object; |
| 147 this._setCallback = setCallback || function() {}; | 147 this._setCallback = setCallback || function() {}; |
| 148 this._removeCallback = removeCallback || function() {}; | 148 this._removeCallback = removeCallback || function() {}; |
| 149 this._removeAllCallback = removeAllCallback || function() {}; | 149 this._removeAllCallback = removeAllCallback || function() {}; |
| 150 this._storagePrefix = storagePrefix || ''; |
| 150 } | 151 } |
| 151 | 152 |
| 152 /** | 153 /** |
| 153 * @param {string} name | 154 * @param {string} name |
| 154 * @param {string} value | 155 * @param {string} value |
| 155 */ | 156 */ |
| 156 set(name, value) { | 157 set(name, value) { |
| 158 name = this._storagePrefix + name; |
| 157 this._object[name] = value; | 159 this._object[name] = value; |
| 158 this._setCallback(name, value); | 160 this._setCallback(name, value); |
| 159 } | 161 } |
| 160 | 162 |
| 161 /** | 163 /** |
| 162 * @param {string} name | 164 * @param {string} name |
| 163 * @return {boolean} | 165 * @return {boolean} |
| 164 */ | 166 */ |
| 165 has(name) { | 167 has(name) { |
| 168 name = this._storagePrefix + name; |
| 166 return name in this._object; | 169 return name in this._object; |
| 167 } | 170 } |
| 168 | 171 |
| 169 /** | 172 /** |
| 170 * @param {string} name | 173 * @param {string} name |
| 171 * @return {string} | 174 * @return {string} |
| 172 */ | 175 */ |
| 173 get(name) { | 176 get(name) { |
| 177 name = this._storagePrefix + name; |
| 174 return this._object[name]; | 178 return this._object[name]; |
| 175 } | 179 } |
| 176 | 180 |
| 177 /** | 181 /** |
| 178 * @param {string} name | 182 * @param {string} name |
| 179 */ | 183 */ |
| 180 remove(name) { | 184 remove(name) { |
| 185 name = this._storagePrefix + name; |
| 181 delete this._object[name]; | 186 delete this._object[name]; |
| 182 this._removeCallback(name); | 187 this._removeCallback(name); |
| 183 } | 188 } |
| 184 | 189 |
| 185 removeAll() { | 190 removeAll() { |
| 186 this._object = {}; | 191 this._object = {}; |
| 187 this._removeAllCallback(); | 192 this._removeAllCallback(); |
| 188 } | 193 } |
| 189 | 194 |
| 190 _dumpSizes() { | 195 _dumpSizes() { |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 return WebInspector.settings.moduleSetting(settingName); | 735 return WebInspector.settings.moduleSetting(settingName); |
| 731 }; | 736 }; |
| 732 | 737 |
| 733 /** | 738 /** |
| 734 * @param {string} settingName | 739 * @param {string} settingName |
| 735 * @return {!WebInspector.Setting} | 740 * @return {!WebInspector.Setting} |
| 736 */ | 741 */ |
| 737 WebInspector.settingForTest = function(settingName) { | 742 WebInspector.settingForTest = function(settingName) { |
| 738 return WebInspector.settings.settingForTest(settingName); | 743 return WebInspector.settings.settingForTest(settingName); |
| 739 }; | 744 }; |
| OLD | NEW |