From 5d84744c8a3fb121a760cd9c1e64ee3f4f36cbec Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Thu, 18 Mar 2021 15:07:18 +0100 Subject: [PATCH] Initialize Glean and enable ping encryption --- core-addon/Core.js | 8 ++++++++ core-addon/DataCollection.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/core-addon/Core.js b/core-addon/Core.js index d1ba5611..7fcff23f 100644 --- a/core-addon/Core.js +++ b/core-addon/Core.js @@ -4,6 +4,7 @@ import Storage from "./Storage.js"; import DataCollection from "./DataCollection.js"; +import * as rallyMetrics from "../public/generated/rally.js"; // The path of the embedded resource used to control options. const OPTIONS_PAGE_PATH = "public/index.html"; @@ -27,6 +28,11 @@ export default class Core { this._storage = new Storage(); this._dataCollection = new DataCollection(); + // Initialize the collection engine once we know if + // user is enrolled or not. + this._storage.getRallyID().finally(id => + this._dataCollection.initialize(id !== undefined)); + // Asynchronously get the available studies. We don't need to wait // for this to finish, the UI can handle the wait. this._availableStudies = this._fetchAvailableStudies().then((studies) => @@ -397,6 +403,8 @@ export default class Core { await this._storage.setRallyID(rallyId); await this._storage.setDeletionID(deletionId); + rallyMetrics.id.set(rallyId); + // Override the uninstall URL to include the rallyID, for deleting data without exposing the Rally ID. await this.setUninstallURL(); diff --git a/core-addon/DataCollection.js b/core-addon/DataCollection.js index 332c67b6..084bfbe1 100644 --- a/core-addon/DataCollection.js +++ b/core-addon/DataCollection.js @@ -2,6 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +import Glean from "@mozilla/glean/webext"; +import PingEncryptionPlugin from "@mozilla/glean/webext/plugins/encryption"; + // The encryption key id and JWK to encrypt data that go // to the "core" environment (i.e. `pioneer-core`). See // bug 1677761 for additional details. @@ -15,6 +18,24 @@ const CORE_ENCRYPTION_JWK = { }; export default class DataCollection { + /** + * Initializes the data collection engine. + * + * @param {boolean} userEnrolled + * Whether or not user has enrolled in the platform. + */ + initialize(userEnrolled) { + // Initialize Glean. Note that we always set 'uploadEnabled=true' if user + // consented to join Rally. Upload is always enabled unless the web-extension + // is uninstalled. + Glean.initialize("rally-core", userEnrolled, { + plugins: [ + new PingEncryptionPlugin(CORE_ENCRYPTION_JWK) + ] + } + ); + } + /** * Sends an otherwise-empty ping with the deletion ID other provided info. *