michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Collects telemetry data for Tabview. michael@0: */ michael@0: let Telemetry = { michael@0: TOPIC_GATHER_TELEMETRY: "gather-telemetry", michael@0: michael@0: /** michael@0: * Initializes the object. michael@0: */ michael@0: init: function Telemetry_init() { michael@0: Services.obs.addObserver(this, this.TOPIC_GATHER_TELEMETRY, false); michael@0: }, michael@0: michael@0: /** michael@0: * Uninitializes the object. michael@0: */ michael@0: uninit: function Telemetry_uninit() { michael@0: Services.obs.removeObserver(this, this.TOPIC_GATHER_TELEMETRY); michael@0: }, michael@0: michael@0: /** michael@0: * Adds telemetry values to gather usage statistics. michael@0: */ michael@0: _collect: function Telemetry_collect() { michael@0: let stackedGroupsCount = 0; michael@0: let childCounts = []; michael@0: michael@0: GroupItems.groupItems.forEach(function (groupItem) { michael@0: if (!groupItem.isEmpty()) { michael@0: childCounts.push(groupItem.getChildren().length); michael@0: michael@0: if (groupItem.isStacked()) michael@0: stackedGroupsCount++; michael@0: } michael@0: }); michael@0: michael@0: function addTelemetryValue(aId, aValue) { michael@0: Services.telemetry.getHistogramById("PANORAMA_" + aId).add(aValue); michael@0: } michael@0: function median(aChildCounts) { michael@0: aChildCounts.sort(function(x, y) { return x - y; }); michael@0: let middle = Math.floor(aChildCounts.length / 2); michael@0: return aChildCounts[middle]; michael@0: } michael@0: michael@0: addTelemetryValue("GROUPS_COUNT", GroupItems.groupItems.length); michael@0: addTelemetryValue("STACKED_GROUPS_COUNT", stackedGroupsCount); michael@0: addTelemetryValue("MEDIAN_TABS_IN_GROUPS_COUNT", median(childCounts)); michael@0: }, michael@0: michael@0: /** michael@0: * Observes for gather telemetry topic. michael@0: */ michael@0: observe: function Telemetry_observe(aSubject, aTopic, aData) { michael@0: if (!gWindow.PrivateBrowsingUtils.isWindowPrivate(gWindow)) michael@0: this._collect(); michael@0: } michael@0: } michael@0: