Skip to content

Commit 6f388fe

Browse files
committed
Use native storage service
1 parent a669508 commit 6f388fe

3 files changed

Lines changed: 20 additions & 31 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ import { UserDataAutoSync } from 'vs/platform/userDataSync/electron-browser/user
6363
import { SettingsSynchroniser } from 'vs/platform/userDataSync/common/settingsSync';
6464
import { UserDataAuthTokenService } from 'vs/platform/userDataSync/common/userDataAuthTokenService';
6565
import { GlobalStorageDatabaseChannelClient } from 'vs/platform/storage/node/storageIpc';
66-
import { IStorageMainService, SimpleStorageMainService } from 'vs/platform/storage/node/storageMainService';
66+
import { NativeStorageService } from 'vs/platform/storage/node/storageService';
67+
import { IStorageService } from 'vs/platform/storage/common/storage';
6768

6869
export interface ISharedProcessConfiguration {
6970
readonly machineId: string;
@@ -115,23 +116,25 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
115116
disposables.add(logService);
116117
logService.info('main', JSON.stringify(configuration));
117118

119+
const mainProcessService = new MainProcessService(server, mainRouter);
120+
services.set(IMainProcessService, mainProcessService);
121+
118122
const configurationService = new ConfigurationService(environmentService.settingsResource);
119123
disposables.add(configurationService);
120124
await configurationService.initialize();
121125

126+
const storageService = new NativeStorageService(new GlobalStorageDatabaseChannelClient(mainProcessService.getChannel('storage')), logService, environmentService);
127+
await storageService.initialize();
128+
services.set(IStorageService, storageService);
129+
disposables.add(toDisposable(() => storageService.flush()));
130+
122131
services.set(IEnvironmentService, environmentService);
123132
services.set(IProductService, { _serviceBrand: undefined, ...product });
124133
services.set(ILogService, logService);
125134
services.set(IConfigurationService, configurationService);
126135
services.set(IRequestService, new SyncDescriptor(RequestService));
127136
services.set(ILoggerService, new SyncDescriptor(LoggerService));
128137

129-
const mainProcessService = new MainProcessService(server, mainRouter);
130-
services.set(IMainProcessService, mainProcessService);
131-
132-
const storageMainService = new SimpleStorageMainService(new GlobalStorageDatabaseChannelClient(mainProcessService.getChannel('storage')));
133-
await storageMainService.initialize();
134-
services.set(IStorageMainService, storageMainService);
135138

136139
const electronService = createChannelSender<IElectronService>(mainProcessService.getChannel('electron'), { context: configuration.windowId });
137140
services.set(IElectronService, electronService);

src/vs/platform/storage/node/storageMainService.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
99
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
1010
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1111
import { SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage';
12-
import { Storage, IStorage, InMemoryStorageDatabase, IStorageDatabase } from 'vs/base/parts/storage/common/storage';
12+
import { Storage, IStorage, InMemoryStorageDatabase } from 'vs/base/parts/storage/common/storage';
1313
import { join } from 'vs/base/common/path';
1414

1515
export const IStorageMainService = createDecorator<IStorageMainService>('storageMainService');
@@ -191,17 +191,3 @@ export class StorageMainService extends AbstractStorageMainService implements IS
191191
};
192192
}
193193
}
194-
195-
export class SimpleStorageMainService extends AbstractStorageMainService implements IStorageMainService {
196-
197-
constructor(
198-
private database: IStorageDatabase
199-
) {
200-
super();
201-
}
202-
203-
protected createStorage(): IStorage {
204-
return new Storage(this.database);
205-
}
206-
207-
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ export class NativeStorageService extends Disposable implements IStorageService
5858
this._onDidChangeStorage.fire({ key, scope });
5959
}
6060

61-
initialize(payload: IWorkspaceInitializationPayload): Promise<void> {
61+
initialize(payload?: IWorkspaceInitializationPayload): Promise<void> {
6262
if (!this.initializePromise) {
6363
this.initializePromise = this.doInitialize(payload);
6464
}
6565

6666
return this.initializePromise;
6767
}
6868

69-
private async doInitialize(payload: IWorkspaceInitializationPayload): Promise<void> {
69+
private async doInitialize(payload?: IWorkspaceInitializationPayload): Promise<void> {
7070

7171
// Init all storage locations
7272
await Promise.all([
7373
this.initializeGlobalStorage(),
74-
this.initializeWorkspaceStorage(payload)
74+
payload ? this.initializeWorkspaceStorage(payload) : Promise.resolve()
7575
]);
7676

7777
// 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
196196
this.getStorage(scope).delete(key);
197197
}
198198

199+
private getStorage(scope: StorageScope): IStorage {
200+
return assertIsDefined(scope === StorageScope.GLOBAL ? this.globalStorage : this.workspaceStorage);
201+
}
202+
199203
private doFlushWhenIdle(): void {
200204

201205
// Dispose any previous idle runner
@@ -227,15 +231,11 @@ export class NativeStorageService extends Disposable implements IStorageService
227231

228232
// Do it
229233
await Promise.all([
230-
this.getStorage(StorageScope.GLOBAL).close(),
231-
this.getStorage(StorageScope.WORKSPACE).close()
234+
this.globalStorage.close(),
235+
this.workspaceStorage ? this.workspaceStorage.close() : Promise.resolve()
232236
]);
233237
}
234238

235-
private getStorage(scope: StorageScope): IStorage {
236-
return assertIsDefined(scope === StorageScope.GLOBAL ? this.globalStorage : this.workspaceStorage);
237-
}
238-
239239
async logStorage(): Promise<void> {
240240
const [workspaceStorage, workspaceStoragePath] = assertAllDefined(this.workspaceStorage, this.workspaceStoragePath);
241241

0 commit comments

Comments
 (0)