Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @param {!Runtime.Extension} extension | 52 * @param {!Runtime.Extension} extension |
| 53 */ | 53 */ |
| 54 _registerModuleSetting(extension) { | 54 _registerModuleSetting(extension) { |
| 55 var descriptor = extension.descriptor(); | 55 var descriptor = extension.descriptor(); |
| 56 var settingName = descriptor['settingName']; | 56 var settingName = descriptor['settingName']; |
| 57 var settingType = descriptor['settingType']; | 57 var settingType = descriptor['settingType']; |
| 58 var defaultValue = descriptor['defaultValue']; | 58 var defaultValue = descriptor['defaultValue']; |
| 59 var isLocal = !!descriptor['local']; | 59 var isLocal = !!descriptor['local']; |
| 60 var setting = settingType === 'regex' ? this.createRegExpSetting(settingName , defaultValue, undefined, isLocal) : | 60 var isRegex = settingType === 'regex'; |
|
pfeldman
2017/02/13 20:24:54
revert
luoe
2017/02/13 22:18:26
Done.
| |
| 61 this.createSetting(settingName, defa ultValue, isLocal); | 61 var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, isLocal) : |
| 62 this.createSetting(settingName, defaultValue, isLoca l); | |
| 63 if (descriptor['title']) | |
| 64 setting.setTitle(descriptor['title']); | |
| 62 this._moduleSettings.set(settingName, setting); | 65 this._moduleSettings.set(settingName, setting); |
| 63 } | 66 } |
| 64 | 67 |
| 65 /** | 68 /** |
| 66 * @param {string} settingName | 69 * @param {string} settingName |
| 67 * @return {!Common.Setting} | 70 * @return {!Common.Setting} |
| 68 */ | 71 */ |
| 69 moduleSetting(settingName) { | 72 moduleSetting(settingName) { |
| 70 var setting = this._moduleSettings.get(settingName); | 73 var setting = this._moduleSettings.get(settingName); |
| 71 if (!setting) | 74 if (!setting) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 85 } | 88 } |
| 86 | 89 |
| 87 /** | 90 /** |
| 88 * @param {string} key | 91 * @param {string} key |
| 89 * @param {*} defaultValue | 92 * @param {*} defaultValue |
| 90 * @param {boolean=} isLocal | 93 * @param {boolean=} isLocal |
| 91 * @return {!Common.Setting} | 94 * @return {!Common.Setting} |
| 92 */ | 95 */ |
| 93 createSetting(key, defaultValue, isLocal) { | 96 createSetting(key, defaultValue, isLocal) { |
| 94 if (!this._registry.get(key)) { | 97 if (!this._registry.get(key)) { |
| 95 this._registry.set( | 98 var setting = new Common.Setting( |
|
pfeldman
2017/02/13 20:24:54
revert
luoe
2017/02/13 22:18:26
Done.
| |
| 96 key, new Common.Setting( | 99 this, key, defaultValue, this._eventSupport, isLocal ? this._localStor age : this._settingsStorage); |
| 97 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage)); | 100 this._registry.set(key, setting); |
| 98 } | 101 } |
| 99 return /** @type {!Common.Setting} */ (this._registry.get(key)); | 102 return /** @type {!Common.Setting} */ (this._registry.get(key)); |
| 100 } | 103 } |
| 101 | 104 |
| 102 /** | 105 /** |
| 103 * @param {string} key | 106 * @param {string} key |
| 104 * @param {*} defaultValue | 107 * @param {*} defaultValue |
| 105 * @return {!Common.Setting} | 108 * @return {!Common.Setting} |
| 106 */ | 109 */ |
| 107 createLocalSetting(key, defaultValue) { | 110 createLocalSetting(key, defaultValue) { |
| 108 return this.createSetting(key, defaultValue, true); | 111 return this.createSetting(key, defaultValue, true); |
| 109 } | 112 } |
| 110 | 113 |
| 111 /** | 114 /** |
| 112 * @param {string} key | 115 * @param {string} key |
| 113 * @param {string} defaultValue | 116 * @param {string} defaultValue |
| 114 * @param {string=} regexFlags | 117 * @param {string=} regexFlags |
| 115 * @param {boolean=} isLocal | 118 * @param {boolean=} isLocal |
| 116 * @return {!Common.RegExpSetting} | 119 * @return {!Common.RegExpSetting} |
| 117 */ | 120 */ |
| 118 createRegExpSetting(key, defaultValue, regexFlags, isLocal) { | 121 createRegExpSetting(key, defaultValue, regexFlags, isLocal) { |
| 119 if (!this._registry.get(key)) { | 122 if (!this._registry.get(key)) { |
| 120 this._registry.set( | 123 var setting = new Common.RegExpSetting( |
|
pfeldman
2017/02/13 20:24:54
ditto
luoe
2017/02/13 22:18:26
Done.
| |
| 121 key, new Common.RegExpSetting( | 124 this, key, defaultValue, this._eventSupport, isLocal ? this._localStor age : this._settingsStorage, |
| 122 this, key, defaultValue, this._eventSupport, isLocal ? this._ localStorage : this._settingsStorage, | 125 regexFlags); |
| 123 regexFlags)); | 126 this._registry.set(key, setting); |
| 124 } | 127 } |
| 125 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); | 128 return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); |
| 126 } | 129 } |
| 127 | 130 |
| 128 clearAll() { | 131 clearAll() { |
| 129 this._settingsStorage.removeAll(); | 132 this._settingsStorage.removeAll(); |
| 130 this._localStorage.removeAll(); | 133 this._localStorage.removeAll(); |
| 131 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0); | 134 var versionSetting = Common.settings.createSetting(Common.VersionController. _currentVersionName, 0); |
| 132 versionSetting.set(Common.VersionController.currentVersion); | 135 versionSetting.set(Common.VersionController.currentVersion); |
| 133 } | 136 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 * @param {V} defaultValue | 227 * @param {V} defaultValue |
| 225 * @param {!Common.Object} eventSupport | 228 * @param {!Common.Object} eventSupport |
| 226 * @param {!Common.SettingsStorage} storage | 229 * @param {!Common.SettingsStorage} storage |
| 227 */ | 230 */ |
| 228 constructor(settings, name, defaultValue, eventSupport, storage) { | 231 constructor(settings, name, defaultValue, eventSupport, storage) { |
| 229 this._settings = settings; | 232 this._settings = settings; |
| 230 this._name = name; | 233 this._name = name; |
| 231 this._defaultValue = defaultValue; | 234 this._defaultValue = defaultValue; |
| 232 this._eventSupport = eventSupport; | 235 this._eventSupport = eventSupport; |
| 233 this._storage = storage; | 236 this._storage = storage; |
| 237 /** @type {string} */ | |
| 238 this._title = ''; | |
| 234 } | 239 } |
| 235 | 240 |
| 236 /** | 241 /** |
| 237 * @param {function(!Common.Event)} listener | 242 * @param {function(!Common.Event)} listener |
| 238 * @param {!Object=} thisObject | 243 * @param {!Object=} thisObject |
| 239 */ | 244 */ |
| 240 addChangeListener(listener, thisObject) { | 245 addChangeListener(listener, thisObject) { |
| 241 this._eventSupport.addEventListener(this._name, listener, thisObject); | 246 this._eventSupport.addEventListener(this._name, listener, thisObject); |
| 242 } | 247 } |
| 243 | 248 |
| 244 /** | 249 /** |
| 245 * @param {function(!Common.Event)} listener | 250 * @param {function(!Common.Event)} listener |
| 246 * @param {!Object=} thisObject | 251 * @param {!Object=} thisObject |
| 247 */ | 252 */ |
| 248 removeChangeListener(listener, thisObject) { | 253 removeChangeListener(listener, thisObject) { |
| 249 this._eventSupport.removeEventListener(this._name, listener, thisObject); | 254 this._eventSupport.removeEventListener(this._name, listener, thisObject); |
| 250 } | 255 } |
| 251 | 256 |
| 252 get name() { | 257 get name() { |
| 253 return this._name; | 258 return this._name; |
| 254 } | 259 } |
| 255 | 260 |
| 256 /** | 261 /** |
| 262 * @return {string} | |
| 263 */ | |
| 264 title() { | |
| 265 return this._title; | |
| 266 } | |
| 267 | |
| 268 /** | |
| 269 * @param {string} title | |
| 270 */ | |
| 271 setTitle(title) { | |
| 272 this._title = title; | |
| 273 } | |
| 274 | |
| 275 /** | |
| 257 * @return {V} | 276 * @return {V} |
| 258 */ | 277 */ |
| 259 get() { | 278 get() { |
| 260 if (typeof this._value !== 'undefined') | 279 if (typeof this._value !== 'undefined') |
| 261 return this._value; | 280 return this._value; |
| 262 | 281 |
| 263 this._value = this._defaultValue; | 282 this._value = this._defaultValue; |
| 264 if (this._storage.has(this._name)) { | 283 if (this._storage.has(this._name)) { |
| 265 try { | 284 try { |
| 266 this._value = JSON.parse(this._storage.get(this._name)); | 285 this._value = JSON.parse(this._storage.get(this._name)); |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 return Common.settings.moduleSetting(settingName); | 779 return Common.settings.moduleSetting(settingName); |
| 761 }; | 780 }; |
| 762 | 781 |
| 763 /** | 782 /** |
| 764 * @param {string} settingName | 783 * @param {string} settingName |
| 765 * @return {!Common.Setting} | 784 * @return {!Common.Setting} |
| 766 */ | 785 */ |
| 767 Common.settingForTest = function(settingName) { | 786 Common.settingForTest = function(settingName) { |
| 768 return Common.settings.settingForTest(settingName); | 787 return Common.settings.settingForTest(settingName); |
| 769 }; | 788 }; |
| OLD | NEW |