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 this.EXPORTED_SYMBOLS = ["TelemetryTimestamps"];
7 const Cu = Components.utils;
9 /**
10 * This module's purpose is to collect timestamps for important
11 * application-specific events.
12 *
13 * The TelemetryPing component attaches the timestamps stored by this module to
14 * the telemetry submission, substracting the process lifetime so that the times
15 * are relative to process startup. The overall goal is to produce a basic
16 * timeline of the startup process.
17 */
18 let timeStamps = {};
20 this.TelemetryTimestamps = {
21 /**
22 * Adds a timestamp to the list. The addition of TimeStamps that already have
23 * a value stored is ignored.
24 *
25 * @param name must be a unique, generally "camelCase" descriptor of what the
26 * timestamp represents. e.g.: "delayedStartupStarted"
27 * @param value is a timeStamp in milliseconds since the epoch. If omitted,
28 * defaults to Date.now().
29 */
30 add: function TT_add(name, value) {
31 // Default to "now" if not specified
32 if (value == null)
33 value = Date.now();
35 if (isNaN(value))
36 throw new Error("Value must be a timestamp");
38 // If there's an existing value, just ignore the new value.
39 if (timeStamps.hasOwnProperty(name))
40 return;
42 timeStamps[name] = value;
43 },
45 /**
46 * Returns a JS object containing all of the timeStamps as properties (can be
47 * easily serialized to JSON). Used by TelemetryPing to retrieve the data
48 * to attach to the telemetry submission.
49 */
50 get: function TT_get() {
51 // Return a copy of the object.
52 return Cu.cloneInto(timeStamps, {});
53 }
54 };