Skip to content

Commit

Permalink
storage - rename GLOBAL to APPLICATION (#152730)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jun 21, 2022
1 parent d9ee36b commit f73cd16
Show file tree
Hide file tree
Showing 43 changed files with 348 additions and 348 deletions.
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { SharedProcess } from 'vs/platform/sharedProcess/electron-main/sharedPro
import { ISignService } from 'vs/platform/sign/common/sign';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { StorageDatabaseChannel } from 'vs/platform/storage/electron-main/storageIpc';
import { GlobalStorageMainService, IGlobalStorageMainService, IStorageMainService, StorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
import { ApplicationStorageMainService, IApplicationStorageMainService, IStorageMainService, StorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
import { ITelemetryService, machineIdKey, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
Expand Down Expand Up @@ -648,7 +648,7 @@ export class CodeApplication extends Disposable {

// Storage
services.set(IStorageMainService, new SyncDescriptor(StorageMainService));
services.set(IGlobalStorageMainService, new SyncDescriptor(GlobalStorageMainService));
services.set(IApplicationStorageMainService, new SyncDescriptor(ApplicationStorageMainService));

// External terminal
if (isWindows) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ExtensionStorageService extends Disposable implements IExtensionSto
}

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

private set migrationList(migrationList: [string, string][]) {
if (migrationList.length) {
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.GLOBAL, StorageTarget.MACHINE);
this.storageService.store('extensionStorage.migrationList', JSON.stringify(migrationList), StorageScope.APPLICATION, StorageTarget.MACHINE);
} else {
this.storageService.remove('extensionStorage.migrationList', StorageScope.GLOBAL);
this.storageService.remove('extensionStorage.migrationList', StorageScope.APPLICATION);
}
}

Expand Down
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/vs/platform/externalServices/common/serviceMachineId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';

export async function getServiceMachineId(environmentService: IEnvironmentService, fileService: IFileService, storageService: IStorageService | undefined): Promise<string> {
let uuid: string | null = storageService ? storageService.get('storage.serviceMachineId', StorageScope.GLOBAL) || null : null;
let uuid: string | null = storageService ? storageService.get('storage.serviceMachineId', StorageScope.APPLICATION) || null : null;
if (uuid) {
return uuid;
}
Expand All @@ -31,7 +31,7 @@ export async function getServiceMachineId(environmentService: IEnvironmentServic
}
}

storageService?.store('storage.serviceMachineId', uuid, StorageScope.GLOBAL, StorageTarget.MACHINE);
storageService?.store('storage.serviceMachineId', uuid, StorageScope.APPLICATION, StorageTarget.MACHINE);

return uuid;
}
74 changes: 37 additions & 37 deletions src/vs/platform/storage/common/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const enum StorageScope {
/**
* The stored data will be scoped to all workspaces across all profiles.
*/
GLOBAL = -1,
APPLICATION = -1,

/**
* The stored data will be scoped to all workspaces of the same profile.
Expand Down Expand Up @@ -311,8 +311,8 @@ export abstract class AbstractStorageService extends Disposable implements IStor

// Clear our cached version which is now out of date
switch (scope) {
case StorageScope.GLOBAL:
this._globalKeyTargets = undefined;
case StorageScope.APPLICATION:
this._applicationKeyTargets = undefined;
break;
case StorageScope.PROFILE:
this._profileKeyTargets = undefined;
Expand Down Expand Up @@ -454,19 +454,19 @@ export abstract class AbstractStorageService extends Disposable implements IStor
return this._profileKeyTargets;
}

private _globalKeyTargets: IKeyTargets | undefined = undefined;
private get globalKeyTargets(): IKeyTargets {
if (!this._globalKeyTargets) {
this._globalKeyTargets = this.loadKeyTargets(StorageScope.GLOBAL);
private _applicationKeyTargets: IKeyTargets | undefined = undefined;
private get applicationKeyTargets(): IKeyTargets {
if (!this._applicationKeyTargets) {
this._applicationKeyTargets = this.loadKeyTargets(StorageScope.APPLICATION);
}

return this._globalKeyTargets;
return this._applicationKeyTargets;
}

private getKeyTargets(scope: StorageScope): IKeyTargets {
switch (scope) {
case StorageScope.GLOBAL:
return this.globalKeyTargets;
case StorageScope.APPLICATION:
return this.applicationKeyTargets;
case StorageScope.PROFILE:
return this.profileKeyTargets;
default:
Expand Down Expand Up @@ -496,7 +496,7 @@ export abstract class AbstractStorageService extends Disposable implements IStor
// Signal event to collect changes
this._onWillSaveState.fire({ reason });

const globalStorage = this.getStorage(StorageScope.GLOBAL);
const applicationStorage = this.getStorage(StorageScope.APPLICATION);
const profileStorage = this.getStorage(StorageScope.PROFILE);
const workspaceStorage = this.getStorage(StorageScope.WORKSPACE);

Expand All @@ -505,7 +505,7 @@ export abstract class AbstractStorageService extends Disposable implements IStor
// Unspecific reason: just wait when data is flushed
case WillSaveStateReason.NONE:
await Promises.settled([
globalStorage?.whenFlushed() ?? Promise.resolve(),
applicationStorage?.whenFlushed() ?? Promise.resolve(),
profileStorage?.whenFlushed() ?? Promise.resolve(),
workspaceStorage?.whenFlushed() ?? Promise.resolve()
]);
Expand All @@ -515,7 +515,7 @@ export abstract class AbstractStorageService extends Disposable implements IStor
// and not hit any delays that might be there
case WillSaveStateReason.SHUTDOWN:
await Promises.settled([
globalStorage?.flush(0) ?? Promise.resolve(),
applicationStorage?.flush(0) ?? Promise.resolve(),
profileStorage?.flush(0) ?? Promise.resolve(),
workspaceStorage?.flush(0) ?? Promise.resolve()
]);
Expand All @@ -524,15 +524,15 @@ export abstract class AbstractStorageService extends Disposable implements IStor
}

async log(): Promise<void> {
const globalItems = this.getStorage(StorageScope.GLOBAL)?.items ?? new Map<string, string>();
const applicationItems = this.getStorage(StorageScope.APPLICATION)?.items ?? new Map<string, string>();
const profileItems = this.getStorage(StorageScope.PROFILE)?.items ?? new Map<string, string>();
const workspaceItems = this.getStorage(StorageScope.WORKSPACE)?.items ?? new Map<string, string>();

return logStorage(
globalItems,
applicationItems,
profileItems,
workspaceItems,
this.getLogDetails(StorageScope.GLOBAL) ?? '',
this.getLogDetails(StorageScope.APPLICATION) ?? '',
this.getLogDetails(StorageScope.PROFILE) ?? '',
this.getLogDetails(StorageScope.WORKSPACE) ?? ''
);
Expand Down Expand Up @@ -595,7 +595,7 @@ export abstract class AbstractStorageService extends Disposable implements IStor

export class InMemoryStorageService extends AbstractStorageService {

private readonly globalStorage = this._register(new Storage(new InMemoryStorageDatabase()));
private readonly applicationStorage = this._register(new Storage(new InMemoryStorageDatabase()));
private readonly profileStorage = this._register(new Storage(new InMemoryStorageDatabase()));
private readonly workspaceStorage = this._register(new Storage(new InMemoryStorageDatabase()));

Expand All @@ -604,13 +604,13 @@ export class InMemoryStorageService extends AbstractStorageService {

this._register(this.workspaceStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.WORKSPACE, key)));
this._register(this.profileStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.PROFILE, key)));
this._register(this.globalStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.GLOBAL, key)));
this._register(this.applicationStorage.onDidChangeStorage(key => this.emitDidChangeValue(StorageScope.APPLICATION, key)));
}

protected getStorage(scope: StorageScope): IStorage {
switch (scope) {
case StorageScope.GLOBAL:
return this.globalStorage;
case StorageScope.APPLICATION:
return this.applicationStorage;
case StorageScope.PROFILE:
return this.profileStorage;
default:
Expand All @@ -620,8 +620,8 @@ export class InMemoryStorageService extends AbstractStorageService {

protected getLogDetails(scope: StorageScope): string | undefined {
switch (scope) {
case StorageScope.GLOBAL:
return 'inMemory (global)';
case StorageScope.APPLICATION:
return 'inMemory (application)';
case StorageScope.PROFILE:
return 'inMemory (profile)';
default:
Expand All @@ -640,7 +640,7 @@ export class InMemoryStorageService extends AbstractStorageService {
}
}

export async function logStorage(global: Map<string, string>, profile: Map<string, string>, workspace: Map<string, string>, globalPath: string, profilePath: string, workspacePath: string): Promise<void> {
export async function logStorage(application: Map<string, string>, profile: Map<string, string>, workspace: Map<string, string>, applicationPath: string, profilePath: string, workspacePath: string): Promise<void> {
const safeParse = (value: string) => {
try {
return JSON.parse(value);
Expand All @@ -649,11 +649,11 @@ export async function logStorage(global: Map<string, string>, profile: Map<strin
}
};

const globalItems = new Map<string, string>();
const globalItemsParsed = new Map<string, string>();
global.forEach((value, key) => {
globalItems.set(key, value);
globalItemsParsed.set(key, safeParse(value));
const applicationItems = new Map<string, string>();
const applicationItemsParsed = new Map<string, string>();
application.forEach((value, key) => {
applicationItems.set(key, value);
applicationItemsParsed.set(key, safeParse(value));
});

const profileItems = new Map<string, string>();
Expand All @@ -670,21 +670,21 @@ export async function logStorage(global: Map<string, string>, profile: Map<strin
workspaceItemsParsed.set(key, safeParse(value));
});

if (globalPath !== profilePath) {
console.group(`Storage: Global (path: ${globalPath})`);
if (applicationPath !== profilePath) {
console.group(`Storage: Application (path: ${applicationPath})`);
} else {
console.group(`Storage: Global & Profile (path: ${globalPath}, default profile)`);
console.group(`Storage: Application & Profile (path: ${applicationPath}, default profile)`);
}
const globalValues: { key: string; value: string }[] = [];
globalItems.forEach((value, key) => {
globalValues.push({ key, value });
const applicationValues: { key: string; value: string }[] = [];
applicationItems.forEach((value, key) => {
applicationValues.push({ key, value });
});
console.table(globalValues);
console.table(applicationValues);
console.groupEnd();

console.log(globalItemsParsed);
console.log(applicationItemsParsed);

if (globalPath !== profilePath) {
if (applicationPath !== profilePath) {
console.group(`Storage: Profile (path: ${profilePath}, profile specific)`);
const profileValues: { key: string; value: string }[] = [];
profileItems.forEach((value, key) => {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/storage/common/storageIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export interface IBaseSerializableStorageRequest {
/**
* Profile to correlate storage. Only used when no
* workspace is provided. Can be undefined to denote
* global scope.
* application scope.
*/
readonly profile: UriDto<IUserDataProfile> | undefined;

/**
* Workspace to correlate storage. Can be undefined to
* denote global or profile scope depending on profile.
* denote application or profile scope depending on profile.
*/
readonly workspace: ISerializedWorkspaceIdentifier | ISerializedSingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined;
}
Expand Down Expand Up @@ -102,15 +102,15 @@ abstract class BaseProfileAwareStorageDatabaseClient extends BaseStorageDatabase
}
}

