Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/common/Settings.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/common/Settings.js b/third_party/WebKit/Source/devtools/front_end/common/Settings.js |
| index 28a3087c506159d76e561d84285be495deca29bf..0a664de30dcbd64ba451fd4bd453aa1b045ab943 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/common/Settings.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/common/Settings.js |
| @@ -37,8 +37,9 @@ Common.Settings = class { |
| * @param {!Common.SettingsStorage} localStorage |
| */ |
| constructor(globalStorage, localStorage) { |
| - this._settingsStorage = globalStorage; |
| + this._globalStorage = globalStorage; |
| this._localStorage = localStorage; |
| + this._sessionStorage = new Common.SettingsStorage({}); |
| this._eventSupport = new Common.Object(); |
| /** @type {!Map<string, !Common.Setting>} */ |
| @@ -54,11 +55,22 @@ Common.Settings = class { |
| _registerModuleSetting(extension) { |
| var descriptor = extension.descriptor(); |
| var settingName = descriptor['settingName']; |
| - var settingType = descriptor['settingType']; |
| + var isRegex = descriptor['settingType'] === 'regex'; |
| var defaultValue = descriptor['defaultValue']; |
| - var isLocal = !!descriptor['local']; |
| - var setting = settingType === 'regex' ? this.createRegExpSetting(settingName, defaultValue, undefined, isLocal) : |
| - this.createSetting(settingName, defaultValue, isLocal); |
| + var storageType; |
| + switch (descriptor['storageType']) { |
| + case ('local'): |
| + storageType = Common.SettingStorageType.Local; |
| + break; |
| + case ('session'): |
| + storageType = Common.SettingStorageType.Session; |
| + break; |
| + default: |
|
pfeldman
2017/03/01 23:23:19
You typically specify all the cases and then retur
luoe
2017/03/03 03:50:22
Done.
|
| + storageType = Common.SettingStorageType.Global; |
| + break; |
| + } |
| + var setting = isRegex ? this.createRegExpSetting(settingName, defaultValue, undefined, storageType) : |
| + this.createSetting(settingName, defaultValue, storageType); |
| if (descriptor['title']) |
| setting.setTitle(descriptor['title']); |
| this._moduleSettings.set(settingName, setting); |
| @@ -89,15 +101,13 @@ Common.Settings = class { |
| /** |
| * @param {string} key |
| * @param {*} defaultValue |
| - * @param {boolean=} isLocal |
| + * @param {!Common.SettingStorageType=} storageType |
| * @return {!Common.Setting} |
| */ |
| - createSetting(key, defaultValue, isLocal) { |
| - if (!this._registry.get(key)) { |
| - this._registry.set( |
| - key, new Common.Setting( |
| - this, key, defaultValue, this._eventSupport, isLocal ? this._localStorage : this._settingsStorage)); |
| - } |
| + createSetting(key, defaultValue, storageType) { |
| + var storage = this._storageFromType(storageType); |
| + if (!this._registry.get(key)) |
| + this._registry.set(key, new Common.Setting(this, key, defaultValue, this._eventSupport, storage)); |
| return /** @type {!Common.Setting} */ (this._registry.get(key)); |
| } |
| @@ -107,32 +117,47 @@ Common.Settings = class { |
| * @return {!Common.Setting} |
| */ |
| createLocalSetting(key, defaultValue) { |
| - return this.createSetting(key, defaultValue, true); |
| + return this.createSetting(key, defaultValue, Common.SettingStorageType.Local); |
| } |
| /** |
| * @param {string} key |
| * @param {string} defaultValue |
| * @param {string=} regexFlags |
| - * @param {boolean=} isLocal |
| + * @param {!Common.SettingStorageType=} storageType |
| * @return {!Common.RegExpSetting} |
| */ |
| - createRegExpSetting(key, defaultValue, regexFlags, isLocal) { |
| + createRegExpSetting(key, defaultValue, regexFlags, storageType) { |
| if (!this._registry.get(key)) { |
| this._registry.set( |
| key, new Common.RegExpSetting( |
| - this, key, defaultValue, this._eventSupport, isLocal ? this._localStorage : this._settingsStorage, |
| - regexFlags)); |
| + this, key, defaultValue, this._eventSupport, this._storageFromType(storageType), regexFlags)); |
| } |
| return /** @type {!Common.RegExpSetting} */ (this._registry.get(key)); |
| } |
| clearAll() { |
| - this._settingsStorage.removeAll(); |
| + this._globalStorage.removeAll(); |
| this._localStorage.removeAll(); |
| var versionSetting = Common.settings.createSetting(Common.VersionController._currentVersionName, 0); |
| versionSetting.set(Common.VersionController.currentVersion); |
| } |
| + |
| + /** |
| + * @param {!Common.SettingStorageType=} storageType |
| + * @return {!Common.SettingsStorage} |
| + */ |
| + _storageFromType(storageType) { |
| + switch (storageType) { |
| + case (Common.SettingStorageType.Local): |
| + return this._localStorage; |
| + case (Common.SettingStorageType.Session): |
| + return this._sessionStorage; |
| + case (Common.SettingStorageType.Global): |
| + default: |
| + return this._globalStorage; |
|
pfeldman
2017/03/01 23:23:19
ditto (no fall through). and I would actually defa
luoe
2017/03/03 03:50:22
Done.
|
| + } |
| + } |
| }; |
| /** |
| @@ -753,7 +778,7 @@ Common.VersionController = class { |
| continue; |
| var value = window.localStorage[key]; |
| window.localStorage.removeItem(key); |
| - Common.settings._settingsStorage[key] = value; |
| + Common.settings._globalStorage[key] = value; |
| } |
| } |
| @@ -778,6 +803,15 @@ Common.VersionController.currentVersion = 24; |
| Common.settings; |
| /** |
| + * @enum {symbol} |
| + */ |
| +Common.SettingStorageType = { |
| + Global: Symbol('Global'), |
| + Local: Symbol('Local'), |
| + Session: Symbol('Session') |
| +}; |
| + |
| +/** |
| * @param {string} settingName |
| * @return {!Common.Setting} |
| */ |