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