Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adopt to application storage #152224

Merged
merged 1 commit into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -256,7 +256,7 @@ export class ExtensionTipsService extends BaseExtensionTipsService {
}

private getLastPromptedMediumExeTime(): number {
let value = this.storageService.getNumber(lastPromptedMediumImpExeTimeStorageKey, StorageScope.GLOBAL);
let value = this.storageService.getNumber(lastPromptedMediumImpExeTimeStorageKey, StorageScope.APPLICATION);
if (!value) {
value = Date.now();
this.updateLastPromptedMediumExeTime(value);
Expand All @@ -265,17 +265,17 @@ export class ExtensionTipsService extends BaseExtensionTipsService {
}

private updateLastPromptedMediumExeTime(value: number): void {
this.storageService.store(lastPromptedMediumImpExeTimeStorageKey, value, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(lastPromptedMediumImpExeTimeStorageKey, value, StorageScope.APPLICATION, StorageTarget.MACHINE);
}

private getPromptedExecutableTips(): IStringDictionary<string[]> {
return JSON.parse(this.storageService.get(promptedExecutableTipsStorageKey, StorageScope.GLOBAL, '{}'));
return JSON.parse(this.storageService.get(promptedExecutableTipsStorageKey, StorageScope.APPLICATION, '{}'));
}

private addToRecommendedExecutables(exeName: string, tips: IExecutableBasedExtensionTip[]) {
const promptedExecutableTips = this.getPromptedExecutableTips();
promptedExecutableTips[exeName] = tips.map(({ extensionId }) => extensionId.toLowerCase());
this.storageService.store(promptedExecutableTipsStorageKey, JSON.stringify(promptedExecutableTips), StorageScope.GLOBAL, StorageTarget.USER);
this.storageService.store(promptedExecutableTipsStorageKey, JSON.stringify(promptedExecutableTips), StorageScope.APPLICATION, StorageTarget.USER);
}

private groupByInstalled(recommendationsToSuggest: string[], local: ILocalExtension[]): { installed: string[]; uninstalled: string[] } {
Expand Down
24 changes: 12 additions & 12 deletions src/vs/platform/userDataSync/common/userDataAutoSyncService.ts
Expand Up @@ -54,26 +54,26 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto

private lastSyncUrl: URI | undefined;
private get syncUrl(): URI | undefined {
const value = this.storageService.get(storeUrlKey, StorageScope.GLOBAL);
const value = this.storageService.get(storeUrlKey, StorageScope.APPLICATION);
return value ? URI.parse(value) : undefined;
}
private set syncUrl(syncUrl: URI | undefined) {
if (syncUrl) {
this.storageService.store(storeUrlKey, syncUrl.toString(), StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(storeUrlKey, syncUrl.toString(), StorageScope.APPLICATION, StorageTarget.MACHINE);
} else {
this.storageService.remove(storeUrlKey, StorageScope.GLOBAL);
this.storageService.remove(storeUrlKey, StorageScope.APPLICATION);
}
}

private previousProductQuality: string | undefined;
private get productQuality(): string | undefined {
return this.storageService.get(productQualityKey, StorageScope.GLOBAL);
return this.storageService.get(productQualityKey, StorageScope.APPLICATION);
}
private set productQuality(productQuality: string | undefined) {
if (productQuality) {
this.storageService.store(productQualityKey, productQuality, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(productQualityKey, productQuality, StorageScope.APPLICATION, StorageTarget.MACHINE);
} else {
this.storageService.remove(productQualityKey, StorageScope.GLOBAL);
this.storageService.remove(productQualityKey, StorageScope.APPLICATION);
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
this.updateEnablement(false);

// Reset Session
this.storageService.remove(sessionIdKey, StorageScope.GLOBAL);
this.storageService.remove(sessionIdKey, StorageScope.APPLICATION);

// Reset
if (everywhere) {
Expand Down Expand Up @@ -315,7 +315,7 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
}

private async disableMachineEventually(): Promise<void> {
this.storageService.store(disableMachineEventuallyKey, true, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(disableMachineEventuallyKey, true, StorageScope.APPLICATION, StorageTarget.MACHINE);
await timeout(1000 * 60 * 10);

// Return if got stopped meanwhile.
Expand All @@ -332,11 +332,11 @@ export class UserDataAutoSyncService extends Disposable implements IUserDataAuto
}

private hasToDisableMachineEventually(): boolean {
return this.storageService.getBoolean(disableMachineEventuallyKey, StorageScope.GLOBAL, false);
return this.storageService.getBoolean(disableMachineEventuallyKey, StorageScope.APPLICATION, false);
}

private stopDisableMachineEventually(): void {
this.storageService.remove(disableMachineEventuallyKey, StorageScope.GLOBAL);
this.storageService.remove(disableMachineEventuallyKey, StorageScope.APPLICATION);
}

private sources: string[] = [];
Expand Down Expand Up @@ -481,7 +481,7 @@ class AutoSync extends Disposable {
}
}

const sessionId = this.storageService.get(sessionIdKey, StorageScope.GLOBAL);
const sessionId = this.storageService.get(sessionIdKey, StorageScope.APPLICATION);
// Server session is different from client session
if (sessionId && this.manifest && sessionId !== this.manifest.session) {
if (this.hasSyncServiceChanged()) {
Expand Down Expand Up @@ -521,7 +521,7 @@ class AutoSync extends Disposable {

// Update local session id
if (this.manifest && this.manifest.session !== sessionId) {
this.storageService.store(sessionIdKey, this.manifest.session, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(sessionIdKey, this.manifest.session, StorageScope.APPLICATION, StorageTarget.MACHINE);
}

// Return if cancellation is requested
Expand Down
Expand Up @@ -46,7 +46,7 @@ export class UserDataSyncEnablementService extends Disposable implements IUserDa
case 'off':
return false;
}
return this.storageService.getBoolean(enablementKey, StorageScope.GLOBAL, false);
return this.storageService.getBoolean(enablementKey, StorageScope.APPLICATION, false);
}

canToggleEnablement(): boolean {
Expand All @@ -58,11 +58,11 @@ export class UserDataSyncEnablementService extends Disposable implements IUserDa
return;
}
this.telemetryService.publicLog2<{ enabled: boolean }, SyncEnablementClassification>(enablementKey, { enabled });
this.storageService.store(enablementKey, enabled, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(enablementKey, enabled, StorageScope.APPLICATION, StorageTarget.MACHINE);
}

isResourceEnabled(resource: SyncResource): boolean {
return this.storageService.getBoolean(getEnablementKey(resource), StorageScope.GLOBAL, true);
return this.storageService.getBoolean(getEnablementKey(resource), StorageScope.APPLICATION, true);
}

setResourceEnablement(resource: SyncResource, enabled: boolean): void {
Expand All @@ -77,11 +77,11 @@ export class UserDataSyncEnablementService extends Disposable implements IUserDa
}

private storeResourceEnablement(resourceEnablementKey: string, enabled: boolean): void {
this.storageService.store(resourceEnablementKey, enabled, StorageScope.GLOBAL, isWeb ? StorageTarget.USER /* sync in web */ : StorageTarget.MACHINE);
this.storageService.store(resourceEnablementKey, enabled, StorageScope.APPLICATION, isWeb ? StorageTarget.USER /* sync in web */ : StorageTarget.MACHINE);
}

private onDidStorageChange(storageChangeEvent: IStorageValueChangeEvent): void {
if (storageChangeEvent.scope !== StorageScope.GLOBAL) {
if (storageChangeEvent.scope !== StorageScope.APPLICATION) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/userDataSync/common/userDataSyncMachines.ts
Expand Up @@ -132,7 +132,7 @@ export class UserDataSyncMachinesService extends Disposable implements IUserData
await this.writeMachinesData(machineData);
const currentMachineId = await this.currentMachineIdPromise;
if (machineId === currentMachineId) {
this.storageService.store(currentMachineNameKey, name, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(currentMachineNameKey, name, StorageScope.APPLICATION, StorageTarget.MACHINE);
}
}
}
Expand All @@ -149,7 +149,7 @@ export class UserDataSyncMachinesService extends Disposable implements IUserData
}

private computeCurrentMachineName(machines: IMachineData[]): string {
const previousName = this.storageService.get(currentMachineNameKey, StorageScope.GLOBAL);
const previousName = this.storageService.get(currentMachineNameKey, StorageScope.APPLICATION);
if (previousName) {
return previousName;
}
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/userDataSync/common/userDataSyncService.ts
Expand Up @@ -85,7 +85,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
) {
super();
this.updateStatus([]);
this._lastSyncTime = this.storageService.getNumber(LAST_SYNC_TIME_KEY, StorageScope.GLOBAL, undefined);
this._lastSyncTime = this.storageService.getNumber(LAST_SYNC_TIME_KEY, StorageScope.APPLICATION, undefined);
}

async createSyncTask(manifest: IUserDataManifest | null, disableCache?: boolean): Promise<ISyncTask> {
Expand Down Expand Up @@ -372,7 +372,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ

async resetLocal(): Promise<void> {
this.checkEnablement();
this.storageService.remove(LAST_SYNC_TIME_KEY, StorageScope.GLOBAL);
this.storageService.remove(LAST_SYNC_TIME_KEY, StorageScope.APPLICATION);
if (this.synchronizers.value) {
for (const synchroniser of this.synchronizers.value.enabled) {
try {
Expand Down Expand Up @@ -451,7 +451,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
private updateLastSyncTime(): void {
if (this.status === SyncStatus.Idle) {
this._lastSyncTime = new Date().getTime();
this.storageService.store(LAST_SYNC_TIME_KEY, this._lastSyncTime, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(LAST_SYNC_TIME_KEY, this._lastSyncTime, StorageScope.APPLICATION, StorageTarget.MACHINE);
this._onDidChangeLastSyncTime.fire(this._lastSyncTime);
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/vs/platform/userDataSync/common/userDataSyncStoreService.ts
Expand Up @@ -44,10 +44,10 @@ export abstract class AbstractUserDataSyncStoreManagementService extends Disposa
get userDataSyncStore(): UserDataSyncStore | undefined { return this._userDataSyncStore; }

protected get userDataSyncStoreType(): UserDataSyncStoreType | undefined {
return this.storageService.get(SYNC_SERVICE_URL_TYPE, StorageScope.GLOBAL) as UserDataSyncStoreType;
return this.storageService.get(SYNC_SERVICE_URL_TYPE, StorageScope.APPLICATION) as UserDataSyncStoreType;
}
protected set userDataSyncStoreType(type: UserDataSyncStoreType | undefined) {
this.storageService.store(SYNC_SERVICE_URL_TYPE, type, StorageScope.GLOBAL, isWeb ? StorageTarget.USER /* sync in web */ : StorageTarget.MACHINE);
this.storageService.store(SYNC_SERVICE_URL_TYPE, type, StorageScope.APPLICATION, isWeb ? StorageTarget.USER /* sync in web */ : StorageTarget.MACHINE);
}

constructor(
Expand All @@ -57,7 +57,7 @@ export abstract class AbstractUserDataSyncStoreManagementService extends Disposa
) {
super();
this.updateUserDataSyncStore();
this._register(Event.filter(storageService.onDidChangeValue, e => e.key === SYNC_SERVICE_URL_TYPE && e.scope === StorageScope.GLOBAL && this.userDataSyncStoreType !== this.userDataSyncStore?.type)(() => this.updateUserDataSyncStore()));
this._register(Event.filter(storageService.onDidChangeValue, e => e.key === SYNC_SERVICE_URL_TYPE && e.scope === StorageScope.APPLICATION && this.userDataSyncStoreType !== this.userDataSyncStore?.type)(() => this.updateUserDataSyncStore()));
}

protected updateUserDataSyncStore(): void {
Expand Down Expand Up @@ -115,16 +115,16 @@ export class UserDataSyncStoreManagementService extends AbstractUserDataSyncStor
) {
super(productService, configurationService, storageService);

const previousConfigurationSyncStore = this.storageService.get(SYNC_PREVIOUS_STORE, StorageScope.GLOBAL);
const previousConfigurationSyncStore = this.storageService.get(SYNC_PREVIOUS_STORE, StorageScope.APPLICATION);
if (previousConfigurationSyncStore) {
this.previousConfigurationSyncStore = JSON.parse(previousConfigurationSyncStore);
}

const syncStore = this.productService[CONFIGURATION_SYNC_STORE_KEY];
if (syncStore) {
this.storageService.store(SYNC_PREVIOUS_STORE, JSON.stringify(syncStore), StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(SYNC_PREVIOUS_STORE, JSON.stringify(syncStore), StorageScope.APPLICATION, StorageTarget.MACHINE);
} else {
this.storageService.remove(SYNC_PREVIOUS_STORE, StorageScope.GLOBAL);
this.storageService.remove(SYNC_PREVIOUS_STORE, StorageScope.APPLICATION);
}
}

Expand Down Expand Up @@ -202,7 +202,7 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
}

private initDonotMakeRequestsUntil(): void {
const donotMakeRequestsUntil = this.storageService.getNumber(DONOT_MAKE_REQUESTS_UNTIL_KEY, StorageScope.GLOBAL);
const donotMakeRequestsUntil = this.storageService.getNumber(DONOT_MAKE_REQUESTS_UNTIL_KEY, StorageScope.APPLICATION);
if (donotMakeRequestsUntil && Date.now() < donotMakeRequestsUntil) {
this.setDonotMakeRequestsUntil(new Date(donotMakeRequestsUntil));
}
Expand All @@ -219,11 +219,11 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
}

if (this._donotMakeRequestsUntil) {
this.storageService.store(DONOT_MAKE_REQUESTS_UNTIL_KEY, this._donotMakeRequestsUntil.getTime(), StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(DONOT_MAKE_REQUESTS_UNTIL_KEY, this._donotMakeRequestsUntil.getTime(), StorageScope.APPLICATION, StorageTarget.MACHINE);
this.resetDonotMakeRequestsUntilPromise = createCancelablePromise(token => timeout(this._donotMakeRequestsUntil!.getTime() - Date.now(), token).then(() => this.setDonotMakeRequestsUntil(undefined)));
this.resetDonotMakeRequestsUntilPromise.then(null, e => null /* ignore error */);
} else {
this.storageService.remove(DONOT_MAKE_REQUESTS_UNTIL_KEY, StorageScope.GLOBAL);
this.storageService.remove(DONOT_MAKE_REQUESTS_UNTIL_KEY, StorageScope.APPLICATION);
}

this._onDidChangeDonotMakeRequestsUntil.fire();
Expand Down Expand Up @@ -362,7 +362,7 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
}
}

const currentSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.GLOBAL);
const currentSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.APPLICATION);

if (currentSessionId && manifest && currentSessionId !== manifest.session) {
// Server session is different from client session so clear cached session.
Expand All @@ -376,7 +376,7 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync

if (manifest) {
// update session
this.storageService.store(USER_SESSION_ID_KEY, manifest.session, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(USER_SESSION_ID_KEY, manifest.session, StorageScope.APPLICATION, StorageTarget.MACHINE);
}

return manifest;
Expand All @@ -397,8 +397,8 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
}

private clearSession(): void {
this.storageService.remove(USER_SESSION_ID_KEY, StorageScope.GLOBAL);
this.storageService.remove(MACHINE_SESSION_ID_KEY, StorageScope.GLOBAL);
this.storageService.remove(USER_SESSION_ID_KEY, StorageScope.APPLICATION);
this.storageService.remove(MACHINE_SESSION_ID_KEY, StorageScope.APPLICATION);
}

private async request(url: string, options: IRequestOptions, successCodes: number[], token: CancellationToken): Promise<IRequestContext> {
Expand Down Expand Up @@ -518,14 +518,14 @@ export class UserDataSyncStoreClient extends Disposable implements IUserDataSync
}

private addSessionHeaders(headers: IHeaders): void {
let machineSessionId = this.storageService.get(MACHINE_SESSION_ID_KEY, StorageScope.GLOBAL);
let machineSessionId = this.storageService.get(MACHINE_SESSION_ID_KEY, StorageScope.APPLICATION);
if (machineSessionId === undefined) {
machineSessionId = generateUuid();
this.storageService.store(MACHINE_SESSION_ID_KEY, machineSessionId, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(MACHINE_SESSION_ID_KEY, machineSessionId, StorageScope.APPLICATION, StorageTarget.MACHINE);
}
headers['X-Machine-Session-Id'] = machineSessionId;

const userSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.GLOBAL);
const userSessionId = this.storageService.get(USER_SESSION_ID_KEY, StorageScope.APPLICATION);
if (userSessionId !== undefined) {
headers['X-User-Session-Id'] = userSessionId;
}
Expand Down
Expand Up @@ -57,11 +57,11 @@ export class RemoteExtensionsInitializerContribution implements IWorkbenchContri
}
const newRemoteConnectionKey = `${IS_NEW_KEY}.${connection.remoteAuthority}`;
// Skip: Not a new remote connection
if (!this.storageService.getBoolean(newRemoteConnectionKey, StorageScope.GLOBAL, true)) {
if (!this.storageService.getBoolean(newRemoteConnectionKey, StorageScope.APPLICATION, true)) {
this.logService.trace(`Skipping initializing remote extensions because the window with this remote authority was opened before.`);
return;
}
this.storageService.store(newRemoteConnectionKey, false, StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store(newRemoteConnectionKey, false, StorageScope.APPLICATION, StorageTarget.MACHINE);
// Skip: Not a new workspace
if (!this.storageService.isNew(StorageScope.WORKSPACE)) {
this.logService.trace(`Skipping initializing remote extensions because this workspace was opened before.`);
Expand Down
Expand Up @@ -218,7 +218,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}
const result: IScannedExtension[] = [];
try {
const useCache = this.storageService.get('additionalBuiltinExtensions', StorageScope.GLOBAL, '[]') === JSON.stringify(extensions);
const useCache = this.storageService.get('additionalBuiltinExtensions', StorageScope.APPLICATION, '[]') === JSON.stringify(extensions);
const webExtensions = await (useCache ? this.getCustomBuiltinExtensionsFromCache() : this.updateCustomBuiltinExtensionsCache());
if (webExtensions.length) {
await Promise.all(webExtensions.map(async webExtension => {
Expand All @@ -232,7 +232,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
}
}));
}
this.storageService.store('additionalBuiltinExtensions', JSON.stringify(extensions), StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store('additionalBuiltinExtensions', JSON.stringify(extensions), StorageScope.APPLICATION, StorageTarget.MACHINE);
} catch (error) {
this.logService.info('Ignoring following additional builtin extensions as there is an error while fetching them from gallery', extensions.map(({ id }) => id), getErrorMessage(error));
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/userData/browser/userDataInit.ts
Expand Up @@ -87,7 +87,7 @@ export class UserDataInitializationService implements IUserDataInitializationSer
return;
}

if (!this.storageService.isNew(StorageScope.GLOBAL)) {
if (!this.storageService.isNew(StorageScope.APPLICATION)) {
this.logService.trace(`Skipping initializing user data as application was opened before`);
return;
}
Expand Down