export class GlobalStorageDatabaseClient extends BaseProfileAwareStorageDatabaseClient {
export class ApplicationStorageDatabaseClient extends BaseProfileAwareStorageDatabaseClient {

constructor(channel: IChannel) {
super(channel, undefined);
}

async close(): Promise<void> {

// The global storage database is shared across all instances so
// The application storage database is shared across all instances so
// we do not close it from the window. However we dispose the
// listener for external changes because we no longer interested in it.

Expand Down
12 changes: 6 additions & 6 deletions src/vs/platform/storage/electron-main/storageIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StorageDatabaseChannel extends Disposable implements IServerChannel

private static readonly STORAGE_CHANGE_DEBOUNCE_TIME = 100;

private readonly onDidChangeGlobalStorageEmitter = this._register(new Emitter<ISerializableItemsChangeEvent>());
private readonly onDidChangeApplicationStorageEmitter = this._register(new Emitter<ISerializableItemsChangeEvent>());

private readonly mapProfileToOnDidChangeProfileStorageEmitter = new Map<string /* profile ID */, Emitter<ISerializableItemsChangeEvent>>();

Expand All @@ -28,7 +28,7 @@ export class StorageDatabaseChannel extends Disposable implements IServerChannel
) {
super();

this.registerStorageChangeListeners(storageMainService.globalStorage, this.onDidChangeGlobalStorageEmitter);
this.registerStorageChangeListeners(storageMainService.applicationStorage, this.onDidChangeApplicationStorageEmitter);
}

//#region Storage Change Events
Expand Down Expand Up @@ -76,9 +76,9 @@ export class StorageDatabaseChannel extends Disposable implements IServerChannel
case 'onDidChangeStorage': {
const profile = arg.profile ? revive<IUserDataProfile>(arg.profile) : undefined;

// Without profile: global scope
// Without profile: application scope
if (!profile) {
return this.onDidChangeGlobalStorageEmitter.event;
return this.onDidChangeApplicationStorageEmitter.event;
}

// With profile: profile scope for the profile
Expand Down Expand Up @@ -137,13 +137,13 @@ export class StorageDatabaseChannel extends Disposable implements IServerChannel
} else if (profile) {
storage = this.storageMainService.profileStorage(profile);
} else {
storage = this.storageMainService.globalStorage;
storage = this.storageMainService.applicationStorage;
}

try {
await storage.init();
} catch (error) {
this.logService.error(`StorageIPC#init: Unable to init ${workspace ? 'workspace' : profile ? 'profile' : 'global'} storage due to ${error}`);
this.logService.error(`StorageIPC#init: Unable to init ${workspace ? 'workspace' : profile ? 'profile' : 'application'} storage due to ${error}`);
}

return storage;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/storage/electron-main/storageMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IStorageMainOptions {
}

/**
* Provides access to global, profile and workspace storage from
* Provides access to application, profile and workspace storage from
* the electron-main side that is the owner of all storage connections.
*/
export interface IStorageMain extends IDisposable {
Expand Down Expand Up @@ -295,7 +295,7 @@ export class ProfileStorageMain extends BaseProfileAwareStorageMain {
}
}

export class GlobalStorageMain extends BaseProfileAwareStorageMain {
export class ApplicationStorageMain extends BaseProfileAwareStorageMain {

constructor(
options: IStorageMainOptions,
Expand All @@ -309,7 +309,7 @@ export class GlobalStorageMain extends BaseProfileAwareStorageMain {
protected override async doInit(storage: IStorage): Promise<void> {
await super.doInit(storage);

// Apply telemetry values as part of the global storage initialization
// Apply telemetry values as part of the application storage initialization
this.updateTelemetryState(storage);
}

Expand Down

0 comments on commit f73cd16

Please sign in to comment.