提交 104a4d1b 编写于 作者: B Benjamin Pasero

💄

上级 44bd7e31
......@@ -39,33 +39,6 @@ export function combinedAppender(...appenders: ITelemetryAppender[]): ITelemetry
export const NullAppender: ITelemetryAppender = { log: () => null };
// --- util
export function anonymize(input: string): string {
if (!input) {
return input;
}
let r = '';
for (let i = 0; i < input.length; i++) {
let ch = input[i];
if (ch >= '0' && ch <= '9') {
r += '0';
continue;
}
if (ch >= 'a' && ch <= 'z') {
r += 'a';
continue;
}
if (ch >= 'A' && ch <= 'Z') {
r += 'A';
continue;
}
r += ch;
}
return r;
}
/* __GDPR__FRAGMENT__
"URIDescriptor" : {
"mimeType" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
......@@ -79,9 +52,9 @@ export interface URIDescriptor {
path?: string;
}
export function telemetryURIDescriptor(uri: URI): URIDescriptor {
export function telemetryURIDescriptor(uri: URI, hashPath: (path: string) => string): URIDescriptor {
const fsPath = uri && uri.fsPath;
return fsPath ? { mimeType: guessMimeTypes(fsPath).join(', '), ext: paths.extname(fsPath), path: anonymize(fsPath) } : {};
return fsPath ? { mimeType: guessMimeTypes(fsPath).join(', '), ext: paths.extname(fsPath), path: hashPath(fsPath) } : {};
}
/**
......
......@@ -11,6 +11,7 @@ import { IReference } from 'vs/base/common/lifecycle';
import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUtils';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
/**
* A read-only text editor input whos contents are made of the provided resource that points to an existing
......@@ -29,7 +30,8 @@ export class ResourceEditorInput extends EditorInput {
name: string,
description: string,
resource: URI,
@ITextModelService private textModelResolverService: ITextModelService
@ITextModelService private textModelResolverService: ITextModelService,
@IHashService private hashService: IHashService
) {
super();
......@@ -70,7 +72,7 @@ export class ResourceEditorInput extends EditorInput {
public getTelemetryDescriptor(): object {
const descriptor = super.getTelemetryDescriptor();
descriptor['resource'] = telemetryURIDescriptor(this.resource);
descriptor['resource'] = telemetryURIDescriptor(this.resource, path => this.hashService.createSHA1(path));
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
......
......@@ -22,6 +22,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { Verbosity } from 'vs/platform/editor/common/editor';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
/**
* An editor input to be used for untitled text buffers.
......@@ -48,7 +49,8 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ITextFileService private textFileService: ITextFileService,
@IEnvironmentService private environmentService: IEnvironmentService
@IEnvironmentService private environmentService: IEnvironmentService,
@IHashService private hashService: IHashService
) {
super();
......@@ -252,7 +254,7 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
public getTelemetryDescriptor(): object {
const descriptor = super.getTelemetryDescriptor();
descriptor['resource'] = telemetryURIDescriptor(this.getResource());
descriptor['resource'] = telemetryURIDescriptor(this.getResource(), path => this.hashService.createSHA1(path));
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
......
......@@ -91,6 +91,8 @@ import { foreground, selectionBackground, focusBorder, scrollbarShadow, scrollba
import { TextMateService } from 'vs/workbench/services/textMate/electron-browser/TMSyntax';
import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService';
import { IBroadcastService, BroadcastService } from 'vs/platform/broadcast/electron-browser/broadcastService';
import { HashService } from 'vs/workbench/services/hash/node/hashService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
/**
* Services that we require for the Shell
......@@ -293,6 +295,9 @@ export class WorkbenchShell {
restoreFontInfo(this.storageService);
readFontInfo(BareFontInfo.createFromRawSettings(this.configurationService.getConfiguration('editor'), browser.getZoomLevel()));
// Hash
serviceCollection.set(IHashService, new SyncDescriptor(HashService));
// Experiments
this.experimentService = instantiationService.createInstance(ExperimentService);
serviceCollection.set(IExperimentService, this.experimentService);
......
......@@ -24,6 +24,7 @@ import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUt
import { Verbosity } from 'vs/platform/editor/common/editor';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
/**
* A file editor input is the input type for the file editor of file system resources.
......@@ -47,7 +48,8 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@ITextFileService private textFileService: ITextFileService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ITextModelService private textModelResolverService: ITextModelService
@ITextModelService private textModelResolverService: ITextModelService,
@IHashService private hashService: IHashService
) {
super();
......@@ -274,7 +276,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
public getTelemetryDescriptor(): object {
const descriptor = super.getTelemetryDescriptor();
descriptor['resource'] = telemetryURIDescriptor(this.getResource());
descriptor['resource'] = telemetryURIDescriptor(this.getResource(), path => this.hashService.createSHA1(path));
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
......
......@@ -7,6 +7,7 @@
import URI from 'vs/base/common/uri';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export interface HtmlInputOptions {
......@@ -25,8 +26,9 @@ export class HtmlInput extends ResourceEditorInput {
description: string,
resource: URI,
public readonly options: HtmlInputOptions,
@ITextModelService textModelResolverService: ITextModelService
@ITextModelService textModelResolverService: ITextModelService,
@IHashService hashService: IHashService
) {
super(name, description, resource, textModelResolverService);
super(name, description, resource, textModelResolverService, hashService);
}
}
......@@ -59,6 +59,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import { Registry } from 'vs/platform/registry/common/platform';
import { MessageController } from 'vs/editor/contrib/message/messageController';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export class PreferencesEditorInput extends SideBySideEditorInput {
public static ID: string = 'workbench.editorinputs.preferencesEditorInput';
......@@ -75,9 +76,10 @@ export class PreferencesEditorInput extends SideBySideEditorInput {
export class DefaultPreferencesEditorInput extends ResourceEditorInput {
public static ID = 'workbench.editorinputs.defaultpreferences';
constructor(defaultSettingsResource: URI,
@ITextModelService textModelResolverService: ITextModelService
@ITextModelService textModelResolverService: ITextModelService,
@IHashService hashService: IHashService
) {
super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, textModelResolverService);
super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, textModelResolverService, hashService);
}
getTypeId(): string {
......
......@@ -15,6 +15,7 @@ import { marked } from 'vs/base/common/marked/marked';
import { Schemas } from 'vs/base/common/network';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export class WalkThroughModel extends EditorModel {
......@@ -63,7 +64,8 @@ export class WalkThroughInput extends EditorInput {
private options: WalkThroughInputOptions,
@ITelemetryService private telemetryService: ITelemetryService,
@ILifecycleService lifecycleService: ILifecycleService,
@ITextModelService private textModelResolverService: ITextModelService
@ITextModelService private textModelResolverService: ITextModelService,
@IHashService private hashService: IHashService
) {
super();
this.disposables.push(lifecycleService.onShutdown(e => this.disposeTelemetry(e)));
......@@ -92,7 +94,7 @@ export class WalkThroughInput extends EditorInput {
getTelemetryDescriptor(): object {
const descriptor = super.getTelemetryDescriptor();
descriptor['target'] = this.getTelemetryFrom();
descriptor['resource'] = telemetryURIDescriptor(this.options.resource);
descriptor['resource'] = telemetryURIDescriptor(this.options.resource, path => this.hashService.createSHA1(path));
/* __GDPR__FRAGMENT__
"EditorTelemetryDescriptor" : {
"target" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IHashService = createDecorator<IHashService>('hashService');
export interface IHashService {
_serviceBrand: any;
/**
* Produce a SHA1 hash of the provided content.
*/
createSHA1(content: string): string;
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { createHash } from 'crypto';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export class HashService implements IHashService {
_serviceBrand: any;
public createSHA1(content: string): string {
return createHash('sha1').update(content).digest('hex');
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { KeyCode, SimpleKeybinding, ChordKeybinding } from 'vs/base/common/keyCodes';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import extfs = require('vs/base/node/extfs');
import { TestTextFileService, TestEditorGroupService, TestLifecycleService, TestBackupFileService, TestContextService, TestTextResourceConfigurationService } from 'vs/workbench/test/workbenchTestServices';
import { TestTextFileService, TestEditorGroupService, TestLifecycleService, TestBackupFileService, TestContextService, TestTextResourceConfigurationService, TestHashService } from 'vs/workbench/test/workbenchTestServices';
import { IWorkspaceContextService, Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import uuid = require('vs/base/common/uuid');
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
......@@ -42,6 +42,7 @@ import { KeybindingsEditingService } from 'vs/workbench/services/keybinding/comm
import { IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
interface Modifiers {
metaKey?: boolean;
......@@ -70,6 +71,7 @@ suite('Keybindings Editing', () => {
instantiationService.stub(IConfigurationService, 'onDidChangeConfiguration', () => { });
instantiationService.stub(IWorkspaceContextService, new TestContextService());
instantiationService.stub(ILifecycleService, new TestLifecycleService());
instantiationService.stub(IHashService, new TestHashService());
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(IModeService, ModeServiceImpl);
......
......@@ -31,9 +31,9 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { anonymize } from 'vs/platform/telemetry/common/telemetryUtils';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IRawTextSource } from 'vs/editor/common/model/textSource';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
/**
* The text file editor model listens to changes to its underlying code editor model and saves these changes through the file service back to the disk.
......@@ -87,6 +87,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
@IBackupFileService private backupFileService: IBackupFileService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IHashService private hashService: IHashService
) {
super(modelService, modeService);
......@@ -380,7 +381,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
"path": { "classification": "CustomerContent", "purpose": "FeatureInsight" }
}
*/
this.telemetryService.publicLog('fileGet', { mimeType: guessMimeTypes(this.resource.fsPath).join(', '), ext: paths.extname(this.resource.fsPath), path: anonymize(this.resource.fsPath) });
this.telemetryService.publicLog('fileGet', { mimeType: guessMimeTypes(this.resource.fsPath).join(', '), ext: paths.extname(this.resource.fsPath), path: this.hashService.createSHA1(this.resource.fsPath) });
}
return model;
......
......@@ -59,6 +59,7 @@ import { IRecentlyOpened } from 'vs/platform/history/common/history';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { IPosition } from 'vs/editor/common/core/position';
import { ICommandAction } from 'vs/platform/actions/common/actions';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, void 0);
......@@ -259,6 +260,7 @@ export function workbenchInstantiationService(): IInstantiationService {
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
instantiationService.stub(IEnvironmentService, TestEnvironmentService);
instantiationService.stub(IThemeService, new TestThemeService());
instantiationService.stub(IHashService, new TestHashService());
return instantiationService;
}
......@@ -1223,4 +1225,12 @@ export class TestTextResourceConfigurationService implements ITextResourceConfig
public getConfiguration(resource: any, position?: any, section?: any): any {
return this.configurationService.getConfiguration(section, { resource });
}
}
export class TestHashService implements IHashService {
_serviceBrand: any;
createSHA1(content: string): string {
return content;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册