Skip to content

Commit 57e2524

Browse files
committed
introduce transient profiles
1 parent 1e6ac12 commit 57e2524

File tree

20 files changed

+344
-128
lines changed

20 files changed

+344
-128
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Disposable } from 'vs/base/common/lifecycle';
7+
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
8+
9+
export class UserDataProfilesCleaner extends Disposable {
10+
11+
constructor(
12+
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
13+
) {
14+
super();
15+
userDataProfilesService.cleanUp();
16+
}
17+
18+
}

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/pol
105105
import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile';
106106
import { SharedProcessRequestService } from 'vs/platform/request/electron-browser/sharedProcessRequestService';
107107
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
108+
import { UserDataProfilesCleaner } from 'vs/code/electron-browser/sharedProcess/contrib/userDataProfilesCleaner';
108109

109110
class SharedProcessMain extends Disposable {
110111

@@ -169,7 +170,8 @@ class SharedProcessMain extends Disposable {
169170
instantiationService.createInstance(StorageDataCleaner, this.configuration.backupWorkspacesPath),
170171
instantiationService.createInstance(LogsDataCleaner),
171172
instantiationService.createInstance(LocalizationsUpdater),
172-
instantiationService.createInstance(ExtensionsCleaner)
173+
instantiationService.createInstance(ExtensionsCleaner),
174+
instantiationService.createInstance(UserDataProfilesCleaner)
173175
));
174176
}
175177

src/vs/code/electron-main/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import { IRequestService } from 'vs/platform/request/common/request';
108108
import { ExtensionsProfileScannerService, IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService';
109109
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';
110110
import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService';
111+
import { UserDataTransientProfilesHandler } from 'vs/platform/userDataProfile/electron-main/userDataTransientProfilesHandler';
111112

112113
/**
113114
* The main VS Code application. There will only ever be one instance,
@@ -562,6 +563,9 @@ export class CodeApplication extends Disposable {
562563

563564
// Default Extensions Profile Init Handler
564565
this._register(instantiationService.createInstance(DefaultExtensionsProfileInitHandler));
566+
567+
// Transient profiles handler
568+
this._register(instantiationService.createInstance(UserDataTransientProfilesHandler));
565569
}
566570

567571
private async resolveMachineId(): Promise<string> {

src/vs/platform/environment/common/argv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface NativeParsedArgs {
9292
editSessionId?: string;
9393
'locate-shell-integration-path'?: string;
9494
'profile'?: string;
95+
'transient'?: boolean;
9596

9697
// chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches
9798
'no-proxy-server'?: boolean;

src/vs/platform/environment/node/argv.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
5050
'waitMarkerFilePath': { type: 'string' },
5151
'locale': { type: 'string', cat: 'o', args: 'locale', description: localize('locale', "The locale to use (e.g. en-US or zh-TW).") },
5252
'user-data-dir': { type: 'string', cat: 'o', args: 'dir', description: localize('userDataDir', "Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.") },
53-
'profile': { type: 'string', 'cat': 'o', args: 'settingsProfileName', description: localize('settingsProfileName', "Opens the provided folder or workspace with the given profile. If the profile does not exist, a new empty one is created.") },
53+
'profile': { type: 'string', 'cat': 'o', args: 'settingsProfileName', description: localize('settingsProfileName', "Opens the provided folder or workspace with the given profile. If the profile does not exist, a new empty one is created. Use '--transient' argument to not to persist the profile.") },
5454
'help': { type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") },
5555

5656
'extensions-dir': { type: 'string', deprecates: ['extensionHomePath'], cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") },
@@ -130,6 +130,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
130130
'__enable-file-policy': { type: 'boolean' },
131131
'editSessionId': { type: 'string' },
132132
'locate-shell-integration-path': { type: 'string', args: ['bash', 'pwsh', 'zsh', 'fish'] },
133+
'transient': { type: 'boolean' },
133134

134135
// chromium flags
135136
'no-proxy-server': { type: 'boolean' },

src/vs/platform/userDataProfile/browser/userDataProfile.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,42 @@ export class BrowserUserDataProfilesService extends UserDataProfilesService impl
3131
this._register(this.changesBroadcastChannel.onDidReceiveData(changes => {
3232
try {
3333
this._profilesObject = undefined;
34+
const added = changes.added.map(p => reviveProfile(p, this.profilesHome.scheme));
35+
const removed = changes.removed.map(p => reviveProfile(p, this.profilesHome.scheme));
36+
const updated = changes.updated.map(p => reviveProfile(p, this.profilesHome.scheme));
37+
38+
this.updateTransientProfiles(
39+
added.filter(a => a.isTransient),
40+
removed.filter(a => a.isTransient),
41+
updated.filter(a => a.isTransient)
42+
);
43+
3444
this._onDidChangeProfiles.fire({
35-
added: changes.added.map(p => reviveProfile(p, this.profilesHome.scheme)),
36-
removed: changes.removed.map(p => reviveProfile(p, this.profilesHome.scheme)),
37-
updated: changes.updated.map(p => reviveProfile(p, this.profilesHome.scheme)),
45+
added,
46+
removed,
47+
updated,
3848
all: this.profiles
3949
});
4050
} catch (error) {/* ignore */ }
4151
}));
4252
}
4353

54+
private updateTransientProfiles(added: IUserDataProfile[], removed: IUserDataProfile[], updated: IUserDataProfile[]): void {
55+
if (added.length) {
56+
this.transientProfilesObject.profiles.push(...added);
57+
}
58+
if (removed.length || updated.length) {
59+
const allTransientProfiles = this.transientProfilesObject.profiles;
60+
this.transientProfilesObject.profiles = [];
61+
for (const profile of allTransientProfiles) {
62+
if (removed.some(p => profile.id === p.id)) {
63+
continue;
64+
}
65+
this.transientProfilesObject.profiles.push(updated.find(p => profile.id === p.id) ?? profile);
66+
}
67+
}
68+
}
69+
4470
override setEnablement(enabled: boolean): void {
4571
super.setEnablement(enabled);
4672
window.localStorage.setItem(PROFILES_ENABLEMENT_CONFIG, enabled ? 'true' : 'false');

0 commit comments

Comments
 (0)