1/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6"use strict";
7
8/**
9 * This module chooses the correct telemetry controller module to load
10 * based on the process:
11 *
12 * - TelemetryControllerParent is loaded only in the parent process, and
13 *   contains code specific to the parent.
14 * - TelemetryControllerContent is loaded only in content processes, and
15 *   contains code specific to them.
16 *
17 * Both the parent and the content modules load TelemetryControllerBase,
18 * which contains code which is common to all processes.
19 *
20 * This division is important for content process memory usage and
21 * startup time. The parent-specific code occupies tens of KB of memory
22 * which, multiplied by the number of content processes we have, adds up
23 * fast.
24 */
25
26var EXPORTED_SYMBOLS = ["TelemetryController"];
27
28// We can't use Services.appinfo here because tests stub out the appinfo
29// service, and if we touch Services.appinfo now, the built-in version
30// will be cached in place of the stub.
31const isParentProcess =
32  // eslint-disable-next-line mozilla/use-services
33  Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).processType ===
34  Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
35
36var TelemetryController;
37if (isParentProcess) {
38  ({ TelemetryController } = ChromeUtils.import(
39    "resource://gre/modules/TelemetryControllerParent.jsm"
40  ));
41} else {
42  ({ TelemetryController } = ChromeUtils.import(
43    "resource://gre/modules/TelemetryControllerContent.jsm"
44  ));
45}
46