未验证 提交 e9167751 编写于 作者: S Sandeep Somavarapu 提交者: GitHub

Introduce storage main service in shared process (#89040)

Introduce storage main service in shared process
......@@ -62,6 +62,9 @@ import { KeytarCredentialsService } from 'vs/platform/credentials/node/credentia
import { UserDataAutoSync } from 'vs/platform/userDataSync/electron-browser/userDataAutoSync';
import { SettingsSynchroniser } from 'vs/platform/userDataSync/common/settingsSync';
import { UserDataAuthTokenService } from 'vs/platform/userDataSync/common/userDataAuthTokenService';
import { GlobalStorageDatabaseChannelClient } from 'vs/platform/storage/node/storageIpc';
import { NativeStorageService } from 'vs/platform/storage/node/storageService';
import { IStorageService } from 'vs/platform/storage/common/storage';
export interface ISharedProcessConfiguration {
readonly machineId: string;
......@@ -113,10 +116,18 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
disposables.add(logService);
logService.info('main', JSON.stringify(configuration));
const mainProcessService = new MainProcessService(server, mainRouter);
services.set(IMainProcessService, mainProcessService);
const configurationService = new ConfigurationService(environmentService.settingsResource);
disposables.add(configurationService);
await configurationService.initialize();
const storageService = new NativeStorageService(new GlobalStorageDatabaseChannelClient(mainProcessService.getChannel('storage')), logService, environmentService);
await storageService.initialize();
services.set(IStorageService, storageService);
disposables.add(toDisposable(() => storageService.flush()));
services.set(IEnvironmentService, environmentService);
services.set(IProductService, { _serviceBrand: undefined, ...product });
services.set(ILogService, logService);
......@@ -124,8 +135,6 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(ILoggerService, new SyncDescriptor(LoggerService));
const mainProcessService = new MainProcessService(server, mainRouter);
services.set(IMainProcessService, mainProcessService);
const electronService = createChannelSender<IElectronService>(mainProcessService.getChannel('electron'), { context: configuration.windowId });
services.set(IElectronService, electronService);
......
......@@ -58,7 +58,7 @@ export class NativeStorageService extends Disposable implements IStorageService
this._onDidChangeStorage.fire({ key, scope });
}
initialize(payload: IWorkspaceInitializationPayload): Promise<void> {
initialize(payload?: IWorkspaceInitializationPayload): Promise<void> {
if (!this.initializePromise) {
this.initializePromise = this.doInitialize(payload);
}
......@@ -66,12 +66,12 @@ export class NativeStorageService extends Disposable implements IStorageService
return this.initializePromise;
}
private async doInitialize(payload: IWorkspaceInitializationPayload): Promise<void> {
private async doInitialize(payload?: IWorkspaceInitializationPayload): Promise<void> {
// Init all storage locations
await Promise.all([
this.initializeGlobalStorage(),
this.initializeWorkspaceStorage(payload)
payload ? this.initializeWorkspaceStorage(payload) : Promise.resolve()
]);
// On some OS we do not get enough time to persist state on shutdown (e.g. when
......@@ -196,6 +196,10 @@ export class NativeStorageService extends Disposable implements IStorageService
this.getStorage(scope).delete(key);
}
private getStorage(scope: StorageScope): IStorage {
return assertIsDefined(scope === StorageScope.GLOBAL ? this.globalStorage : this.workspaceStorage);
}
private doFlushWhenIdle(): void {
// Dispose any previous idle runner
......@@ -227,15 +231,11 @@ export class NativeStorageService extends Disposable implements IStorageService
// Do it
await Promise.all([
this.getStorage(StorageScope.GLOBAL).close(),
this.getStorage(StorageScope.WORKSPACE).close()
this.globalStorage.close(),
this.workspaceStorage ? this.workspaceStorage.close() : Promise.resolve()
]);
}
private getStorage(scope: StorageScope): IStorage {
return assertIsDefined(scope === StorageScope.GLOBAL ? this.globalStorage : this.workspaceStorage);
}
async logStorage(): Promise<void> {
const [workspaceStorage, workspaceStoragePath] = assertAllDefined(this.workspaceStorage, this.workspaceStoragePath);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册