Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /**
6 * Collects telemetry data for Tabview.
7 */
8 let Telemetry = {
9 TOPIC_GATHER_TELEMETRY: "gather-telemetry",
11 /**
12 * Initializes the object.
13 */
14 init: function Telemetry_init() {
15 Services.obs.addObserver(this, this.TOPIC_GATHER_TELEMETRY, false);
16 },
18 /**
19 * Uninitializes the object.
20 */
21 uninit: function Telemetry_uninit() {
22 Services.obs.removeObserver(this, this.TOPIC_GATHER_TELEMETRY);
23 },
25 /**
26 * Adds telemetry values to gather usage statistics.
27 */
28 _collect: function Telemetry_collect() {
29 let stackedGroupsCount = 0;
30 let childCounts = [];
32 GroupItems.groupItems.forEach(function (groupItem) {
33 if (!groupItem.isEmpty()) {
34 childCounts.push(groupItem.getChildren().length);
36 if (groupItem.isStacked())
37 stackedGroupsCount++;
38 }
39 });
41 function addTelemetryValue(aId, aValue) {
42 Services.telemetry.getHistogramById("PANORAMA_" + aId).add(aValue);
43 }
44 function median(aChildCounts) {
45 aChildCounts.sort(function(x, y) { return x - y; });
46 let middle = Math.floor(aChildCounts.length / 2);
47 return aChildCounts[middle];
48 }
50 addTelemetryValue("GROUPS_COUNT", GroupItems.groupItems.length);
51 addTelemetryValue("STACKED_GROUPS_COUNT", stackedGroupsCount);
52 addTelemetryValue("MEDIAN_TABS_IN_GROUPS_COUNT", median(childCounts));
53 },
55 /**
56 * Observes for gather telemetry topic.
57 */
58 observe: function Telemetry_observe(aSubject, aTopic, aData) {
59 if (!gWindow.PrivateBrowsingUtils.isWindowPrivate(gWindow))
60 this._collect();
61 }
62 }