Skip to content

Commit 6f7c824

Browse files
authored
adopt to application scope (microsoft#152286)
1 parent 8559324 commit 6f7c824

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

src/vs/platform/extensionManagement/common/extensionStorage.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
5555
return undefined;
5656
}
5757

58+
/* TODO @sandy081: This has to be done across all profiles */
5859
static async removeOutdatedExtensionVersions(extensionManagementService: IExtensionManagementService, storageService: IStorageService): Promise<void> {
5960
const extensions = await extensionManagementService.getInstalled();
6061
const extensionVersionsToRemove: string[] = [];
@@ -193,7 +194,7 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
193194
}
194195

195196
private get migrationList(): [string, string][] {
196-
const value = this.storageService.get('extensionStorage.migrationList', StorageScope.GLOBAL, '[]');
197+
const value = this.storageService.get('extensionStorage.migrationList', StorageScope.APPLICATION, '[]');
197198
try {
198199
const migrationList = JSON.parse(value);
199200
if (isArray(migrationList)) {
@@ -205,9 +206,9 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
205206

206207
private set migrationList(migrationList: [string, string][]) {
207208
if (migrationList.length) {
208-
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.GLOBAL, StorageTarget.MACHINE);
209+
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.APPLICATION, StorageTarget.MACHINE);
209210
} else {
210-
this.storageService.remove('extensionStorage.migrationList', StorageScope.GLOBAL);
211+
this.storageService.remove('extensionStorage.migrationList', StorageScope.APPLICATION);
211212
}
212213
}
213214

src/vs/platform/userDataSync/common/globalStateSync.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function stringify(globalState: IGlobalState, format: boolean): string {
5656
const GLOBAL_STATE_DATA_VERSION = 1;
5757

5858
/**
59+
* TODO: @sandy081: Sync only global state of default profile
60+
*
5961
* Synchronises global state that includes
6062
* - Global storage with user scope
6163
* - Locale from argv properties

src/vs/workbench/contrib/experiments/common/experimentService.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ export class ExperimentService extends Disposable implements IExperimentService
223223

224224
public markAsCompleted(experimentId: string): void {
225225
const storageKey = 'experiments.' + experimentId;
226-
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
226+
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
227227
experimentState.state = ExperimentState.Complete;
228-
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
228+
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
229229
}
230230

231231
protected async getExperiments(): Promise<IRawExperiment[] | null> {
@@ -255,11 +255,11 @@ export class ExperimentService extends Disposable implements IExperimentService
255255
return this.getExperiments().then(rawExperiments => {
256256
// Offline mode
257257
if (!rawExperiments) {
258-
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.GLOBAL), []);
258+
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.APPLICATION), []);
259259
if (Array.isArray(allExperimentIdsFromStorage)) {
260260
allExperimentIdsFromStorage.forEach(experimentId => {
261261
const storageKey = 'experiments.' + experimentId;
262-
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), null);
262+
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), null);
263263
if (experimentState) {
264264
this._experiments.push({
265265
id: experimentId,
@@ -278,19 +278,19 @@ export class ExperimentService extends Disposable implements IExperimentService
278278
rawExperiments = rawExperiments.filter(e => (e.schemaVersion || 0) <= currentSchemaVersion);
279279

280280
// Clear disbaled/deleted experiments from storage
281-
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.GLOBAL), []);
281+
const allExperimentIdsFromStorage = safeParse(this.storageService.get('allExperiments', StorageScope.APPLICATION), []);
282282
const enabledExperiments = rawExperiments.filter(experiment => !!experiment.enabled).map(experiment => experiment.id.toLowerCase());
283283
if (Array.isArray(allExperimentIdsFromStorage)) {
284284
allExperimentIdsFromStorage.forEach(experiment => {
285285
if (enabledExperiments.indexOf(experiment) === -1) {
286-
this.storageService.remove(`experiments.${experiment}`, StorageScope.GLOBAL);
286+
this.storageService.remove(`experiments.${experiment}`, StorageScope.APPLICATION);
287287
}
288288
});
289289
}
290290
if (enabledExperiments.length) {
291-
this.storageService.store('allExperiments', JSON.stringify(enabledExperiments), StorageScope.GLOBAL, StorageTarget.MACHINE);
291+
this.storageService.store('allExperiments', JSON.stringify(enabledExperiments), StorageScope.APPLICATION, StorageTarget.MACHINE);
292292
} else {
293-
this.storageService.remove('allExperiments', StorageScope.GLOBAL);
293+
this.storageService.remove('allExperiments', StorageScope.APPLICATION);
294294
}
295295

296296
const activationEvents = new Set(rawExperiments.map(exp => exp.condition?.activationEvent?.event)
@@ -348,7 +348,7 @@ export class ExperimentService extends Disposable implements IExperimentService
348348
}
349349

350350
const storageKey = 'experiments.' + experiment.id;
351-
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
351+
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
352352
if (!experimentState.hasOwnProperty('enabled')) {
353353
experimentState.enabled = processedExperiment.enabled;
354354
}
@@ -360,7 +360,7 @@ export class ExperimentService extends Disposable implements IExperimentService
360360

361361
return this.shouldRunExperiment(experiment, processedExperiment).then((state: ExperimentState) => {
362362
experimentState.state = processedExperiment.state = state;
363-
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
363+
this.storageService.store(storageKey, JSON.stringify(experimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
364364

365365
if (state === ExperimentState.Run) {
366366
this.fireRunExperiment(processedExperiment);
@@ -372,22 +372,22 @@ export class ExperimentService extends Disposable implements IExperimentService
372372

373373
private fireRunExperiment(experiment: IExperiment) {
374374
this._onExperimentEnabled.fire(experiment);
375-
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.GLOBAL), []);
375+
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.APPLICATION), []);
376376
if (runExperimentIdsFromStorage.indexOf(experiment.id) === -1) {
377377
runExperimentIdsFromStorage.push(experiment.id);
378378
}
379379

380380
// Ensure we dont store duplicates
381381
const distinctExperiments = distinct(runExperimentIdsFromStorage);
382382
if (runExperimentIdsFromStorage.length !== distinctExperiments.length) {
383-
this.storageService.store('currentOrPreviouslyRunExperiments', JSON.stringify(distinctExperiments), StorageScope.GLOBAL, StorageTarget.MACHINE);
383+
this.storageService.store('currentOrPreviouslyRunExperiments', JSON.stringify(distinctExperiments), StorageScope.APPLICATION, StorageTarget.MACHINE);
384384
}
385385
}
386386

387387
private checkExperimentDependencies(experiment: IRawExperiment): boolean {
388388
const experimentsPreviouslyRun = experiment.condition?.experimentsPreviouslyRun;
389389
if (experimentsPreviouslyRun) {
390-
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.GLOBAL), []);
390+
const runExperimentIdsFromStorage: string[] = safeParse(this.storageService.get('currentOrPreviouslyRunExperiments', StorageScope.APPLICATION), []);
391391
let includeCheck = true;
392392
let excludeCheck = true;
393393
const includes = experimentsPreviouslyRun.includes;
@@ -407,9 +407,9 @@ export class ExperimentService extends Disposable implements IExperimentService
407407

408408
private recordActivatedEvent(event: string) {
409409
const key = experimentEventStorageKey(event);
410-
const record = getCurrentActivationRecord(safeParse(this.storageService.get(key, StorageScope.GLOBAL), undefined));
410+
const record = getCurrentActivationRecord(safeParse(this.storageService.get(key, StorageScope.APPLICATION), undefined));
411411
record.count[0]++;
412-
this.storageService.store(key, JSON.stringify(record), StorageScope.GLOBAL, StorageTarget.MACHINE);
412+
this.storageService.store(key, JSON.stringify(record), StorageScope.APPLICATION, StorageTarget.MACHINE);
413413

414414
this._experiments
415415
.filter(e => {
@@ -434,7 +434,7 @@ export class ExperimentService extends Disposable implements IExperimentService
434434

435435
const events = typeof setting.event === 'string' ? [setting.event] : setting.event;
436436
for (const event of events) {
437-
const { count } = getCurrentActivationRecord(safeParse(this.storageService.get(experimentEventStorageKey(event), StorageScope.GLOBAL), undefined));
437+
const { count } = getCurrentActivationRecord(safeParse(this.storageService.get(experimentEventStorageKey(event), StorageScope.APPLICATION), undefined));
438438

439439
for (const entry of count) {
440440
if (entry > 0) {
@@ -532,7 +532,7 @@ export class ExperimentService extends Disposable implements IExperimentService
532532
}
533533

534534
const storageKey = 'experiments.' + experiment.id;
535-
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
535+
const experimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
536536

537537
return extensionsCheckPromise.then(success => {
538538
const fileEdits = condition.fileEdits;
@@ -549,7 +549,7 @@ export class ExperimentService extends Disposable implements IExperimentService
549549
// Process model-save event every 250ms to reduce load
550550
const onModelsSavedWorker = this._register(new RunOnceWorker<ITextFileEditorModel>(models => {
551551
const date = new Date().toDateString();
552-
const latestExperimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.GLOBAL), {});
552+
const latestExperimentState: IExperimentStorageState = safeParse(this.storageService.get(storageKey, StorageScope.APPLICATION), {});
553553
if (latestExperimentState.state !== ExperimentState.Evaluating) {
554554
onSaveHandler.dispose();
555555
onModelsSavedWorker.dispose();
@@ -579,12 +579,12 @@ export class ExperimentService extends Disposable implements IExperimentService
579579
if (filePathCheck && workspaceCheck) {
580580
latestExperimentState.editCount = (latestExperimentState.editCount || 0) + 1;
581581
latestExperimentState.lastEditedDate = date;
582-
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
582+
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
583583
}
584584
});
585585
if (typeof latestExperimentState.editCount === 'number' && latestExperimentState.editCount >= fileEdits.minEditCount) {
586586
processedExperiment.state = latestExperimentState.state = (typeof condition.userProbability === 'number' && Math.random() < condition.userProbability && this.checkExperimentDependencies(experiment)) ? ExperimentState.Run : ExperimentState.NoRun;
587-
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.GLOBAL, StorageTarget.MACHINE);
587+
this.storageService.store(storageKey, JSON.stringify(latestExperimentState), StorageScope.APPLICATION, StorageTarget.MACHINE);
588588
if (latestExperimentState.state === ExperimentState.Run && processedExperiment.action && ExperimentActionType[processedExperiment.action.type] === ExperimentActionType.Prompt) {
589589
this.fireRunExperiment(processedExperiment);
590590
}

src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ suite('Experiment Service', () => {
535535
didGetCall = true;
536536
assert.strictEqual(key, 'experimentEventRecord-my-event');
537537
assert.deepStrictEqual(JSON.parse(value).count, [1, 0, 10, 0, 0, 0, 0]);
538-
assert.strictEqual(scope, StorageScope.GLOBAL);
538+
assert.strictEqual(scope, StorageScope.APPLICATION);
539539
}
540540
});
541541

src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
15681568
}).then(undefined, error => this.onError(error));
15691569
}
15701570

1571-
1571+
/* TODO: @sandy081 Extension version shall be moved to extensions.json file */
15721572
private _ignoredAutoUpdateExtensions: string[] | undefined;
15731573
private get ignoredAutoUpdateExtensions(): string[] {
15741574
if (!this._ignoredAutoUpdateExtensions) {

src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
190190
if (requiresInitialization && !this.userDataSyncEnablementService.isEnabled()) {
191191
this.updateSyncAfterInitializationContext(true);
192192
} else {
193-
this.updateSyncAfterInitializationContext(this.storageService.getBoolean(CONTEXT_SYNC_AFTER_INITIALIZATION.key, StorageScope.GLOBAL, false));
193+
this.updateSyncAfterInitializationContext(this.storageService.getBoolean(CONTEXT_SYNC_AFTER_INITIALIZATION.key, StorageScope.APPLICATION, false));
194194
}
195195
const disposable = this._register(this.userDataSyncEnablementService.onDidChangeEnablement(() => {
196196
if (this.userDataSyncEnablementService.isEnabled()) {
@@ -201,7 +201,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
201201
}
202202

203203
private async updateSyncAfterInitializationContext(value: boolean): Promise<void> {
204-
this.storageService.store(CONTEXT_SYNC_AFTER_INITIALIZATION.key, value, StorageScope.GLOBAL, StorageTarget.MACHINE);
204+
this.storageService.store(CONTEXT_SYNC_AFTER_INITIALIZATION.key, value, StorageScope.APPLICATION, StorageTarget.MACHINE);
205205
this.syncAfterInitializationContext.set(value);
206206
this.updateGlobalActivityBadge();
207207
}

0 commit comments

Comments
 (0)