Skip to content

Commit d206715

Browse files
author
Benjamin Pasero
committed
sqlite - more next storage adoption
1 parent 084fb5c commit d206715

13 files changed

Lines changed: 99 additions & 91 deletions

File tree

src/vs/platform/lifecycle/electron-browser/lifecycleService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { TPromise } from 'vs/base/common/winjs.base';
77
import { toErrorMessage } from 'vs/base/common/errorMessage';
88
import { ILifecycleService, WillShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, handleVetos, LifecyclePhaseToString, ShutdownEvent } from 'vs/platform/lifecycle/common/lifecycle';
9-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
9+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1010
import { ipcRenderer as ipc } from 'electron';
1111
import { Event, Emitter } from 'vs/base/common/event';
1212
import { IWindowService } from 'vs/platform/windows/common/windows';
@@ -40,7 +40,7 @@ export class LifecycleService extends Disposable implements ILifecycleService {
4040
constructor(
4141
@INotificationService private notificationService: INotificationService,
4242
@IWindowService private windowService: IWindowService,
43-
@IStorageService private storageService: IStorageService,
43+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
4444
@ILogService private logService: ILogService
4545
) {
4646
super();
@@ -51,8 +51,8 @@ export class LifecycleService extends Disposable implements ILifecycleService {
5151
}
5252

5353
private resolveStartupKind(): StartupKind {
54-
const lastShutdownReason = this.storageService.getInteger(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
55-
this.storageService.remove(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
54+
const lastShutdownReason = this.nextStorage2Service.getInteger(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
55+
this.nextStorage2Service.delete(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
5656

5757
let startupKind: StartupKind;
5858
if (lastShutdownReason === ShutdownReason.RELOAD) {
@@ -76,13 +76,13 @@ export class LifecycleService extends Disposable implements ILifecycleService {
7676
this.logService.trace(`lifecycle: onBeforeUnload (reason: ${reply.reason})`);
7777

7878
// store shutdown reason to retrieve next startup
79-
this.storageService.store(LifecycleService.LAST_SHUTDOWN_REASON_KEY, JSON.stringify(reply.reason), StorageScope.WORKSPACE);
79+
this.nextStorage2Service.set(LifecycleService.LAST_SHUTDOWN_REASON_KEY, JSON.stringify(reply.reason), StorageScope.WORKSPACE);
8080

8181
// trigger onWillShutdown events and veto collecting
8282
this.handleWillShutdown(reply.reason).then(veto => {
8383
if (veto) {
8484
this.logService.trace('lifecycle: onBeforeUnload prevented via veto');
85-
this.storageService.remove(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
85+
this.nextStorage2Service.delete(LifecycleService.LAST_SHUTDOWN_REASON_KEY, StorageScope.WORKSPACE);
8686
ipc.send(reply.cancelChannel, windowId);
8787
} else {
8888
this.logService.trace('lifecycle: onBeforeUnload continues without veto');

src/vs/platform/storage2/electron-browser/nextStorage2Service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
104104
private _onWillClose: Emitter<ShutdownReason> = this._register(new Emitter<ShutdownReason>());
105105
get onWillClose(): Event<ShutdownReason> { return this._onWillClose.event; }
106106

107+
private closed: boolean;
108+
107109
constructor(
108110
@INextStorage2Service private nextStorage2Service: NextStorage2Service,
109111
@IStorageService private storageService: IStorageService,
@@ -163,18 +165,32 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
163165
}
164166

165167
set(key: string, value: any, scope: StorageScope): Promise<void> {
168+
if (this.closed) {
169+
this.logService.warn(`Unsupported write (set) access after close (key: ${key})`);
170+
171+
return Promise.resolve(); // prevent writing after close to detect late write access
172+
}
173+
166174
this.storageService.store(key, value, this.convertScope(scope));
167175

168176
return this.nextStorage2Service.set(key, value, scope);
169177
}
170178

171179
delete(key: string, scope: StorageScope): Promise<void> {
180+
if (this.closed) {
181+
this.logService.warn(`Unsupported write (delete) access after close (key: ${key})`);
182+
183+
return Promise.resolve(); // prevent writing after close to detect late write access
184+
}
185+
172186
this.storageService.remove(key, this.convertScope(scope));
173187

174188
return this.nextStorage2Service.delete(key, scope);
175189
}
176190

177191
close(reason: ShutdownReason): Promise<void> {
192+
this.closed = true;
193+
178194
return this.nextStorage2Service.close(reason);
179195
}
180196

src/vs/workbench/api/electron-browser/mainThreadStorage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { TPromise } from 'vs/base/common/winjs.base';
7-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
7+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
88
import { MainThreadStorageShape, MainContext, IExtHostContext } from '../node/extHost.protocol';
99
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
1010

1111
@extHostNamedCustomer(MainContext.MainThreadStorage)
1212
export class MainThreadStorage implements MainThreadStorageShape {
1313

14-
private _storageService: IStorageService;
14+
private _nextStorage2Service: INextStorage2Service;
1515

1616
constructor(
1717
extHostContext: IExtHostContext,
18-
@IStorageService storageService: IStorageService
18+
@INextStorage2Service nextStorage2Service: INextStorage2Service
1919
) {
20-
this._storageService = storageService;
20+
this._nextStorage2Service = nextStorage2Service;
2121
}
2222

2323
dispose(): void {
2424
}
2525

2626
$getValue<T>(shared: boolean, key: string): Thenable<T> {
27-
let jsonValue = this._storageService.get(key, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
27+
let jsonValue = this._nextStorage2Service.get(key, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
2828
if (!jsonValue) {
2929
return TPromise.as(undefined);
3030
}
@@ -41,7 +41,7 @@ export class MainThreadStorage implements MainThreadStorageShape {
4141
let jsonValue: any;
4242
try {
4343
jsonValue = JSON.stringify(value);
44-
this._storageService.store(key, jsonValue, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
44+
this._nextStorage2Service.set(key, jsonValue, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
4545
} catch (err) {
4646
return TPromise.wrapError(err);
4747
}

src/vs/workbench/browser/layout.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickIn
88
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
99
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
1010
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
11-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
11+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1212
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
1313
import { Disposable } from 'vs/base/common/lifecycle';
1414
import { IThemeService } from 'vs/platform/theme/common/themeService';
@@ -82,7 +82,7 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
8282
private quickInput: QuickInputService,
8383
private notificationsCenter: NotificationsCenter,
8484
private notificationsToasts: NotificationsToasts,
85-
@IStorageService private storageService: IStorageService,
85+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
8686
@IContextViewService private contextViewService: IContextViewService,
8787
@IPartService private partService: IPartService,
8888
@IViewletService private viewletService: IViewletService,
@@ -103,13 +103,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
103103
}
104104

105105
private restorePreviousState(): void {
106-
this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_SIDEBAR_PART_WIDTH));
106+
this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.nextStorage2Service.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_SIDEBAR_PART_WIDTH));
107107

108-
this._panelWidth = Math.max(this.partLayoutInfo.panel.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
109-
this._panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
108+
this._panelWidth = Math.max(this.partLayoutInfo.panel.minWidth, this.nextStorage2Service.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
109+
this._panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, this.nextStorage2Service.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
110110

111111
this.panelMaximized = false;
112-
this.panelSizeBeforeMaximized = this.storageService.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
112+
this.panelSizeBeforeMaximized = this.nextStorage2Service.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
113113
}
114114

115115
private registerListeners(): void {
@@ -372,34 +372,37 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
372372
}));
373373

374374
this._register(this.sashXOne.onDidEnd(() => {
375-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
375+
this.nextStorage2Service.set(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
376376
}));
377377

378378
this._register(this.sashY.onDidEnd(() => {
379-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
379+
this.nextStorage2Service.set(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
380380
}));
381381

382382
this._register(this.sashXTwo.onDidEnd(() => {
383-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
383+
this.nextStorage2Service.set(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
384384
}));
385385

386386
this._register(this.sashY.onDidReset(() => {
387387
this.panelHeight = this.sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT;
388-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
388+
this.nextStorage2Service.set(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
389+
389390
this.layout();
390391
}));
391392

392393
this._register(this.sashXOne.onDidReset(() => {
393394
let activeViewlet = this.viewletService.getActiveViewlet();
394395
let optimalWidth = activeViewlet && activeViewlet.getOptimalWidth();
395396
this.sidebarWidth = Math.max(optimalWidth, DEFAULT_SIDEBAR_PART_WIDTH);
396-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
397+
this.nextStorage2Service.set(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
398+
397399
this.partService.setSideBarHidden(false).then(() => this.layout());
398400
}));
399401

400402
this._register(this.sashXTwo.onDidReset(() => {
401403
this.panelWidth = (this.workbenchSize.width - this.sidebarWidth - this.activitybarWidth) * DEFAULT_PANEL_SIZE_COEFFICIENT;
402-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
404+
this.nextStorage2Service.set(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
405+
403406
this.layout();
404407
}));
405408
}
@@ -472,7 +475,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
472475
this.panelSizeBeforeMaximized = panelWidth;
473476
}
474477
}
475-
this.storageService.store(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
478+
479+
this.nextStorage2Service.set(WorkbenchLayout.panelSizeBeforeMaximizedKey, this.panelSizeBeforeMaximized, StorageScope.GLOBAL);
480+
476481
const panelDimension = new Dimension(panelWidth, panelHeight);
477482

478483
// Editor
@@ -527,16 +532,16 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
527532

528533
if (!isSidebarHidden) {
529534
this.sidebarWidth = sidebarSize.width;
530-
this.storageService.store(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
535+
this.nextStorage2Service.set(WorkbenchLayout.sashXOneWidthSettingsKey, this.sidebarWidth, StorageScope.GLOBAL);
531536
}
532537

533538
if (!isPanelHidden) {
534539
if (panelPosition === Position.BOTTOM) {
535540
this.panelHeight = panelDimension.height;
536-
this.storageService.store(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
541+
this.nextStorage2Service.set(WorkbenchLayout.sashYHeightSettingsKey, this.panelHeight, StorageScope.GLOBAL);
537542
} else {
538543
this.panelWidth = panelDimension.width;
539-
this.storageService.store(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
544+
this.nextStorage2Service.set(WorkbenchLayout.sashXTwoWidthSettingsKey, this.panelWidth, StorageScope.GLOBAL);
540545
}
541546
}
542547

src/vs/workbench/browser/parts/activitybar/activitybarPart.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { isMacintosh } from 'vs/base/common/platform';
2525
import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
2626
import { scheduleAtNextAnimationFrame, Dimension, addClass } from 'vs/base/browser/dom';
2727
import { Color } from 'vs/base/common/color';
28-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
28+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
2929
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
3030
import { URI } from 'vs/base/common/uri';
3131
import { ToggleCompositePinnedAction, ICompositeBarColors } from 'vs/workbench/browser/parts/compositeBarActions';
@@ -58,7 +58,7 @@ export class ActivitybarPart extends Part {
5858
@IPartService private partService: IPartService,
5959
@IThemeService themeService: IThemeService,
6060
@ILifecycleService private lifecycleService: ILifecycleService,
61-
@IStorageService private storageService: IStorageService,
61+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
6262
@IExtensionService private extensionService: IExtensionService
6363
) {
6464
super(id, { hasTitle: false }, themeService);
@@ -79,7 +79,7 @@ export class ActivitybarPart extends Part {
7979
overflowActionSize: ActivitybarPart.ACTION_HEIGHT
8080
}));
8181

82-
const previousState = this.storageService.get(ActivitybarPart.PLACEHOLDER_VIEWLETS, StorageScope.GLOBAL, '[]');
82+
const previousState = this.nextStorage2Service.get(ActivitybarPart.PLACEHOLDER_VIEWLETS, StorageScope.GLOBAL, '[]');
8383
this.placeholderComposites = <IPlaceholderComposite[]>JSON.parse(previousState);
8484
this.placeholderComposites.forEach((s) => {
8585
if (typeof s.iconUrl === 'object') {
@@ -110,6 +110,11 @@ export class ActivitybarPart extends Part {
110110
}));
111111

112112
this._register(this.extensionService.onDidRegisterExtensions(() => this.onDidRegisterExtensions()));
113+
114+
this._register(this.nextStorage2Service.onWillClose(() => {
115+
const state = this.viewletService.getAllViewlets().map(({ id, iconUrl }) => ({ id, iconUrl }));
116+
this.nextStorage2Service.set(ActivitybarPart.PLACEHOLDER_VIEWLETS, JSON.stringify(state), StorageScope.GLOBAL);
117+
}));
113118
}
114119

115120
private onDidRegisterExtensions(): void {
@@ -331,11 +336,4 @@ export class ActivitybarPart extends Part {
331336

332337
return sizes;
333338
}
334-
335-
shutdown(): void {
336-
const state = this.viewletService.getAllViewlets().map(({ id, iconUrl }) => ({ id, iconUrl }));
337-
this.storageService.store(ActivitybarPart.PLACEHOLDER_VIEWLETS, JSON.stringify(state), StorageScope.GLOBAL);
338-
339-
super.shutdown();
340-
}
341339
}

src/vs/workbench/browser/parts/compositeBar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { illegalArgument } from 'vs/base/common/errors';
99
import * as arrays from 'vs/base/common/arrays';
1010
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
1111
import { IBadge } from 'vs/workbench/services/activity/common/activity';
12-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
12+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1313
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1414
import { ActionBar, ActionsOrientation, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
1515
import { CompositeActionItem, CompositeOverflowActivityAction, ICompositeActivity, CompositeOverflowActivityActionItem, ActivityAction, ICompositeBar, ICompositeBarColors, DraggedCompositeIdentifier } from 'vs/workbench/browser/parts/compositeBarActions';
@@ -55,12 +55,12 @@ export class CompositeBar extends Widget implements ICompositeBar {
5555
constructor(
5656
private options: ICompositeBarOptions,
5757
@IInstantiationService private instantiationService: IInstantiationService,
58-
@IStorageService storageService: IStorageService,
58+
@INextStorage2Service nextStorage2Service: INextStorage2Service,
5959
@IContextMenuService private contextMenuService: IContextMenuService
6060
) {
6161
super();
6262

63-
this.model = new CompositeBarModel(options, storageService);
63+
this.model = new CompositeBarModel(options, nextStorage2Service);
6464
this.visibleComposites = [];
6565
this.compositeSizeInBar = new Map<string, number>();
6666
this.compositeTransfer = LocalSelectionTransfer.getInstance<DraggedCompositeIdentifier>();
@@ -452,7 +452,7 @@ class CompositeBarModel {
452452

453453
constructor(
454454
options: ICompositeBarOptions,
455-
private storageService: IStorageService,
455+
private nextStorage2Service: INextStorage2Service,
456456
) {
457457
this.options = options;
458458
this.items = this.loadItemStates();
@@ -650,7 +650,7 @@ class CompositeBarModel {
650650
}
651651

652652
private loadItemStates(): ICompositeBarItem[] {
653-
const storedStates = <Array<string | ISerializedCompositeBarItem>>JSON.parse(this.storageService.get(this.options.storageId, StorageScope.GLOBAL, '[]'));
653+
const storedStates = <Array<string | ISerializedCompositeBarItem>>JSON.parse(this.nextStorage2Service.get(this.options.storageId, StorageScope.GLOBAL, '[]'));
654654
return <ICompositeBarItem[]>storedStates.map(c => {
655655
const serialized: ISerializedCompositeBarItem = typeof c === 'string' /* migration from pinned states to composites states */ ? { id: c, pinned: true, order: void 0, visible: true } : c;
656656
return this.createCompositeBarItem(serialized.id, void 0, serialized.order, serialized.pinned, isUndefinedOrNull(serialized.visible) ? true : serialized.visible);
@@ -659,6 +659,6 @@ class CompositeBarModel {
659659

660660
saveState(): void {
661661
const serialized = this.items.map(({ id, pinned, order, visible }) => ({ id, pinned, order, visible }));
662-
this.storageService.store(this.options.storageId, JSON.stringify(serialized), StorageScope.GLOBAL);
662+
this.nextStorage2Service.set(this.options.storageId, JSON.stringify(serialized), StorageScope.GLOBAL);
663663
}
664664
}

0 commit comments

Comments
 (0)