Layer-breaker in telemetryUtils (fixes #27141)

This commit is contained in:
Benjamin Pasero
2017-05-31 07:42:54 +02:00
committed by Christof Marti
parent 706d52c1aa
commit 13112461e0
3 changed files with 39 additions and 36 deletions
@@ -50,15 +50,15 @@ export function loadExperiments(accessor: ServicesAccessor): ITelemetryExperimen
const storageService = accessor.get(IStorageService);
const configurationService = accessor.get(IConfigurationService);
updateExperimentsOverrides(configurationService);
configurationService.onDidUpdateConfiguration(e => updateExperimentsOverrides(configurationService));
updateExperimentsOverrides(configurationService, storageService);
configurationService.onDidUpdateConfiguration(e => updateExperimentsOverrides(configurationService, storageService));
let {
showNewUserWatermark,
openUntitledFile,
enableWelcomePage,
mergeQuickLinks,
} = splitExperimentsRandomness();
} = splitExperimentsRandomness(storageService);
const newUserDuration = 24 * 60 * 60 * 1000;
const firstSessionDate = storageService.get('telemetry.firstSessionDate');
@@ -73,16 +73,16 @@ export function loadExperiments(accessor: ServicesAccessor): ITelemetryExperimen
openUntitledFile,
enableWelcomePage,
mergeQuickLinks,
});
}, storageService);
}
export function isWelcomePageEnabled() {
const overrides = getExperimentsOverrides();
return 'enableWelcomePage' in overrides ? overrides.enableWelcomePage : splitExperimentsRandomness().enableWelcomePage;
export function isWelcomePageEnabled(storageService: IStorageService) {
const overrides = getExperimentsOverrides(storageService);
return 'enableWelcomePage' in overrides ? overrides.enableWelcomePage : splitExperimentsRandomness(storageService).enableWelcomePage;
}
function applyOverrides(experiments: ITelemetryExperiments): ITelemetryExperiments {
const experimentsConfig = getExperimentsOverrides();
function applyOverrides(experiments: ITelemetryExperiments, storageService: IStorageService): ITelemetryExperiments {
const experimentsConfig = getExperimentsOverrides(storageService);
Object.keys(experiments).forEach(key => {
if (key in experimentsConfig) {
experiments[key] = experimentsConfig[key];
@@ -91,8 +91,8 @@ function applyOverrides(experiments: ITelemetryExperiments): ITelemetryExperimen
return experiments;
}
function splitExperimentsRandomness(): ITelemetryExperiments {
const random1 = getExperimentsRandomness();
function splitExperimentsRandomness(storageService: IStorageService): ITelemetryExperiments {
const random1 = getExperimentsRandomness(storageService);
const [random2, showNewUserWatermark] = splitRandom(random1);
const [random3, openUntitledFile] = splitRandom(random2);
const [random4, mergeQuickLinks] = splitRandom(random3);
@@ -105,12 +105,12 @@ function splitExperimentsRandomness(): ITelemetryExperiments {
};
}
function getExperimentsRandomness() {
function getExperimentsRandomness(storageService: IStorageService) {
const key = StorageService.GLOBAL_PREFIX + 'experiments.randomness';
let valueString = window.localStorage.getItem(key);
let valueString = storageService.get(key);
if (!valueString) {
valueString = Math.random().toString();
window.localStorage.setItem(key, valueString);
storageService.store(key, valueString);
}
return parseFloat(valueString);
@@ -124,17 +124,17 @@ function splitRandom(random: number): [number, boolean] {
const experimentsOverridesKey = StorageService.GLOBAL_PREFIX + 'experiments.overrides';
function getExperimentsOverrides(): ITelemetryExperiments {
const valueString = window.localStorage.getItem(experimentsOverridesKey);
function getExperimentsOverrides(storageService: IStorageService): ITelemetryExperiments {
const valueString = storageService.get(experimentsOverridesKey);
return valueString ? JSON.parse(valueString) : <any>{};
}
function updateExperimentsOverrides(configurationService: IConfigurationService) {
const storageOverrides = getExperimentsOverrides();
function updateExperimentsOverrides(configurationService: IConfigurationService, storageService: IStorageService) {
const storageOverrides = getExperimentsOverrides(storageService);
const config: any = configurationService.getConfiguration('telemetry');
const configOverrides = config && config.experiments || {};
if (!objects.equals(storageOverrides, configOverrides)) {
window.localStorage.setItem(experimentsOverridesKey, JSON.stringify(configOverrides));
storageService.store(experimentsOverridesKey, JSON.stringify(configOverrides));
}
}
@@ -8,24 +8,8 @@ import { localize } from 'vs/nls';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/platform';
import { WelcomePageContribution, WelcomePageAction } from 'vs/workbench/parts/welcome/page/electron-browser/welcomePage';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { isWelcomePageEnabled } from 'vs/platform/telemetry/common/telemetryUtils';
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
'id': 'workbench',
'order': 7,
'title': localize('workbenchConfigurationTitle', "Workbench"),
'properties': {
'workbench.welcome.enabled': {
'type': 'boolean',
'default': isWelcomePageEnabled(),
'description': localize('welcomePage.enabled', "When enabled, will show the Welcome page on startup.")
},
}
});
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(WelcomePageContribution);
@@ -38,6 +38,10 @@ import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/com
import { registerColor, focusBorder, textLinkForeground, textLinkActiveForeground, foreground, descriptionForeground, contrastBorder, activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { getExtraColor } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughUtils';
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
import { isWelcomePageEnabled } from 'vs/platform/telemetry/common/telemetryUtils';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IStorageService } from "vs/platform/storage/common/storage";
import { Registry } from 'vs/platform/platform';
used();
@@ -52,7 +56,8 @@ export class WelcomePageContribution implements IWorkbenchContribution {
@IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IBackupFileService backupFileService: IBackupFileService,
@ITelemetryService telemetryService: ITelemetryService
@ITelemetryService telemetryService: ITelemetryService,
@IStorageService storageService: IStorageService
) {
const enabled = configurationService.lookup<boolean>(enabledKey).value;
if (enabled) {
@@ -66,6 +71,20 @@ export class WelcomePageContribution implements IWorkbenchContribution {
}
}).then(null, onUnexpectedError);
}
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
'id': 'workbench',
'order': 7,
'title': localize('workbenchConfigurationTitle', "Workbench"),
'properties': {
'workbench.welcome.enabled': {
'type': 'boolean',
'default': isWelcomePageEnabled(storageService),
'description': localize('welcomePage.enabled', "When enabled, will show the Welcome page on startup.")
},
}
});
}
public getId() {