Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
Initialize Glean and enable ping encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexterp37 committed Mar 22, 2021
1 parent aa7afad commit 5d84744
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core-addon/Core.js
Expand Up @@ -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";
Expand All @@ -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) =>
Expand Down Expand Up @@ -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();

Expand Down
21 changes: 21 additions & 0 deletions core-addon/DataCollection.js
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down

0 comments on commit 5d84744

Please sign in to comment.