@@ -9,7 +9,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
99import { ILogService , LogLevel } from 'vs/platform/log/common/log' ;
1010import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
1111import { SQLiteStorageDatabase , ISQLiteStorageDatabaseLoggingOptions } from 'vs/base/parts/storage/node/storage' ;
12- import { Storage , IStorage , InMemoryStorageDatabase } from 'vs/base/parts/storage/common/storage' ;
12+ import { Storage , IStorage , InMemoryStorageDatabase , IStorageDatabase } from 'vs/base/parts/storage/common/storage' ;
1313import { join } from 'vs/base/common/path' ;
1414
1515export const IStorageMainService = createDecorator < IStorageMainService > ( 'storageMainService' ) ;
@@ -83,12 +83,10 @@ export interface IStorageChangeEvent {
8383 key : string ;
8484}
8585
86- export class StorageMainService extends Disposable implements IStorageMainService {
86+ export abstract class AbstractStorageMainService extends Disposable implements IStorageMainService {
8787
8888 _serviceBrand : undefined ;
8989
90- private static readonly STORAGE_NAME = 'state.vscdb' ;
91-
9290 private readonly _onDidChangeStorage = this . _register ( new Emitter < IStorageChangeEvent > ( ) ) ;
9391 readonly onDidChangeStorage = this . _onDidChangeStorage . event ;
9492
@@ -98,34 +96,15 @@ export class StorageMainService extends Disposable implements IStorageMainServic
9896 get items ( ) : Map < string , string > { return this . storage . items ; }
9997
10098 private storage : IStorage ;
101-
10299 private initializePromise : Promise < void > | undefined ;
103100
104- constructor (
105- @ILogService private readonly logService : ILogService ,
106- @IEnvironmentService private readonly environmentService : IEnvironmentService
107- ) {
101+ constructor ( ) {
108102 super ( ) ;
109103
110104 // Until the storage has been initialized, it can only be in memory
111105 this . storage = new Storage ( new InMemoryStorageDatabase ( ) ) ;
112106 }
113107
114- private get storagePath ( ) : string {
115- if ( ! ! this . environmentService . extensionTestsLocationURI ) {
116- return SQLiteStorageDatabase . IN_MEMORY_PATH ; // no storage during extension tests!
117- }
118-
119- return join ( this . environmentService . globalStorageHome , StorageMainService . STORAGE_NAME ) ;
120- }
121-
122- private createLogginOptions ( ) : ISQLiteStorageDatabaseLoggingOptions {
123- return {
124- logTrace : ( this . logService . getLevel ( ) === LogLevel . Trace ) ? msg => this . logService . trace ( msg ) : undefined ,
125- logError : error => this . logService . error ( error )
126- } ;
127- }
128-
129108 initialize ( ) : Promise < void > {
130109 if ( ! this . initializePromise ) {
131110 this . initializePromise = this . doInitialize ( ) ;
@@ -134,12 +113,9 @@ export class StorageMainService extends Disposable implements IStorageMainServic
134113 return this . initializePromise ;
135114 }
136115
137- private doInitialize ( ) : Promise < void > {
116+ private async doInitialize ( ) : Promise < void > {
138117 this . storage . dispose ( ) ;
139- this . storage = new Storage ( new SQLiteStorageDatabase ( this . storagePath , {
140- logging : this . createLogginOptions ( )
141- } ) ) ;
142-
118+ this . storage = this . createStorage ( ) ;
143119 this . _register ( this . storage . onDidChangeStorage ( key => this . _onDidChangeStorage . fire ( { key } ) ) ) ;
144120
145121 return this . storage . init ( ) ;
@@ -179,4 +155,53 @@ export class StorageMainService extends Disposable implements IStorageMainServic
179155 // Do it
180156 return this . storage . close ( ) ;
181157 }
158+
159+ protected abstract createStorage ( ) : IStorage ;
160+ }
161+
162+ export class StorageMainService extends AbstractStorageMainService implements IStorageMainService {
163+
164+ private static readonly STORAGE_NAME = 'state.vscdb' ;
165+
166+ constructor (
167+ @ILogService private readonly logService : ILogService ,
168+ @IEnvironmentService private readonly environmentService : IEnvironmentService
169+ ) {
170+ super ( ) ;
171+ }
172+
173+ private get storagePath ( ) : string {
174+ if ( ! ! this . environmentService . extensionTestsLocationURI ) {
175+ return SQLiteStorageDatabase . IN_MEMORY_PATH ; // no storage during extension tests!
176+ }
177+
178+ return join ( this . environmentService . globalStorageHome , StorageMainService . STORAGE_NAME ) ;
179+ }
180+
181+ protected createStorage ( ) : IStorage {
182+ return new Storage ( new SQLiteStorageDatabase ( this . storagePath , {
183+ logging : this . createLogginOptions ( )
184+ } ) ) ;
185+ }
186+
187+ private createLogginOptions ( ) : ISQLiteStorageDatabaseLoggingOptions {
188+ return {
189+ logTrace : ( this . logService . getLevel ( ) === LogLevel . Trace ) ? msg => this . logService . trace ( msg ) : undefined ,
190+ logError : error => this . logService . error ( error )
191+ } ;
192+ }
193+ }
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+
182207}
0 commit comments