diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index dfcc180ca34..862a359dfd9 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -100,10 +100,11 @@ import { InspectProfilingService as V8InspectProfilingService } from 'vs/platfor import { IV8InspectProfilingService } from 'vs/platform/profiling/common/profiling'; import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService'; import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService'; -import { IUserDataProfilesService, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; +import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; import { ExtensionsProfileScannerService, IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService'; import { PolicyChannelClient } from 'vs/platform/policy/common/policyIpc'; import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy'; +import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile'; import { OneDataSystemWebAppender } from 'vs/platform/telemetry/browser/1dsAppender'; class SharedProcessMain extends Disposable { @@ -231,7 +232,7 @@ class SharedProcessMain extends Disposable { fileService.registerProvider(Schemas.vscodeUserData, userDataFileSystemProvider); // User Data Profiles - const userDataProfilesService = this._register(new UserDataProfilesService(this.configuration.defaultProfile, environmentService, fileService, logService)); + const userDataProfilesService = this._register(new UserDataProfilesNativeService(this.configuration.profiles, mainProcessService, environmentService, fileService, logService)); services.set(IUserDataProfilesService, userDataProfilesService); // Configuration diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index fb2f5def29e..ec3b137d626 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -711,7 +711,9 @@ export class CodeApplication extends Disposable { sharedProcessClient.then(client => client.registerChannel(LOCAL_FILE_SYSTEM_CHANNEL_NAME, fileSystemProviderChannel)); // Profiles - mainProcessElectronServer.registerChannel('userDataProfiles', ProxyChannel.fromService(accessor.get(IUserDataProfilesMainService))); + const userDataProfilesService = ProxyChannel.fromService(accessor.get(IUserDataProfilesMainService)); + mainProcessElectronServer.registerChannel('userDataProfiles', userDataProfilesService); + sharedProcessClient.then(client => client.registerChannel('userDataProfiles', userDataProfilesService)); // Update const updateChannel = new UpdateChannel(accessor.get(IUpdateService)); diff --git a/src/vs/code/node/cliProcessMain.ts b/src/vs/code/node/cliProcessMain.ts index 3cda56cf0e5..ece4482cfbb 100644 --- a/src/vs/code/node/cliProcessMain.ts +++ b/src/vs/code/node/cliProcessMain.ts @@ -134,7 +134,7 @@ class CliMain extends Disposable { fileService.registerProvider(Schemas.file, diskFileSystemProvider); // User Data Profiles - const userDataProfilesService = new UserDataProfilesService(undefined, environmentService, fileService, logService); + const userDataProfilesService = new UserDataProfilesService(environmentService, fileService, logService); services.set(IUserDataProfilesService, userDataProfilesService); // Policy diff --git a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts index 7da986b840b..49267052530 100644 --- a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts +++ b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts @@ -242,7 +242,7 @@ export class SharedProcess extends Disposable implements ISharedProcess { appRoot: this.environmentMainService.appRoot, codeCachePath: this.environmentMainService.codeCachePath, backupWorkspacesPath: this.environmentMainService.backupWorkspacesPath, - defaultProfile: this.userDataProfilesService.defaultProfile, + profiles: this.userDataProfilesService.profiles, userEnv: this.userEnv, args: this.environmentMainService.args, logLevel: this.logService.getLevel(), diff --git a/src/vs/platform/sharedProcess/node/sharedProcess.ts b/src/vs/platform/sharedProcess/node/sharedProcess.ts index e445bc596d0..dafb357ea16 100644 --- a/src/vs/platform/sharedProcess/node/sharedProcess.ts +++ b/src/vs/platform/sharedProcess/node/sharedProcess.ts @@ -29,7 +29,7 @@ export interface ISharedProcessConfiguration extends ISandboxConfiguration { readonly backupWorkspacesPath: string; - readonly defaultProfile: UriDto; + readonly profiles: UriDto[]; readonly policiesData?: IStringDictionary<{ definition: PolicyDefinition; value: PolicyValue }>; } diff --git a/src/vs/platform/userData/test/browser/fileUserDataProvider.test.ts b/src/vs/platform/userData/test/browser/fileUserDataProvider.test.ts index 00f18d5163b..f6a9b0d6993 100644 --- a/src/vs/platform/userData/test/browser/fileUserDataProvider.test.ts +++ b/src/vs/platform/userData/test/browser/fileUserDataProvider.test.ts @@ -52,7 +52,7 @@ suite('FileUserDataProvider', () => { await testObject.createFolder(backupWorkspaceHomeOnDisk); environmentService = new TestEnvironmentService(userDataHomeOnDisk); - userDataProfilesService = new UserDataProfilesService(undefined, environmentService, testObject, logService); + userDataProfilesService = new UserDataProfilesService(environmentService, testObject, logService); fileUserDataProvider = new FileUserDataProvider(ROOT.scheme, fileSystemProvider, Schemas.vscodeUserData, logService); disposables.add(fileUserDataProvider); diff --git a/src/vs/platform/userDataProfile/common/userDataProfile.ts b/src/vs/platform/userDataProfile/common/userDataProfile.ts index 15b35fbf036..2d4b0776466 100644 --- a/src/vs/platform/userDataProfile/common/userDataProfile.ts +++ b/src/vs/platform/userDataProfile/common/userDataProfile.ts @@ -116,23 +116,20 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf readonly profilesHome: URI; - protected _defaultProfile: IUserDataProfile; - get defaultProfile(): IUserDataProfile { return this._defaultProfile; } - + private readonly _defaultProfile = this.createDefaultUserDataProfile(false); + get defaultProfile(): IUserDataProfile { return this.profiles[0] ?? this._defaultProfile; } get profiles(): IUserDataProfile[] { return []; } protected readonly _onDidChangeProfiles = this._register(new Emitter()); readonly onDidChangeProfiles = this._onDidChangeProfiles.event; constructor( - defaultProfile: UriDto | undefined, @IEnvironmentService protected readonly environmentService: IEnvironmentService, @IFileService protected readonly fileService: IFileService, @ILogService protected readonly logService: ILogService ) { super(); this.profilesHome = joinPath(this.environmentService.userRoamingDataHome, 'profiles'); - this._defaultProfile = defaultProfile ? reviveProfile(defaultProfile, this.profilesHome.scheme) : this.createDefaultUserDataProfile(false); } newProfile(name: string, useDefaultFlags?: UseDefaultProfileFlags): CustomUserDataProfile { diff --git a/src/vs/platform/userDataProfile/electron-main/userDataProfile.ts b/src/vs/platform/userDataProfile/electron-main/userDataProfile.ts index a1aadfd3823..0d3d4f2016e 100644 --- a/src/vs/platform/userDataProfile/electron-main/userDataProfile.ts +++ b/src/vs/platform/userDataProfile/electron-main/userDataProfile.ts @@ -32,7 +32,6 @@ export const IUserDataProfilesMainService = refineServiceDecorator; readonly onWillRemoveProfile: Event; - getAllProfiles(): Promise; } type UserDataProfilesObject = { @@ -69,38 +68,34 @@ export class UserDataProfilesMainService extends UserDataProfilesService impleme @IFileService fileService: IFileService, @ILogService logService: ILogService, ) { - super(undefined, environmentService, fileService, logService); + super(environmentService, fileService, logService); } init(): void { - if (this.storedProfiles.length) { - this._defaultProfile = this.createDefaultUserDataProfile(true); - } + this._profilesObject = undefined; } private _profilesObject: UserDataProfilesObject | undefined; private get profilesObject(): UserDataProfilesObject { if (!this._profilesObject) { const profiles = this.storedProfiles.map(storedProfile => toUserDataProfile(storedProfile.name, storedProfile.location, storedProfile.useDefaultFlags)); - profiles.unshift(this.defaultProfile); - const workspaces = this.storedWorskpaceInfos.reduce((workspaces, workspaceProfileInfo) => { - const profile = profiles.find(p => this.uriIdentityService.extUri.isEqual(p.location, workspaceProfileInfo.profile)); - if (profile) { - workspaces.set(workspaceProfileInfo.workspace, profile); + const workspaces = new ResourceMap(); + if (profiles.length) { + profiles.unshift(this.createDefaultUserDataProfile(true)); + for (const workspaceProfileInfo of this.storedWorskpaceInfos) { + const profile = profiles.find(p => this.uriIdentityService.extUri.isEqual(p.location, workspaceProfileInfo.profile)); + if (profile) { + workspaces.set(workspaceProfileInfo.workspace, profile); + } } - return workspaces; - }, new ResourceMap()); - this._profilesObject = { profiles: profiles, workspaces: workspaces }; + } + this._profilesObject = { profiles, workspaces }; } return this._profilesObject; } override get profiles(): IUserDataProfile[] { return this.profilesObject.profiles; } - async getAllProfiles(): Promise { - return this.profiles; - } - override getProfile(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): IUserDataProfile { return this.profilesObject.workspaces.get(this.getWorkspace(workspaceIdentifier)) ?? this.defaultProfile; } diff --git a/src/vs/platform/userDataProfile/electron-sandbox/userDataProfile.ts b/src/vs/platform/userDataProfile/electron-sandbox/userDataProfile.ts index 08b8b4c4c56..97ae03b8663 100644 --- a/src/vs/platform/userDataProfile/electron-sandbox/userDataProfile.ts +++ b/src/vs/platform/userDataProfile/electron-sandbox/userDataProfile.ts @@ -7,29 +7,28 @@ import { UriDto } from 'vs/base/common/types'; import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IFileService } from 'vs/platform/files/common/files'; +import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services'; import { ILogService } from 'vs/platform/log/common/log'; import { IUserDataProfile, IUserDataProfilesService, reviveProfile, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace'; export class UserDataProfilesNativeService extends UserDataProfilesService implements IUserDataProfilesService { + private readonly channel: IChannel; + private _profiles: IUserDataProfile[] = []; override get profiles(): IUserDataProfile[] { return this._profiles; } constructor( - defaultProfile: UriDto, - private readonly channel: IChannel, + profiles: UriDto[], + @IMainProcessService mainProcessService: IMainProcessService, @IEnvironmentService environmentService: IEnvironmentService, @IFileService fileService: IFileService, @ILogService logService: ILogService, ) { - super(defaultProfile, environmentService, fileService, logService); - this.initializeProfiles(); - } - - private async initializeProfiles(): Promise { - const result = await this.channel.call[]>('getAllProfiles'); - this._profiles = result.map(profile => reviveProfile(profile, this.profilesHome.scheme)); + super(environmentService, fileService, logService); + this.channel = mainProcessService.getChannel('userDataProfiles'); + this._profiles = profiles.map(profile => reviveProfile(profile, this.profilesHome.scheme)); this._register(this.channel.listen('onDidChangeProfiles')((profiles) => { this._profiles = profiles.map(profile => reviveProfile(profile, this.profilesHome.scheme)); this._onDidChangeProfiles.fire(this._profiles); diff --git a/src/vs/platform/userDataSync/test/common/userDataSyncClient.ts b/src/vs/platform/userDataSync/test/common/userDataSyncClient.ts index 1924fffc3ec..645181d8a3c 100644 --- a/src/vs/platform/userDataSync/test/common/userDataSyncClient.ts +++ b/src/vs/platform/userDataSync/test/common/userDataSyncClient.ts @@ -83,7 +83,7 @@ export class UserDataSyncClient extends Disposable { fileService.registerProvider(Schemas.inMemory, new InMemoryFileSystemProvider()); this.instantiationService.stub(IFileService, fileService); - const userDataProfilesService = this.instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(undefined, environmentService, fileService, logService)); + const userDataProfilesService = this.instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(environmentService, fileService, logService)); this.instantiationService.stub(IStorageService, this._register(new InMemoryStorageService())); diff --git a/src/vs/platform/window/common/window.ts b/src/vs/platform/window/common/window.ts index 875bd45f761..1b68d3a166f 100644 --- a/src/vs/platform/window/common/window.ts +++ b/src/vs/platform/window/common/window.ts @@ -285,7 +285,7 @@ export interface INativeWindowConfiguration extends IWindowConfiguration, Native backupPath?: string; profiles: { - default: UriDto; + all: UriDto[]; current: UriDto; }; diff --git a/src/vs/platform/windows/electron-main/window.ts b/src/vs/platform/windows/electron-main/window.ts index 79516573971..02524b2235b 100644 --- a/src/vs/platform/windows/electron-main/window.ts +++ b/src/vs/platform/windows/electron-main/window.ts @@ -905,7 +905,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { configuration.policiesData = this.policyService.serialize(); // set policies data again configuration.editSessionId = this.environmentMainService.editSessionId; // set latest edit session id configuration.profiles = { - default: this.userDataProfilesService.defaultProfile, + all: this.userDataProfilesService.profiles, current: configuration.workspace ? this.userDataProfilesService.getProfile(configuration.workspace) : this.userDataProfilesService.defaultProfile, }; diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 836e7f607d0..37cd6b32c68 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -1301,7 +1301,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic backupPath: options.emptyWindowBackupInfo ? join(this.environmentMainService.backupHome, options.emptyWindowBackupInfo.backupFolder) : undefined, profiles: { - default: this.userDataProfilesService.defaultProfile, + all: this.userDataProfilesService.profiles, current: options.workspace ? this.userDataProfilesService.getProfile(options.workspace) : this.userDataProfilesService.defaultProfile, }, diff --git a/src/vs/server/node/remoteExtensionHostAgentCli.ts b/src/vs/server/node/remoteExtensionHostAgentCli.ts index 520cca772bb..631a6d18b12 100644 --- a/src/vs/server/node/remoteExtensionHostAgentCli.ts +++ b/src/vs/server/node/remoteExtensionHostAgentCli.ts @@ -94,7 +94,7 @@ class CliMain extends Disposable { fileService.registerProvider(Schemas.file, this._register(new DiskFileSystemProvider(logService))); // User Data Profiles - const userDataProfilesService = this._register(new UserDataProfilesService(undefined, environmentService, fileService, logService)); + const userDataProfilesService = this._register(new UserDataProfilesService(environmentService, fileService, logService)); services.set(IUserDataProfilesService, userDataProfilesService); // Configuration diff --git a/src/vs/server/node/serverServices.ts b/src/vs/server/node/serverServices.ts index e3e267c1d94..9e8682f634b 100644 --- a/src/vs/server/node/serverServices.ts +++ b/src/vs/server/node/serverServices.ts @@ -111,7 +111,7 @@ export async function setupServerServices(connectionToken: ServerConnectionToken fileService.registerProvider(Schemas.file, disposables.add(new DiskFileSystemProvider(logService))); // Configuration - const userDataProfilesService = new UserDataProfilesService(undefined, environmentService, fileService, logService); + const userDataProfilesService = new UserDataProfilesService(environmentService, fileService, logService); const configurationService = new ConfigurationService(environmentService.machineSettingsResource, fileService, new NullPolicyService(), logService); services.set(IConfigurationService, configurationService); await configurationService.initialize(); diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts index 2a4f660e084..46659aff538 100644 --- a/src/vs/workbench/browser/web.main.ts +++ b/src/vs/workbench/browser/web.main.ts @@ -260,7 +260,7 @@ export class BrowserMain extends Disposable { await this.registerFileSystemProviders(environmentService, fileService, remoteAgentService, logService, logsPath); // User Data Profiles - const userDataProfilesService = new UserDataProfilesService(undefined, environmentService, fileService, logService); + const userDataProfilesService = new UserDataProfilesService(environmentService, fileService, logService); serviceCollection.set(IUserDataProfilesService, userDataProfilesService); const userDataProfileService = new UserDataProfileService(userDataProfilesService.defaultProfile, userDataProfilesService.defaultProfile); diff --git a/src/vs/workbench/electron-sandbox/desktop.main.ts b/src/vs/workbench/electron-sandbox/desktop.main.ts index c6fd800927c..89f0a8bfba0 100644 --- a/src/vs/workbench/electron-sandbox/desktop.main.ts +++ b/src/vs/workbench/electron-sandbox/desktop.main.ts @@ -241,7 +241,7 @@ export class DesktopMain extends Disposable { serviceCollection.set(IUriIdentityService, uriIdentityService); // User Data Profiles - const userDataProfilesService = new UserDataProfilesNativeService(this.configuration.profiles.default, mainProcessService.getChannel('userDataProfiles'), environmentService, fileService, logService); + const userDataProfilesService = new UserDataProfilesNativeService(this.configuration.profiles.all, mainProcessService, environmentService, fileService, logService); serviceCollection.set(IUserDataProfilesService, userDataProfilesService); const userDataProfileService = new UserDataProfileService(userDataProfilesService.defaultProfile, reviveProfile(this.configuration.profiles.current, userDataProfilesService.profilesHome.scheme)); serviceCollection.set(IUserDataProfileService, userDataProfileService); diff --git a/src/vs/workbench/services/extensions/test/browser/extensionStorageMigration.test.ts b/src/vs/workbench/services/extensions/test/browser/extensionStorageMigration.test.ts index 4811179de3e..e294342052f 100644 --- a/src/vs/workbench/services/extensions/test/browser/extensionStorageMigration.test.ts +++ b/src/vs/workbench/services/extensions/test/browser/extensionStorageMigration.test.ts @@ -38,7 +38,7 @@ suite('ExtensionStorageMigration', () => { fileService.registerProvider(ROOT.scheme, disposables.add(new InMemoryFileSystemProvider())); instantiationService.stub(IFileService, fileService); const environmentService = instantiationService.stub(IEnvironmentService, >{ userRoamingDataHome: ROOT, workspaceStorageHome }); - const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(undefined, environmentService, fileService, new NullLogService())); + const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(environmentService, fileService, new NullLogService())); instantiationService.stub(IUserDataProfileService, new UserDataProfileService(userDataProfilesService.defaultProfile, userDataProfilesService.defaultProfile)); instantiationService.stub(IExtensionStorageService, instantiationService.createInstance(ExtensionStorageService)); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 17e24745944..0284d2c46f4 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -283,7 +283,7 @@ export function workbenchInstantiationService( instantiationService.stub(IModelService, disposables.add(instantiationService.createInstance(ModelService))); const fileService = overrides?.fileService ? overrides.fileService(instantiationService) : new TestFileService(); instantiationService.stub(IFileService, fileService); - const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(undefined, environmentService, fileService, new NullLogService())); + const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(environmentService, fileService, new NullLogService())); instantiationService.stub(IUserDataProfileService, new UserDataProfileService(userDataProfilesService.defaultProfile, userDataProfilesService.defaultProfile)); instantiationService.stub(IUriIdentityService, new UriIdentityService(fileService)); instantiationService.stub(IWorkingCopyBackupService, new TestWorkingCopyBackupService()); diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index aa599aa191c..a72e83760bf 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -85,7 +85,7 @@ export const TestNativeWindowConfiguration: INativeWindowConfiguration = { homeDir: homeDir, tmpDir: tmpdir(), userDataDir: getUserDataPath(args), - profiles: { current: NULL_PROFILE, default: NULL_PROFILE }, + profiles: { current: NULL_PROFILE, all: [NULL_PROFILE] }, ...args }; @@ -289,7 +289,7 @@ export function workbenchInstantiationService(disposables = new DisposableStore( instantiationService.stub(INativeEnvironmentService, TestEnvironmentService); instantiationService.stub(IWorkbenchEnvironmentService, TestEnvironmentService); instantiationService.stub(INativeWorkbenchEnvironmentService, TestEnvironmentService); - const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(undefined, TestEnvironmentService, new FileService(new NullLogService()), new NullLogService())); + const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(TestEnvironmentService, new FileService(new NullLogService()), new NullLogService())); instantiationService.stub(IUserDataProfileService, new UserDataProfileService(userDataProfilesService.defaultProfile, userDataProfilesService.defaultProfile)); return instantiationService;