Skip to content

Commit 3d4a1bc

Browse files
sandy081bpasero
andauthored
Split IUserDataProfilesService (microsoft#152385)
* - extract IUserDataProfileService from IUserDataProfilesService - Adopt it * 💄 Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 761f8b2 commit 3d4a1bc

File tree

44 files changed

+375
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+375
-309
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ import { InspectProfilingService as V8InspectProfilingService } from 'vs/platfor
100100
import { IV8InspectProfilingService } from 'vs/platform/profiling/common/profiling';
101101
import { IExtensionsScannerService } from 'vs/platform/extensionManagement/common/extensionsScannerService';
102102
import { ExtensionsScannerService } from 'vs/platform/extensionManagement/node/extensionsScannerService';
103-
import { IUserDataProfilesService, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
103+
import { IUserDataProfileService, IUserDataProfilesService, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
104104
import { ExtensionsProfileScannerService, IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService';
105105
import { PolicyChannelClient } from 'vs/platform/policy/common/policyIpc';
106106
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
107107
import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
108+
import { UserDataProfileService } from 'vs/platform/userDataProfile/common/userDataProfileService';
108109
// import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender';
109110

110111
class SharedProcessMain extends Disposable {
@@ -232,15 +233,18 @@ class SharedProcessMain extends Disposable {
232233
fileService.registerProvider(Schemas.vscodeUserData, userDataFileSystemProvider);
233234

234235
// User Data Profiles
235-
const userDataProfilesService = this._register(new UserDataProfilesService(this.configuration.defaultProfile, undefined, environmentService, fileService, logService));
236+
const userDataProfilesService = this._register(new UserDataProfilesService(this.configuration.defaultProfile, environmentService, fileService, logService));
236237
services.set(IUserDataProfilesService, userDataProfilesService);
237238

239+
const userDataProfileService = this._register(new UserDataProfileService(userDataProfilesService.defaultProfile, userDataProfilesService.defaultProfile));
240+
services.set(IUserDataProfileService, userDataProfileService);
241+
238242
// Configuration
239243
const configurationService = this._register(new ConfigurationService(userDataProfilesService.defaultProfile.settingsResource, fileService, policyService, logService));
240244
services.set(IConfigurationService, configurationService);
241245

242246
// Storage (global access only)
243-
const storageService = new NativeStorageService(undefined, mainProcessService, userDataProfilesService, environmentService);
247+
const storageService = new NativeStorageService(undefined, mainProcessService, userDataProfileService, environmentService);
244248
services.set(IStorageService, storageService);
245249
this._register(toDisposable(() => storageService.flush()));
246250

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ import { IWorkspacesHistoryMainService, WorkspacesHistoryMainService } from 'vs/
9999
import { WorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
100100
import { IWorkspacesManagementMainService, WorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService';
101101
import { CredentialsNativeMainService } from 'vs/platform/credentials/electron-main/credentialsMainService';
102-
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
103102
import { IPolicyService } from 'vs/platform/policy/common/policy';
104103
import { PolicyChannel } from 'vs/platform/policy/common/policyIpc';
104+
import { IUserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
105105

106106
/**
107107
* The main VS Code application. There will only ever be one instance,
@@ -711,8 +711,7 @@ export class CodeApplication extends Disposable {
711711
sharedProcessClient.then(client => client.registerChannel(LOCAL_FILE_SYSTEM_CHANNEL_NAME, fileSystemProviderChannel));
712712

713713
// Profiles
714-
const userDataProfilesService = ProxyChannel.fromService(accessor.get(IUserDataProfilesService));
715-
mainProcessElectronServer.registerChannel('userDataProfiles', userDataProfilesService);
714+
mainProcessElectronServer.registerChannel('userDataProfiles', ProxyChannel.fromService(accessor.get(IUserDataProfilesMainService)));
716715

717716
// Update
718717
const updateChannel = new UpdateChannel(accessor.get(IUpdateService));

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ import { IStateMainService } from 'vs/platform/state/electron-main/state';
6262
import { StateMainService } from 'vs/platform/state/electron-main/stateMainService';
6363
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
6464
import { IThemeMainService, ThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
65-
import { UserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
66-
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
65+
import { IUserDataProfilesMainService, UserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
6766
import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/policy';
6867
import { NativePolicyService } from 'vs/platform/policy/node/nativePolicyService';
6968
import { FilePolicyService } from 'vs/platform/policy/common/filePolicyService';
@@ -185,7 +184,7 @@ class CodeMain {
185184

186185
// User Data Profiles
187186
const userDataProfilesMainService = new UserDataProfilesMainService(stateMainService, uriIdentityService, environmentMainService, fileService, logService);
188-
services.set(IUserDataProfilesService, userDataProfilesMainService);
187+
services.set(IUserDataProfilesMainService, userDataProfilesMainService);
189188

190189
// Policy
191190
const policyService = isWindows && productService.win32RegValueName ? disposables.add(new NativePolicyService(productService.win32RegValueName))

src/vs/code/node/cliProcessMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class CliMain extends Disposable {
134134
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
135135

136136
// User Data Profiles
137-
const userDataProfilesService = new UserDataProfilesService(undefined, undefined, environmentService, fileService, logService);
137+
const userDataProfilesService = new UserDataProfilesService(undefined, environmentService, fileService, logService);
138138
services.set(IUserDataProfilesService, userDataProfilesService);
139139

140140
// Policy

src/vs/platform/extensionManagement/common/extensionManagementIpc.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { DefaultURITransformer, IURITransformer, transformAndReviveIncomingURIs
1212
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
1313
import { DidUninstallExtensionEvent, IExtensionIdentifier, IExtensionManagementService, IExtensionTipsService, IGalleryExtension, IGalleryMetadata, ILocalExtension, InstallExtensionEvent, InstallExtensionResult, InstallOptions, InstallVSIXOptions, IExtensionsControlManifest, isTargetPlatformCompatible, UninstallOptions, IServerExtensionManagementService, ServerInstallOptions, ServerInstallVSIXOptions, ServerUninstallOptions, Metadata } from 'vs/platform/extensionManagement/common/extensionManagement';
1414
import { ExtensionType, IExtensionManifest, TargetPlatform } from 'vs/platform/extensions/common/extensions';
15-
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
1615

1716
function transformIncomingURI(uri: UriComponents, transformer: IURITransformer | null): URI {
1817
return URI.revive(transformer ? transformer.transformIncoming(uri) : uri);
@@ -98,10 +97,7 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
9897
private readonly _onDidUninstallExtension = this._register(new Emitter<DidUninstallExtensionEvent>());
9998
readonly onDidUninstallExtension = this._onDidUninstallExtension.event;
10099

101-
constructor(
102-
private readonly channel: IChannel,
103-
private readonly userDataProfilesService: IUserDataProfilesService | undefined
104-
) {
100+
constructor(private readonly channel: IChannel) {
105101
super();
106102
this._register(this.channel.listen<InstallExtensionEvent>('onInstallExtension')(e => this._onInstallExtension.fire({ identifier: e.identifier, source: this.isUriComponents(e.source) ? URI.revive(e.source) : e.source })));
107103
this._register(this.channel.listen<readonly InstallExtensionResult[]>('onDidInstallExtensions')(results => this._onDidInstallExtensions.fire(results.map(e => ({ ...e, local: e.local ? transformIncomingExtension(e.local, null) : e.local, source: this.isUriComponents(e.source) ? URI.revive(e.source) : e.source })))));
@@ -139,7 +135,7 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
139135
}
140136

141137
install(vsix: URI, options?: InstallVSIXOptions): Promise<ILocalExtension> {
142-
const serverInstallOptions: ServerInstallVSIXOptions = { ...options, profileLocation: this.userDataProfilesService?.currentProfile.extensionsResource };
138+
const serverInstallOptions: ServerInstallVSIXOptions = { ...options, profileLocation: this.getExtensionsProfileResource() };
143139
return Promise.resolve(this.channel.call<ILocalExtension>('install', [vsix, serverInstallOptions])).then(local => transformIncomingExtension(local, null));
144140
}
145141

@@ -148,12 +144,12 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
148144
}
149145

150146
installFromGallery(extension: IGalleryExtension, installOptions?: InstallOptions): Promise<ILocalExtension> {
151-
const serverInstallOptions: ServerInstallOptions = { ...installOptions, profileLocation: this.userDataProfilesService?.currentProfile.extensionsResource };
147+
const serverInstallOptions: ServerInstallOptions = { ...installOptions, profileLocation: this.getExtensionsProfileResource() };
152148
return Promise.resolve(this.channel.call<ILocalExtension>('installFromGallery', [extension, serverInstallOptions])).then(local => transformIncomingExtension(local, null));
153149
}
154150

155151
uninstall(extension: ILocalExtension, options?: UninstallOptions): Promise<void> {
156-
const serverUninstallOptions: ServerUninstallOptions = { ...options, profileLocation: this.userDataProfilesService?.currentProfile.extensionsResource };
152+
const serverUninstallOptions: ServerUninstallOptions = { ...options, profileLocation: this.getExtensionsProfileResource() };
157153
return Promise.resolve(this.channel.call('uninstall', [extension!, serverUninstallOptions]));
158154
}
159155

@@ -162,7 +158,7 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
162158
}
163159

164160
getInstalled(type: ExtensionType | null = null): Promise<ILocalExtension[]> {
165-
return Promise.resolve(this.channel.call<ILocalExtension[]>('getInstalled', [type, this.userDataProfilesService?.currentProfile.extensionsResource]))
161+
return Promise.resolve(this.channel.call<ILocalExtension[]>('getInstalled', [type, this.getExtensionsProfileResource()]))
166162
.then(extensions => extensions.map(extension => transformIncomingExtension(extension, null)));
167163
}
168164

@@ -185,6 +181,10 @@ export class ExtensionManagementChannelClient extends Disposable implements IExt
185181
}
186182

187183
registerParticipant() { throw new Error('Not Supported'); }
184+
185+
protected getExtensionsProfileResource(): URI | undefined {
186+
return undefined;
187+
}
188188
}
189189

190190
export class ExtensionTipsChannel implements IServerChannel {

src/vs/platform/storage/browser/storageService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { assertIsDefined } from 'vs/base/common/types';
1313
import { InMemoryStorageDatabase, isStorageItemsChangeEvent, IStorage, IStorageDatabase, IStorageItemsChangeEvent, IUpdateRequest, Storage } from 'vs/base/parts/storage/common/storage';
1414
import { ILogService } from 'vs/platform/log/common/log';
1515
import { AbstractStorageService, IS_NEW_KEY, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
16-
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
16+
import { IUserDataProfile, IUserDataProfileService } from 'vs/platform/userDataProfile/common/userDataProfile';
1717
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
1818

1919
export class BrowserStorageService extends AbstractStorageService {
@@ -43,7 +43,7 @@ export class BrowserStorageService extends AbstractStorageService {
4343
constructor(
4444
private readonly payload: IAnyWorkspaceIdentifier,
4545
@ILogService private readonly logService: ILogService,
46-
@IUserDataProfilesService userDataProfileService: IUserDataProfilesService
46+
@IUserDataProfileService userDataProfileService: IUserDataProfileService
4747
) {
4848
super({ flushInterval: BrowserStorageService.BROWSER_DEFAULT_FLUSH_INTERVAL });
4949

src/vs/platform/storage/electron-sandbox/storageService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1111
import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services';
1212
import { AbstractStorageService, StorageScope, WillSaveStateReason } from 'vs/platform/storage/common/storage';
1313
import { ApplicationStorageDatabaseClient, GlobalStorageDatabaseClient, WorkspaceStorageDatabaseClient } from 'vs/platform/storage/common/storageIpc';
14-
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
14+
import { IUserDataProfile, IUserDataProfileService } from 'vs/platform/userDataProfile/common/userDataProfile';
1515
import { IAnyWorkspaceIdentifier, IEmptyWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
1616

1717
export class NativeStorageService extends AbstractStorageService {
@@ -30,15 +30,15 @@ export class NativeStorageService extends AbstractStorageService {
3030
constructor(
3131
workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IEmptyWorkspaceIdentifier | undefined,
3232
private readonly mainProcessService: IMainProcessService,
33-
userDataProfilesService: IUserDataProfilesService,
33+
userDataProfileService: IUserDataProfileService,
3434
private readonly environmentService: IEnvironmentService
3535
) {
3636
super();
3737

38-
this.applicationStorageProfile = userDataProfilesService.defaultProfile;
38+
this.applicationStorageProfile = userDataProfileService.defaultProfile;
3939

4040
this.applicationStorage = this.createApplicationStorage();
41-
this.globalStorage = this.createGlobalStorage(userDataProfilesService.currentProfile);
41+
this.globalStorage = this.createGlobalStorage(userDataProfileService.currentProfile);
4242
this.workspaceStorage = this.createWorkspaceStorage(workspace);
4343
}
4444

src/vs/platform/storage/test/browser/storageService.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ import { Schemas } from 'vs/base/common/network';
99
import { joinPath } from 'vs/base/common/resources';
1010
import { URI } from 'vs/base/common/uri';
1111
import { Storage } from 'vs/base/parts/storage/common/storage';
12-
import { mock } from 'vs/base/test/common/mock';
1312
import { flakySuite } from 'vs/base/test/common/testUtils';
1413
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
15-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1614
import { FileService } from 'vs/platform/files/common/fileService';
1715
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
1816
import { NullLogService } from 'vs/platform/log/common/log';
1917
import { BrowserStorageService, IndexedDBStorageDatabase } from 'vs/platform/storage/browser/storageService';
2018
import { StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2119
import { createSuite } from 'vs/platform/storage/test/common/storageService.test';
22-
import { IUserDataProfile, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
20+
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
21+
import { UserDataProfileService } from 'vs/platform/userDataProfile/common/userDataProfileService';
2322

2423
async function createStorageService(): Promise<[DisposableStore, BrowserStorageService]> {
2524
const disposables = new DisposableStore();
@@ -32,10 +31,6 @@ async function createStorageService(): Promise<[DisposableStore, BrowserStorageS
3231

3332
const profilesRoot = URI.file('/profiles').with({ scheme: Schemas.inMemory });
3433

35-
class EnvironmentServiceMock extends mock<IEnvironmentService>() {
36-
override readonly userRoamingDataHome = profilesRoot;
37-
}
38-
3934
const inMemoryDefaultProfileRoot = joinPath(profilesRoot, 'default');
4035
const inMemoryDefaultProfile: IUserDataProfile = {
4136
id: 'id',
@@ -64,7 +59,7 @@ async function createStorageService(): Promise<[DisposableStore, BrowserStorageS
6459
extensionsResource: joinPath(inMemoryExtraProfileRoot, 'extensionsResource')
6560
};
6661

67-
const userDataProfileService = new UserDataProfilesService(inMemoryDefaultProfile, inMemoryExtraProfile, new EnvironmentServiceMock(), fileService, new NullLogService());
62+
const userDataProfileService = new UserDataProfileService(inMemoryDefaultProfile, inMemoryExtraProfile);
6863

6964
const storageService = disposables.add(new BrowserStorageService({ id: 'workspace-storage-test' }, logService, userDataProfileService));
7065

src/vs/platform/storage/test/electron-main/storageMainService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ suite('StorageMainService', function () {
145145
function createStorageService(lifecycleMainService: ILifecycleMainService = new StorageTestLifecycleMainService()): TestStorageMainService {
146146
const environmentService = new NativeEnvironmentService(parseArgs(process.argv, OPTIONS), productService);
147147
const fileService = new FileService(new NullLogService());
148-
return new TestStorageMainService(new NullLogService(), environmentService, new UserDataProfilesService(undefined, undefined, environmentService, fileService, new NullLogService()), lifecycleMainService, fileService);
148+
return new TestStorageMainService(new NullLogService(), environmentService, new UserDataProfilesService(undefined, environmentService, fileService, new NullLogService()), lifecycleMainService, fileService);
149149
}
150150

151151
test('basics (application)', function () {

0 commit comments

Comments
 (0)