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 |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = [ |
michael@0 | 8 | "DummyMeasurement", |
michael@0 | 9 | "DummyProvider", |
michael@0 | 10 | "DummyConstantProvider", |
michael@0 | 11 | "DummyPullOnlyThrowsOnInitProvider", |
michael@0 | 12 | "DummyThrowOnInitProvider", |
michael@0 | 13 | "DummyThrowOnShutdownProvider", |
michael@0 | 14 | ]; |
michael@0 | 15 | |
michael@0 | 16 | const {utils: Cu} = Components; |
michael@0 | 17 | |
michael@0 | 18 | Cu.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 19 | Cu.import("resource://gre/modules/Metrics.jsm"); |
michael@0 | 20 | Cu.import("resource://gre/modules/Task.jsm"); |
michael@0 | 21 | |
michael@0 | 22 | this.DummyMeasurement = function DummyMeasurement(name="DummyMeasurement") { |
michael@0 | 23 | this.name = name; |
michael@0 | 24 | |
michael@0 | 25 | Metrics.Measurement.call(this); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | DummyMeasurement.prototype = { |
michael@0 | 29 | __proto__: Metrics.Measurement.prototype, |
michael@0 | 30 | |
michael@0 | 31 | version: 1, |
michael@0 | 32 | |
michael@0 | 33 | fields: { |
michael@0 | 34 | "daily-counter": {type: Metrics.Storage.FIELD_DAILY_COUNTER}, |
michael@0 | 35 | "daily-discrete-numeric": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_NUMERIC}, |
michael@0 | 36 | "daily-discrete-text": {type: Metrics.Storage.FIELD_DAILY_DISCRETE_TEXT}, |
michael@0 | 37 | "daily-last-numeric": {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC}, |
michael@0 | 38 | "daily-last-text": {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT}, |
michael@0 | 39 | "last-numeric": {type: Metrics.Storage.FIELD_LAST_NUMERIC}, |
michael@0 | 40 | "last-text": {type: Metrics.Storage.FIELD_LAST_TEXT}, |
michael@0 | 41 | }, |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | |
michael@0 | 45 | this.DummyProvider = function DummyProvider(name="DummyProvider") { |
michael@0 | 46 | Object.defineProperty(this, "name", { |
michael@0 | 47 | value: name, |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | this.measurementTypes = [DummyMeasurement]; |
michael@0 | 51 | |
michael@0 | 52 | Metrics.Provider.call(this); |
michael@0 | 53 | |
michael@0 | 54 | this.constantMeasurementName = "DummyMeasurement"; |
michael@0 | 55 | this.collectConstantCount = 0; |
michael@0 | 56 | this.throwDuringCollectConstantData = null; |
michael@0 | 57 | this.throwDuringConstantPopulate = null; |
michael@0 | 58 | |
michael@0 | 59 | this.collectDailyCount = 0; |
michael@0 | 60 | |
michael@0 | 61 | this.havePushedMeasurements = true; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | DummyProvider.prototype = { |
michael@0 | 65 | __proto__: Metrics.Provider.prototype, |
michael@0 | 66 | |
michael@0 | 67 | name: "DummyProvider", |
michael@0 | 68 | |
michael@0 | 69 | collectConstantData: function () { |
michael@0 | 70 | this.collectConstantCount++; |
michael@0 | 71 | |
michael@0 | 72 | if (this.throwDuringCollectConstantData) { |
michael@0 | 73 | throw new Error(this.throwDuringCollectConstantData); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | return this.enqueueStorageOperation(function doStorage() { |
michael@0 | 77 | if (this.throwDuringConstantPopulate) { |
michael@0 | 78 | throw new Error(this.throwDuringConstantPopulate); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | let m = this.getMeasurement("DummyMeasurement", 1); |
michael@0 | 82 | let now = new Date(); |
michael@0 | 83 | m.incrementDailyCounter("daily-counter", now); |
michael@0 | 84 | m.addDailyDiscreteNumeric("daily-discrete-numeric", 1, now); |
michael@0 | 85 | m.addDailyDiscreteNumeric("daily-discrete-numeric", 2, now); |
michael@0 | 86 | m.addDailyDiscreteText("daily-discrete-text", "foo", now); |
michael@0 | 87 | m.addDailyDiscreteText("daily-discrete-text", "bar", now); |
michael@0 | 88 | m.setDailyLastNumeric("daily-last-numeric", 3, now); |
michael@0 | 89 | m.setDailyLastText("daily-last-text", "biz", now); |
michael@0 | 90 | m.setLastNumeric("last-numeric", 4, now); |
michael@0 | 91 | return m.setLastText("last-text", "bazfoo", now); |
michael@0 | 92 | }.bind(this)); |
michael@0 | 93 | }, |
michael@0 | 94 | |
michael@0 | 95 | collectDailyData: function () { |
michael@0 | 96 | this.collectDailyCount++; |
michael@0 | 97 | |
michael@0 | 98 | return Promise.resolve(); |
michael@0 | 99 | }, |
michael@0 | 100 | }; |
michael@0 | 101 | |
michael@0 | 102 | |
michael@0 | 103 | this.DummyConstantProvider = function () { |
michael@0 | 104 | DummyProvider.call(this, this.name); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | DummyConstantProvider.prototype = { |
michael@0 | 108 | __proto__: DummyProvider.prototype, |
michael@0 | 109 | |
michael@0 | 110 | name: "DummyConstantProvider", |
michael@0 | 111 | |
michael@0 | 112 | pullOnly: true, |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | this.DummyThrowOnInitProvider = function () { |
michael@0 | 116 | DummyProvider.call(this, "DummyThrowOnInitProvider"); |
michael@0 | 117 | |
michael@0 | 118 | throw new Error("Dummy Error"); |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | this.DummyThrowOnInitProvider.prototype = { |
michael@0 | 122 | __proto__: DummyProvider.prototype, |
michael@0 | 123 | |
michael@0 | 124 | name: "DummyThrowOnInitProvider", |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | this.DummyPullOnlyThrowsOnInitProvider = function () { |
michael@0 | 128 | DummyConstantProvider.call(this); |
michael@0 | 129 | |
michael@0 | 130 | throw new Error("Dummy Error"); |
michael@0 | 131 | }; |
michael@0 | 132 | |
michael@0 | 133 | this.DummyPullOnlyThrowsOnInitProvider.prototype = { |
michael@0 | 134 | __proto__: DummyConstantProvider.prototype, |
michael@0 | 135 | |
michael@0 | 136 | name: "DummyPullOnlyThrowsOnInitProvider", |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | this.DummyThrowOnShutdownProvider = function () { |
michael@0 | 140 | DummyProvider.call(this, "DummyThrowOnShutdownProvider"); |
michael@0 | 141 | }; |
michael@0 | 142 | |
michael@0 | 143 | this.DummyThrowOnShutdownProvider.prototype = { |
michael@0 | 144 | __proto__: DummyProvider.prototype, |
michael@0 | 145 | |
michael@0 | 146 | name: "DummyThrowOnShutdownProvider", |
michael@0 | 147 | |
michael@0 | 148 | pullOnly: true, |
michael@0 | 149 | |
michael@0 | 150 | onShutdown: function () { |
michael@0 | 151 | throw new Error("Dummy shutdown error"); |
michael@0 | 152 | }, |
michael@0 | 153 | }; |
michael@0 | 154 |