Skip to content

Commit

Permalink
prepare for server profiles (microsoft#174232)
Browse files Browse the repository at this point in the history
* prepare for server profiles
- make state service available in server
- Intrdouce save stragey in state service - state shall be saved immediately in server
- use UserDataProfilesService that can save profiles in server

* feedback

* - add tests
- register IStateReadService in main
  • Loading branch information
sandy081 authored and c-claeys committed Feb 16, 2023
1 parent 45194bd commit 455f734
Show file tree
Hide file tree
Showing 27 changed files with 330 additions and 218 deletions.
8 changes: 4 additions & 4 deletions src/vs/code/electron-main/app.ts
Expand Up @@ -65,7 +65,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
import { SharedProcess } from 'vs/platform/sharedProcess/electron-main/sharedProcess';
import { ISignService } from 'vs/platform/sign/common/sign';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { IStateService } from 'vs/platform/state/node/state';
import { StorageDatabaseChannel } from 'vs/platform/storage/electron-main/storageIpc';
import { ApplicationStorageMainService, IApplicationStorageMainService, IStorageMainService, StorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
Expand Down Expand Up @@ -131,7 +131,7 @@ export class CodeApplication extends Disposable {
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IStateMainService private readonly stateMainService: IStateMainService,
@IStateService private readonly stateService: IStateService,
@IFileService private readonly fileService: IFileService,
@IProductService private readonly productService: IProductService,
@IUserDataProfilesMainService private readonly userDataProfilesMainService: IUserDataProfilesMainService,
Expand Down Expand Up @@ -528,7 +528,7 @@ export class CodeApplication extends Disposable {

// Resolve unique machine ID
this.logService.trace('Resolving machine identifier...');
const machineId = await resolveMachineId(this.stateMainService);
const machineId = await resolveMachineId(this.stateService);
this.logService.trace(`Resolved machine identifier: ${machineId}`);

// Shared process
Expand Down Expand Up @@ -920,7 +920,7 @@ export class CodeApplication extends Disposable {
}

// Backups
const backupMainService = new BackupMainService(this.environmentMainService, this.configurationService, this.logService, this.stateMainService);
const backupMainService = new BackupMainService(this.environmentMainService, this.configurationService, this.logService, this.stateService);
services.set(IBackupMainService, backupMainService);

// Workspaces
Expand Down
19 changes: 10 additions & 9 deletions src/vs/code/electron-main/main.ts
Expand Up @@ -56,8 +56,7 @@ import { IRequestService } from 'vs/platform/request/common/request';
import { RequestMainService } from 'vs/platform/request/electron-main/requestMainService';
import { ISignService } from 'vs/platform/sign/common/sign';
import { SignService } from 'vs/platform/sign/node/signService';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { StateMainService } from 'vs/platform/state/electron-main/stateMainService';
import { IStateReadService, IStateService } from 'vs/platform/state/node/state';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IThemeMainService, ThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
import { IUserDataProfilesMainService, UserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
Expand All @@ -70,6 +69,7 @@ import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentitySe
import { ILoggerMainService, LoggerMainService } from 'vs/platform/log/electron-main/loggerService';
import { LogService } from 'vs/platform/log/common/logService';
import { massageMessageBoxOptions } from 'vs/platform/dialogs/common/dialogs';
import { SaveStrategy, StateService } from 'vs/platform/state/node/stateService';

/**
* The main VS Code entry point.
Expand Down Expand Up @@ -147,7 +147,7 @@ class CodeMain {
}
}

private createServices(): [IInstantiationService, IProcessEnvironment, IEnvironmentMainService, ConfigurationService, StateMainService, BufferLogger, IProductService, UserDataProfilesMainService] {
private createServices(): [IInstantiationService, IProcessEnvironment, IEnvironmentMainService, ConfigurationService, StateService, BufferLogger, IProductService, UserDataProfilesMainService] {
const services = new ServiceCollection();
const disposables = new DisposableStore();
process.once('exit', () => disposables.dispose());
Expand Down Expand Up @@ -183,11 +183,12 @@ class CodeMain {
services.set(IUriIdentityService, uriIdentityService);

// State
const stateMainService = new StateMainService(environmentMainService, logService, fileService);
services.set(IStateMainService, stateMainService);
const stateService = new StateService(SaveStrategy.DELAYED, environmentMainService, logService, fileService);
services.set(IStateReadService, stateService);
services.set(IStateService, stateService);

// User Data Profiles
const userDataProfilesMainService = new UserDataProfilesMainService(stateMainService, uriIdentityService, environmentMainService, fileService, logService);
const userDataProfilesMainService = new UserDataProfilesMainService(stateService, uriIdentityService, environmentMainService, fileService, logService);
services.set(IUserDataProfilesMainService, userDataProfilesMainService);

// Policy
Expand Down Expand Up @@ -218,7 +219,7 @@ class CodeMain {
// Protocol (instantiated early and not using sync descriptor for security reasons)
services.set(IProtocolMainService, new ProtocolMainService(environmentMainService, userDataProfilesMainService, logService));

return [new InstantiationService(services, true), instanceEnvironment, environmentMainService, configurationService, stateMainService, bufferLogger, productService, userDataProfilesMainService];
return [new InstantiationService(services, true), instanceEnvironment, environmentMainService, configurationService, stateService, bufferLogger, productService, userDataProfilesMainService];
}

private patchEnvironment(environmentMainService: IEnvironmentMainService): IProcessEnvironment {
Expand All @@ -238,7 +239,7 @@ class CodeMain {
return instanceEnvironment;
}

private async initServices(environmentMainService: IEnvironmentMainService, userDataProfilesMainService: UserDataProfilesMainService, configurationService: ConfigurationService, stateMainService: StateMainService, productService: IProductService): Promise<void> {
private async initServices(environmentMainService: IEnvironmentMainService, userDataProfilesMainService: UserDataProfilesMainService, configurationService: ConfigurationService, stateService: StateService, productService: IProductService): Promise<void> {
await Promises.settled<unknown>([

// Environment service (paths)
Expand All @@ -253,7 +254,7 @@ class CodeMain {
].map(path => path ? FSPromises.mkdir(path, { recursive: true }) : undefined)),

// State service
stateMainService.init(),
stateService.init(),

// Configuration service
configurationService.initialize()
Expand Down
10 changes: 4 additions & 6 deletions src/vs/code/node/cliProcessMain.ts
Expand Up @@ -48,8 +48,7 @@ import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { IRequestService } from 'vs/platform/request/common/request';
import { RequestService } from 'vs/platform/request/node/requestService';
import { IStateService } from 'vs/platform/state/node/state';
import { StateService } from 'vs/platform/state/node/stateService';
import { SaveStrategy, StateReadonlyService } from 'vs/platform/state/node/stateService';
import { resolveCommonProperties } from 'vs/platform/telemetry/common/commonProperties';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITelemetryServiceConfig, TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
Expand All @@ -59,7 +58,7 @@ import { buildTelemetryMessage } from 'vs/platform/telemetry/node/telemetry';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
import { UserDataProfilesService } from 'vs/platform/userDataProfile/node/userDataProfile';
import { UserDataProfilesReadonlyService } from 'vs/platform/userDataProfile/node/userDataProfile';
import { resolveMachineId } from 'vs/platform/telemetry/node/telemetryUtils';
import { ExtensionsProfileScannerService } from 'vs/platform/extensionManagement/node/extensionsProfileScannerService';
import { LogService } from 'vs/platform/log/common/logService';
Expand Down Expand Up @@ -144,15 +143,14 @@ class CliMain extends Disposable {
fileService.registerProvider(Schemas.file, diskFileSystemProvider);

// State
const stateService = new StateService(environmentService, logService, fileService);
services.set(IStateService, stateService);

// Uri Identity
const uriIdentityService = new UriIdentityService(fileService);
services.set(IUriIdentityService, uriIdentityService);

// User Data Profiles
const userDataProfilesService = new UserDataProfilesService(stateService, uriIdentityService, environmentService, fileService, logService);
const stateService = new StateReadonlyService(SaveStrategy.DELAYED, environmentService, logService, fileService);
const userDataProfilesService = new UserDataProfilesReadonlyService(stateService, uriIdentityService, environmentService, fileService, logService);
services.set(IUserDataProfilesService, userDataProfilesService);

// Policy
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/backup/electron-main/backupMainService.ts
Expand Up @@ -14,7 +14,7 @@ import { IBackupMainService } from 'vs/platform/backup/electron-main/backup';
import { ISerializedBackupWorkspaces, IEmptyWindowBackupInfo, isEmptyWindowBackupInfo, deserializeWorkspaceInfos, deserializeFolderInfos, ISerializedWorkspaceBackupInfo, ISerializedFolderBackupInfo, ISerializedEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { IStateService } from 'vs/platform/state/node/state';
import { HotExitConfiguration, IFilesConfiguration } from 'vs/platform/files/common/files';
import { ILogService } from 'vs/platform/log/common/log';
import { IFolderBackupInfo, isFolderBackupInfo, IWorkspaceBackupInfo } from 'vs/platform/backup/common/backup';
Expand Down Expand Up @@ -43,14 +43,14 @@ export class BackupMainService implements IBackupMainService {
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@ILogService private readonly logService: ILogService,
@IStateMainService private readonly stateMainService: IStateMainService
@IStateService private readonly stateService: IStateService
) {
}

async initialize(): Promise<void> {

// read backup workspaces
const serializedBackupWorkspaces = this.stateMainService.getItem<ISerializedBackupWorkspaces>(BackupMainService.backupWorkspacesMetadataStorageKey) ?? { workspaces: [], folders: [], emptyWindows: [] };
const serializedBackupWorkspaces = this.stateService.getItem<ISerializedBackupWorkspaces>(BackupMainService.backupWorkspacesMetadataStorageKey) ?? { workspaces: [], folders: [], emptyWindows: [] };

// validate empty workspaces backups first
this.emptyWindows = await this.validateEmptyWorkspaces(serializedBackupWorkspaces.emptyWindows);
Expand Down Expand Up @@ -397,7 +397,7 @@ export class BackupMainService implements IBackupMainService {
})
};

this.stateMainService.setItem(BackupMainService.backupWorkspacesMetadataStorageKey, serializedBackupWorkspaces);
this.stateService.setItem(BackupMainService.backupWorkspacesMetadataStorageKey, serializedBackupWorkspaces);
}

protected getFolderHash(folder: IFolderBackupInfo): string {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/issue/electron-main/issueMainService.ts
Expand Up @@ -26,7 +26,7 @@ import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
import { IWindowState } from 'vs/platform/window/electron-main/window';
import { randomPath } from 'vs/base/common/extpath';
import { withNullAsUndefined } from 'vs/base/common/types';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { IStateService } from 'vs/platform/state/node/state';

export const IIssueMainService = createDecorator<IIssueMainService>('issueMainService');
const processExplorerWindowState = 'issue.processExplorerWindowState';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class IssueMainService implements IIssueMainService {
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService,
@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
@IProductService private readonly productService: IProductService,
@IStateMainService private readonly stateMainService: IStateMainService
@IStateService private readonly stateService: IStateService
) {
this.registerListeners();
}
Expand Down Expand Up @@ -255,7 +255,7 @@ export class IssueMainService implements IIssueMainService {

const processExplorerWindowConfigUrl = processExplorerDisposables.add(this.protocolMainService.createIPCObjectUrl<ProcessExplorerWindowConfiguration>());

const savedPosition = this.stateMainService.getItem<IWindowState>(processExplorerWindowState, undefined);
const savedPosition = this.stateService.getItem<IWindowState>(processExplorerWindowState, undefined);
const position = isStrictWindowState(savedPosition) ? savedPosition : this.getWindowPosition(this.processExplorerParentWindow, 800, 500);

// Correct dimensions to take scale/dpr into account
Expand Down Expand Up @@ -312,7 +312,7 @@ export class IssueMainService implements IIssueMainService {
x: position[0],
y: position[1]
};
this.stateMainService.setItem(processExplorerWindowState, state);
this.stateService.setItem(processExplorerWindowState, state);
};

this.processExplorerWindow.on('moved', storeState);
Expand Down
12 changes: 6 additions & 6 deletions src/vs/platform/lifecycle/electron-main/lifecycleMainService.ts
Expand Up @@ -14,7 +14,7 @@ import { assertIsDefined } from 'vs/base/common/types';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { IStateService } from 'vs/platform/state/node/state';
import { ICodeWindow, LoadReason, UnloadReason } from 'vs/platform/window/electron-main/window';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
Expand Down Expand Up @@ -226,7 +226,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe

constructor(
@ILogService private readonly logService: ILogService,
@IStateMainService private readonly stateMainService: IStateMainService,
@IStateService private readonly stateService: IStateService,
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService
) {
super();
Expand All @@ -236,11 +236,11 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
}

private resolveRestarted(): void {
this._wasRestarted = !!this.stateMainService.getItem(LifecycleMainService.QUIT_AND_RESTART_KEY);
this._wasRestarted = !!this.stateService.getItem(LifecycleMainService.QUIT_AND_RESTART_KEY);

if (this._wasRestarted) {
// remove the marker right after if found
this.stateMainService.removeItem(LifecycleMainService.QUIT_AND_RESTART_KEY);
this.stateService.removeItem(LifecycleMainService.QUIT_AND_RESTART_KEY);
}
}

Expand Down Expand Up @@ -347,7 +347,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
// Then, always make sure at the end
// the state service is flushed.
try {
await this.stateMainService.close();
await this.stateService.close();
} catch (error) {
this.logService.error(error);
}
Expand Down Expand Up @@ -563,7 +563,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe

// Remember if we are about to restart
if (willRestart) {
this.stateMainService.setItem(LifecycleMainService.QUIT_AND_RESTART_KEY, true);
this.stateService.setItem(LifecycleMainService.QUIT_AND_RESTART_KEY, true);
}

this.pendingQuitPromise = new Promise(resolve => {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/menubar/electron-main/menubar.ts
Expand Up @@ -18,7 +18,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IMenubarData, IMenubarKeybinding, IMenubarMenu, IMenubarMenuRecentItemAction, isMenubarMenuItemAction, isMenubarMenuItemRecentAction, isMenubarMenuItemSeparator, isMenubarMenuItemSubmenu, MenubarMenuItem } from 'vs/platform/menubar/common/menubar';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
import { IProductService } from 'vs/platform/product/common/productService';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { IStateService } from 'vs/platform/state/node/state';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IUpdateService, StateType } from 'vs/platform/update/common/update';
import { getTitleBarStyle, INativeRunActionInWindowRequest, INativeRunKeybindingInWindowRequest, IWindowOpenable } from 'vs/platform/window/common/window';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class Menubar {
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IWorkspacesHistoryMainService private readonly workspacesHistoryMainService: IWorkspacesHistoryMainService,
@IStateMainService private readonly stateMainService: IStateMainService,
@IStateService private readonly stateService: IStateService,
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
@ILogService private readonly logService: ILogService,
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService,
Expand Down Expand Up @@ -100,7 +100,7 @@ export class Menubar {
}

private restoreCachedMenubarData() {
const menubarData = this.stateMainService.getItem<IMenubarData>(Menubar.lastKnownMenubarStorageKey);
const menubarData = this.stateService.getItem<IMenubarData>(Menubar.lastKnownMenubarStorageKey);
if (menubarData) {
if (menubarData.menus) {
this.menubarMenus = menubarData.menus;
Expand Down Expand Up @@ -197,7 +197,7 @@ export class Menubar {
this.keybindings = menubarData.keybindings;

// Save off new menu and keybindings
this.stateMainService.setItem(Menubar.lastKnownMenubarStorageKey, menubarData);
this.stateService.setItem(Menubar.lastKnownMenubarStorageKey, menubarData);

this.scheduleUpdateMenu();
}
Expand Down

0 comments on commit 455f734

Please sign in to comment.