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

fix default profile #152915

Merged
merged 2 commits into from Jun 23, 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 @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/vs/code/electron-main/app.ts
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/node/cliProcessMain.ts
Expand Up @@ -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
Expand Down
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/sharedProcess/node/sharedProcess.ts
Expand Up @@ -29,7 +29,7 @@ export interface ISharedProcessConfiguration extends ISandboxConfiguration {

readonly backupWorkspacesPath: string;

readonly defaultProfile: UriDto<IUserDataProfile>;
readonly profiles: UriDto<IUserDataProfile>[];

readonly policiesData?: IStringDictionary<{ definition: PolicyDefinition; value: PolicyValue }>;
}
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/vs/platform/userDataProfile/common/userDataProfile.ts
Expand Up @@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be this.profiles?.[0]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rzhao271 looks like this.profiles is always defined and there’s no setter to overwrite that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right.

get profiles(): IUserDataProfile[] { return []; }

protected readonly _onDidChangeProfiles = this._register(new Emitter<IUserDataProfile[]>());
readonly onDidChangeProfiles = this._onDidChangeProfiles.event;

constructor(
defaultProfile: UriDto<IUserDataProfile> | 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 {
Expand Down
29 changes: 12 additions & 17 deletions src/vs/platform/userDataProfile/electron-main/userDataProfile.ts
Expand Up @@ -32,7 +32,6 @@ export const IUserDataProfilesMainService = refineServiceDecorator<IUserDataProf
export interface IUserDataProfilesMainService extends IUserDataProfilesService {
readonly onWillCreateProfile: Event<WillCreateProfileEvent>;
readonly onWillRemoveProfile: Event<WillRemoveProfileEvent>;
getAllProfiles(): Promise<IUserDataProfile[]>;
}

type UserDataProfilesObject = {
Expand Down Expand Up @@ -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<IUserDataProfile>(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<IUserDataProfile>();
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<IUserDataProfile>());
this._profilesObject = { profiles: profiles, workspaces: workspaces };
}
this._profilesObject = { profiles, workspaces };
}
return this._profilesObject;
}

override get profiles(): IUserDataProfile[] { return this.profilesObject.profiles; }

async getAllProfiles(): Promise<IUserDataProfile[]> {
return this.profiles;
}

override getProfile(workspaceIdentifier: ISingleFolderWorkspaceIdentifier | IWorkspaceIdentifier): IUserDataProfile {
return this.profilesObject.workspaces.get(this.getWorkspace(workspaceIdentifier)) ?? this.defaultProfile;
}
Expand Down
Expand Up @@ -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<IUserDataProfile>,
private readonly channel: IChannel,
profiles: UriDto<IUserDataProfile>[],
@IMainProcessService mainProcessService: IMainProcessService,
@IEnvironmentService environmentService: IEnvironmentService,
@IFileService fileService: IFileService,
@ILogService logService: ILogService,
) {
super(defaultProfile, environmentService, fileService, logService);
this.initializeProfiles();
}

private async initializeProfiles(): Promise<void> {
const result = await this.channel.call<UriDto<IUserDataProfile>[]>('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<IUserDataProfile[]>('onDidChangeProfiles')((profiles) => {
this._profiles = profiles.map(profile => reviveProfile(profile, this.profilesHome.scheme));
this._onDidChangeProfiles.fire(this._profiles);
Expand Down
Expand Up @@ -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()));

Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/window/common/window.ts
Expand Up @@ -285,7 +285,7 @@ export interface INativeWindowConfiguration extends IWindowConfiguration, Native
backupPath?: string;

profiles: {
default: UriDto<IUserDataProfile>;
all: UriDto<IUserDataProfile>[];
current: UriDto<IUserDataProfile>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/windows/electron-main/window.ts
Expand Up @@ -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,
};

Expand Down
Expand Up @@ -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,
},

Expand Down
2 changes: 1 addition & 1 deletion src/vs/server/node/remoteExtensionHostAgentCli.ts
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vs/server/node/serverServices.ts
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/web.main.ts
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/electron-sandbox/desktop.main.ts
Expand Up @@ -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);
Expand Down
Expand Up @@ -38,7 +38,7 @@ suite('ExtensionStorageMigration', () => {
fileService.registerProvider(ROOT.scheme, disposables.add(new InMemoryFileSystemProvider()));
instantiationService.stub(IFileService, fileService);
const environmentService = instantiationService.stub(IEnvironmentService, <Partial<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));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/test/browser/workbenchTestServices.ts
Expand Up @@ -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());
Expand Down
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
Expand Down