Skip to content

Commit

Permalink
reuse telemetry info when getting common http headers, will likely ma…
Browse files Browse the repository at this point in the history
…ke use not spawn a process which saves at least 10ms, #17108
  • Loading branch information
jrieken committed Dec 20, 2016
1 parent d749475 commit 8a41bdb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { parseArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/node/product';
import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http';
import { getCommonHttpHeaders } from 'vs/platform/environment/node/http';
import { IWindowSettings } from 'vs/platform/windows/common/windows';

export interface IWindowState {
Expand Down Expand Up @@ -154,7 +155,8 @@ export class VSCodeWindow implements IVSCodeWindow {
@ILogService private logService: ILogService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IConfigurationService private configurationService: IConfigurationService,
@IStorageService private storageService: IStorageService
@IStorageService private storageService: IStorageService,
@ITelemetryService private telemetryService: ITelemetryService
) {
this.options = config;
this._lastFocusTime = -1;
Expand Down Expand Up @@ -208,7 +210,7 @@ export class VSCodeWindow implements IVSCodeWindow {
// TODO@joao: hook this up to some initialization routine
// this causes a race between setting the headers and doing
// a request that needs them. chances are low
getCommonHTTPHeaders().done(headers => {
getCommonHttpHeaders(this.telemetryService).done(headers => {
if (!this._win) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/vs/code/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ipcMain as ipc, app, screen, BrowserWindow, dialog } from 'electron';
import { IPathWithLineAndColumn, parseLineAndColumnAware } from 'vs/code/electron-main/paths';
import { ILifecycleService, UnloadReason } from 'vs/code/electron-main/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ILogService } from 'vs/code/electron-main/log';
import { getPathLabel } from 'vs/base/common/labels';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -148,7 +149,8 @@ export class WindowsManager implements IWindowsMainService {
@IEnvironmentService private environmentService: IEnvironmentService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IBackupMainService private backupService: IBackupMainService,
@IConfigurationService private configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService
) { }

public ready(initialUserEnv: platform.IProcessEnvironment): void {
Expand Down Expand Up @@ -734,7 +736,8 @@ export class WindowsManager implements IWindowsMainService {
this.logService,
this.environmentService,
this.configurationService,
this.storageService
this.storageService,
this.telemetryService
);

WindowsManager.WINDOWS.push(vscodeWindow);
Expand Down
10 changes: 5 additions & 5 deletions src/vs/platform/environment/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import { TPromise } from 'vs/base/common/winjs.base';
import { getMachineId } from 'vs/base/node/id';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import pkg from 'vs/platform/node/package';

export function getCommonHTTPHeaders(): TPromise<{ [key: string]: string; }> {
return getMachineId().then(machineId => ({
export function getCommonHttpHeaders(telemetryService: ITelemetryService): TPromise<{ [key: string]: string }> {
return telemetryService.getTelemetryInfo().then(info => ({
'X-Market-Client-Id': `VSCode ${pkg.version}`,
'User-Agent': `VSCode ${pkg.version}`,
'X-Market-User-Id': machineId
'X-Market-User-Id': info.machineId
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import pkg from 'vs/platform/node/package';
import product from 'vs/platform/node/product';
import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator';
import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http';
import { getCommonHttpHeaders } from 'vs/platform/environment/node/http';

interface IRawGalleryExtensionFile {
assetType: string;
Expand Down Expand Up @@ -269,7 +269,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {

@memoize
private get commonHTTPHeaders(): TPromise<{ [key: string]: string; }> {
return getCommonHTTPHeaders();
return getCommonHttpHeaders(this.telemetryService);
}

constructor(
Expand Down

0 comments on commit 8a41bdb

Please sign in to comment.