提交 c08d8b42 编写于 作者: S Sandeep Somavarapu

introduce gallery machine id resource in env

上级 73a34e68
......@@ -170,4 +170,6 @@ export interface IEnvironmentService {
webviewEndpoint?: string;
readonly webviewResourceRoot: string;
readonly webviewCspSource: string;
readonly galleryMachineIdResource?: URI;
}
......@@ -266,6 +266,9 @@ export class EnvironmentService implements IEnvironmentService {
@memoize
get nodeCachedDataDir(): string | undefined { return process.env['VSCODE_NODE_CACHED_DATA_DIR'] || undefined; }
@memoize
get galleryMachineIdResource(): URI { return resources.joinPath(URI.file(this.userDataPath), 'machineid'); }
get disableUpdates(): boolean { return !!this._args['disable-updates']; }
get disableCrashReporter(): boolean { return !!this._args['disable-crash-reporter']; }
......
......@@ -9,7 +9,7 @@ import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGallery
import { assign, getOrDefault } from 'vs/base/common/objects';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IPager } from 'vs/base/common/paging';
import { IRequestService, IRequestOptions, IRequestContext, asJson, asText } from 'vs/platform/request/common/request';
import { IRequestService, IRequestOptions, IRequestContext, asJson, asText, IHeaders } from 'vs/platform/request/common/request';
import { isEngineValid } from 'vs/platform/extensions/common/extensionValidator';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { generateUuid, isUUID } from 'vs/base/common/uuid';
......@@ -774,12 +774,14 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
export async function resolveMarketplaceHeaders(version: string, environmentService: IEnvironmentService, fileService: IFileService): Promise<{ [key: string]: string; }> {
const marketplaceMachineIdFile = joinPath(URI.file(environmentService.userDataPath), 'machineid');
const headers: IHeaders = {
'X-Market-Client-Id': `VSCode ${version}`,
'User-Agent': `VSCode ${version}`
};
let uuid: string | null = null;
if (environmentService.galleryMachineIdResource) {
try {
const contents = await fileService.readFile(marketplaceMachineIdFile);
const contents = await fileService.readFile(environmentService.galleryMachineIdResource);
const value = contents.value.toString();
uuid = isUUID(value) ? value : null;
} catch (e) {
......@@ -789,14 +791,13 @@ export async function resolveMarketplaceHeaders(version: string, environmentServ
if (!uuid) {
uuid = generateUuid();
try {
await fileService.writeFile(marketplaceMachineIdFile, VSBuffer.fromString(uuid));
await fileService.writeFile(environmentService.galleryMachineIdResource, VSBuffer.fromString(uuid));
} catch (error) {
//noop
}
}
return {
'X-Market-Client-Id': `VSCode ${version}`,
'User-Agent': `VSCode ${version}`,
'X-Market-User-Id': uuid
};
headers['X-Market-User-Id'] = uuid;
}
return headers;
}
\ No newline at end of file
......@@ -143,6 +143,7 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
driverHandle?: string;
driverVerbose: boolean;
webviewEndpoint?: string;
galleryMachineIdResource?: URI;
get webviewResourceRoot(): string {
return this.webviewEndpoint ? this.webviewEndpoint + '/vscode-resource{{resource}}' : 'vscode-resource:{{resource}}';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册