Skip to content

Commit 18fbfdd

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[common] Consistently use 'this.#settings' in VersionController
There were still two helpers 'removeSetting' and 'moduleSetting' that access the global instance. This is fine in production since we only ever have a single instance, but makes reasoning in tests unnecessary hard. [email protected] Bug: 458180550 Change-Id: I0534002ec0ed6846976bff5ba660ee9f9c73e314 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7131063 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Simon Zünd <[email protected]> Commit-Queue: Philip Pfaffe <[email protected]> Auto-Submit: Simon Zünd <[email protected]>
1 parent c561310 commit 18fbfdd

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

front_end/core/common/Settings.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,6 @@ export class SettingsStorage {
305305
}
306306
}
307307

308-
function removeSetting(setting: {name: string, storage: SettingsStorage}): void {
309-
const name = setting.name;
310-
const settings = Settings.instance();
311-
312-
settings.getRegistry().delete(name);
313-
settings.moduleSettings.delete(name);
314-
315-
setting.storage.remove(name);
316-
}
317-
318308
export class Deprecation {
319309
readonly disabled: boolean;
320310
readonly warning: Platform.UIString.LocalizedString;
@@ -687,6 +677,15 @@ export class VersionController {
687677
this.#localVersionSetting.set(VersionController.CURRENT_VERSION);
688678
}
689679

680+
#removeSetting(setting: {name: string, storage: SettingsStorage}): void {
681+
const name = setting.name;
682+
683+
this.#settings.getRegistry().delete(name);
684+
this.#settings.moduleSettings.delete(name);
685+
686+
setting.storage.remove(name);
687+
}
688+
690689
/**
691690
* Runs the appropriate migrations and updates the version settings accordingly.
692691
*
@@ -728,13 +727,13 @@ export class VersionController {
728727

729728
updateVersionFrom2To3(): void {
730729
this.#settings.createSetting('fileSystemMapping', {}).set({});
731-
removeSetting(this.#settings.createSetting('fileMappingEntries', []));
730+
this.#removeSetting(this.#settings.createSetting('fileMappingEntries', []));
732731
}
733732

734733
updateVersionFrom3To4(): void {
735734
const advancedMode = this.#settings.createSetting('showHeaSnapshotObjectsHiddenProperties', false);
736-
moduleSetting('showAdvancedHeapSnapshotProperties').set(advancedMode.get());
737-
removeSetting(advancedMode);
735+
this.#settings.moduleSetting('showAdvancedHeapSnapshotProperties').set(advancedMode.get());
736+
this.#removeSetting(advancedMode);
738737
}
739738

740739
updateVersionFrom4To5(): void {
@@ -772,7 +771,7 @@ export class VersionController {
772771
newValue.vertical = {};
773772
// @ts-expect-error
774773
newValue.vertical.size = oldSetting.get();
775-
removeSetting(oldSetting);
774+
this.#removeSetting(oldSetting);
776775
}
777776
const oldSettingH = this.#settings.createSetting(oldNameH, empty);
778777
if (oldSettingH.get() !== empty) {
@@ -781,7 +780,7 @@ export class VersionController {
781780
newValue.horizontal = {};
782781
// @ts-expect-error
783782
newValue.horizontal.size = oldSettingH.get();
784-
removeSetting(oldSettingH);
783+
this.#removeSetting(oldSettingH);
785784
}
786785
if (newValue) {
787786
this.#settings.createSetting(newName, {}).set(newValue);
@@ -799,14 +798,14 @@ export class VersionController {
799798
for (const oldName in settingNames) {
800799
const oldSetting = this.#settings.createSetting(oldName, null);
801800
if (oldSetting.get() === null) {
802-
removeSetting(oldSetting);
801+
this.#removeSetting(oldSetting);
803802
continue;
804803
}
805804

806805
const newName = settingNames[oldName];
807806
const invert = oldName === 'WebInspector.Drawer.showOnLoad';
808807
const hidden = oldSetting.get() !== invert;
809-
removeSetting(oldSetting);
808+
this.#removeSetting(oldSetting);
810809
const showMode = hidden ? 'OnlyMain' : 'Both';
811810

812811
const newSetting = this.#settings.createSetting(newName, {});
@@ -925,7 +924,7 @@ export class VersionController {
925924
if (newList.length) {
926925
this.#settings.createSetting<unknown[]>(newSettingName, []).set(newList);
927926
}
928-
removeSetting(oldSetting);
927+
this.#removeSetting(oldSetting);
929928
}
930929

931930
updateVersionFrom11To12(): void {
@@ -934,7 +933,7 @@ export class VersionController {
934933

935934
updateVersionFrom12To13(): void {
936935
this.migrateSettingsFromLocalStorage();
937-
removeSetting(this.#settings.createSetting('timelineOverviewMode', ''));
936+
this.#removeSetting(this.#settings.createSetting('timelineOverviewMode', ''));
938937
}
939938

940939
updateVersionFrom13To14(): void {
@@ -1018,14 +1017,14 @@ export class VersionController {
10181017
}
10191018
const newSetting = this.#settings.createSetting('networkLogColumns', {});
10201019
newSetting.set(configs);
1021-
removeSetting(visibleColumnSettings);
1020+
this.#removeSetting(visibleColumnSettings);
10221021
}
10231022

10241023
updateVersionFrom19To20(): void {
10251024
const oldSetting = this.#settings.createSetting('InspectorView.panelOrder', {});
10261025
const newSetting = this.#settings.createSetting('panel-tabOrder', {});
10271026
newSetting.set(oldSetting.get());
1028-
removeSetting(oldSetting);
1027+
this.#removeSetting(oldSetting);
10291028
}
10301029

10311030
updateVersionFrom20To21(): void {
@@ -1054,7 +1053,7 @@ export class VersionController {
10541053
const oldSetting = this.#settings.createSetting('searchInContentScripts', false);
10551054
const newSetting = this.#settings.createSetting('searchInAnonymousAndContentScripts', false);
10561055
newSetting.set(oldSetting.get());
1057-
removeSetting(oldSetting);
1056+
this.#removeSetting(oldSetting);
10581057
}
10591058

10601059
updateVersionFrom24To25(): void {
@@ -1075,7 +1074,7 @@ export class VersionController {
10751074
const suffix = textFilterSetting.get() ? ` ${textFilterSetting.get()}` : '';
10761075
textFilterSetting.set(`${textFilter}${suffix}`);
10771076
}
1078-
removeSetting(oldSetting);
1077+
this.#removeSetting(oldSetting);
10791078
}
10801079

10811080
updateVersionFrom26To27(): void {
@@ -1150,15 +1149,15 @@ export class VersionController {
11501149
closeableTabSetting.set(newValue);
11511150

11521151
// Remove old settings
1153-
removeSetting(panelCloseableTabSetting);
1154-
removeSetting(drawerCloseableTabSetting);
1152+
this.#removeSetting(panelCloseableTabSetting);
1153+
this.#removeSetting(drawerCloseableTabSetting);
11551154
}
11561155

11571156
updateVersionFrom30To31(): void {
11581157
// Remove recorder_recordings setting that was used for storing recordings
11591158
// by an old recorder experiment.
11601159
const recordingsSetting = this.#settings.createSetting('recorder_recordings', []);
1161-
removeSetting(recordingsSetting);
1160+
this.#removeSetting(recordingsSetting);
11621161
}
11631162

11641163
updateVersionFrom31To32(): void {
@@ -1249,7 +1248,7 @@ export class VersionController {
12491248
const normalizedKey = Settings.normalizeSettingName(key);
12501249
if (normalizedKey !== key) {
12511250
const value = storage.get(key);
1252-
removeSetting({name: key, storage});
1251+
this.#removeSetting({name: key, storage});
12531252
storage.set(normalizedKey, value);
12541253
}
12551254
}
@@ -1274,7 +1273,7 @@ export class VersionController {
12741273
updateVersionFrom37To38(): void {
12751274
const getConsoleInsightsEnabledSetting = (): Setting<boolean>|undefined => {
12761275
try {
1277-
return moduleSetting('console-insights-enabled') as Setting<boolean>;
1276+
return this.#settings.moduleSetting('console-insights-enabled') as Setting<boolean>;
12781277
} catch {
12791278
return;
12801279
}
@@ -1337,7 +1336,7 @@ export class VersionController {
13371336
const hasCustomNetworkConditionsSetting = (): boolean => {
13381337
try {
13391338
// this will error if it does not exist
1340-
moduleSetting('custom-network-conditions');
1339+
this.#settings.moduleSetting('custom-network-conditions');
13411340
return true;
13421341
} catch {
13431342
return false;
@@ -1353,7 +1352,8 @@ export class VersionController {
13531352
* objects, and we need to set the right key on each one. The actual keys &
13541353
* values in the object are not important.
13551354
*/
1356-
const conditionsSetting = moduleSetting('custom-network-conditions') as Setting<Array<{key?: string}>>;
1355+
const conditionsSetting =
1356+
this.#settings.moduleSetting('custom-network-conditions') as Setting<Array<{key?: string}>>;
13571357
const customConditions = conditionsSetting.get();
13581358
if (customConditions?.length > 0) {
13591359
customConditions.forEach((condition, i) => {

0 commit comments

Comments
 (0)