提交 87e2e7d8 编写于 作者: J Joao Moreno

report uninstall telemetry

上级 fdcf26e8
......@@ -195,12 +195,17 @@ export interface IQueryOptions {
sortOrder?: SortOrder;
}
export enum StatisticType {
Uninstall = 'uninstall'
}
export interface IExtensionGalleryService {
_serviceBrand: any;
isEnabled(): boolean;
getRequestHeaders(): TPromise<{ [key: string]: string; }>;
query(options?: IQueryOptions): TPromise<IPager<IGalleryExtension>>;
download(extension: IGalleryExtension): TPromise<string>;
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void>;
getReadme(extension: IGalleryExtension): TPromise<string>;
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
getChangelog(extension: IGalleryMetadata): TPromise<string>;
......
......@@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import * as uuid from 'vs/base/common/uuid';
import { distinct } from 'vs/base/common/arrays';
import { getErrorMessage } from 'vs/base/common/errors';
import { IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { assign, getOrDefault } from 'vs/base/common/objects';
import { IRequestService } from 'vs/platform/request/node/request';
......@@ -385,6 +385,23 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return { galleryExtensions, total };
}
async reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void> {
if (!this.isEnabled()) {
return;
}
try {
const headers = await this.commonHTTPHeaders;
await this.requestService.request({
type: 'POST',
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
headers
});
} catch (err) {
// noop
}
}
download(extension: IGalleryExtension): TPromise<string> {
return this.loadCompatibleVersion(extension).then(extension => {
const zipPath = path.join(tmpdir(), uuid.generateUuid());
......
......@@ -17,7 +17,8 @@ import { Promise, TPromise } from 'vs/base/common/winjs.base';
import {
IExtensionManagementService, IExtensionGalleryService, ILocalExtension,
IGalleryExtension, IExtensionManifest, IGalleryMetadata,
InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, LocalExtensionType
InstallExtensionEvent, DidInstallExtensionEvent, DidUninstallExtensionEvent, LocalExtensionType,
StatisticType
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { getLocalExtensionIdFromGallery, getLocalExtensionIdFromManifest, getGalleryExtensionIdFromLocal, getIdAndVersionFromLocalExtensionId, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { localizeManifest } from '../common/extensionNls';
......@@ -223,9 +224,9 @@ export class ExtensionManagementService implements IExtensionManagementService {
}
private rollback(localExtension: ILocalExtension, dependecies: IGalleryExtension[]): TPromise<void> {
return this.doUninstall(localExtension.id)
return this.doUninstall(localExtension)
.then(() => this.filterOutUninstalled(dependecies))
.then(installed => TPromise.join(installed.map((i) => this.doUninstall(i.id))))
.then(installed => TPromise.join(installed.map((i) => this.doUninstall(i))))
.then(() => null);
}
......@@ -304,7 +305,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
}
private checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[], force: boolean): TPromise<void> {
return this.preUninstallExtension(extension.id)
return this.preUninstallExtension(extension)
.then(() => this.hasDependencies(extension, installed) ? this.promptForDependenciesAndUninstall(extension, installed, force) : this.promptAndUninstall(extension, installed, force))
.then(() => this.postUninstallExtension(extension.id),
error => {
......@@ -370,7 +371,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
if (dependents.length) {
return TPromise.wrapError<void>(new Error(this.getDependentsErrorMessage(extension, dependents)));
}
return TPromise.join([this.uninstallExtension(extension.id), ...dependenciesToUninstall.map(d => this.doUninstall(d.id))]).then(() => null);
return TPromise.join([this.uninstallExtension(extension.id), ...dependenciesToUninstall.map(d => this.doUninstall(d))]).then(() => null);
}
private getDependentsErrorMessage(extension: ILocalExtension, dependents: ILocalExtension[]): string {
......@@ -419,21 +420,22 @@ export class ExtensionManagementService implements IExtensionManagementService {
return installed.filter(e => e.manifest.extensionDependencies && e.manifest.extensionDependencies.indexOf(getGalleryExtensionIdFromLocal(extension)) !== -1);
}
private doUninstall(id: string): TPromise<void> {
return this.preUninstallExtension(id)
.then(() => this.uninstallExtension(id))
.then(() => this.postUninstallExtension(id),
private doUninstall(extension: ILocalExtension): TPromise<void> {
return this.preUninstallExtension(extension)
.then(() => this.uninstallExtension(extension.id))
.then(() => this.postUninstallExtension(extension.id),
error => {
this.postUninstallExtension(id, error);
this.postUninstallExtension(extension.id, error);
return TPromise.wrapError(error);
});
}
private preUninstallExtension(id: string): TPromise<void> {
const extensionPath = path.join(this.extensionsPath, id);
private preUninstallExtension(extension: ILocalExtension): TPromise<void> {
const extensionPath = path.join(this.extensionsPath, extension.id);
return pfs.exists(extensionPath)
.then(exists => exists ? null : TPromise.wrapError(new Error(nls.localize('notExists', "Could not find extension"))))
.then(() => this._onUninstallExtension.fire(id));
.then(() => this._onUninstallExtension.fire(extension.id))
.then(() => this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall));
}
private uninstallExtension(id: string): TPromise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册