Bug 1967809 - Add more isDestroyed checks to TranslationsEngine actors r=translations-reviewers,gregtatum
Adds a few more checks for isDestroyed in places where we might send asynchronous messages within the TranslationsEngine actors. Differential Revision: https://phabricator.services.mozilla.com/D250765
This commit is contained in:
committed by
enordin@mozilla.com
parent
b954773108
commit
deffee7c59
@@ -16,6 +16,11 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
"chrome://global/content/translations/translations-engine.sys.mjs",
|
||||
});
|
||||
|
||||
/**
|
||||
* @typedef {import("../translations").LanguagePair} LanguagePair
|
||||
* @typedef {import("../translations").TranslationsEnginePayload} TranslationsEnginePayload
|
||||
*/
|
||||
|
||||
/**
|
||||
* The engine child is responsible for exposing privileged code to the un-privileged
|
||||
* space the engine runs in.
|
||||
@@ -136,6 +141,10 @@ export class TranslationsEngineChild extends JSProcessActorChild {
|
||||
totalTranslatedWords,
|
||||
totalCompletedRequests,
|
||||
}) {
|
||||
if (this.#isDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendAsyncMessage("TranslationsEngine:ReportEnginePerformance", {
|
||||
sourceLanguage,
|
||||
targetLanguage,
|
||||
@@ -147,8 +156,14 @@ export class TranslationsEngineChild extends JSProcessActorChild {
|
||||
|
||||
/**
|
||||
* @param {LanguagePair} languagePair
|
||||
*
|
||||
* @returns {Promise<TranslationsEnginePayload> | undefined}
|
||||
*/
|
||||
TE_requestEnginePayload(languagePair) {
|
||||
if (this.#isDestroyed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.sendQuery("TranslationsEngine:RequestEnginePayload", {
|
||||
languagePair,
|
||||
});
|
||||
@@ -159,6 +174,10 @@ export class TranslationsEngineChild extends JSProcessActorChild {
|
||||
* @param {"ready" | "error"} status
|
||||
*/
|
||||
TE_reportEngineStatus(innerWindowId, status) {
|
||||
if (this.#isDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendAsyncMessage("TranslationsEngine:ReportEngineStatus", {
|
||||
innerWindowId,
|
||||
status,
|
||||
@@ -169,6 +188,10 @@ export class TranslationsEngineChild extends JSProcessActorChild {
|
||||
* No engines are still alive, signal that the process can be destroyed.
|
||||
*/
|
||||
TE_destroyEngineProcess() {
|
||||
if (this.#isDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendAsyncMessage("TranslationsEngine:DestroyEngineProcess");
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
|
||||
/**
|
||||
* @typedef {import("../translations").LanguagePair} LanguagePair
|
||||
* @typedef {import("../translations").TranslationsEnginePayload} TranslationsEnginePayload
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -45,11 +46,15 @@ export class TranslationsEngineParent extends JSProcessActorParent {
|
||||
switch (name) {
|
||||
case "TranslationsEngine:RequestEnginePayload": {
|
||||
const { languagePair } = data;
|
||||
|
||||
/** @type {Promise<TranslationsEnginePayload>} */
|
||||
const payloadPromise =
|
||||
lazy.TranslationsParent.getTranslationsEnginePayload(languagePair);
|
||||
|
||||
payloadPromise.catch(error => {
|
||||
lazy.TranslationsParent.telemetry().onError(String(error));
|
||||
});
|
||||
|
||||
return payloadPromise;
|
||||
}
|
||||
case "TranslationsEngine:ReportEnginePerformance": {
|
||||
|
||||
@@ -210,6 +210,7 @@ const VERIFY_SIGNATURES_FROM_FS = false;
|
||||
* @typedef {import("../translations").TranslationModelRecord} TranslationModelRecord
|
||||
* @typedef {import("../translations").RemoteSettingsClient} RemoteSettingsClient
|
||||
* @typedef {import("../translations").TranslationModelPayload} TranslationModelPayload
|
||||
* @typedef {import("../translations").TranslationsEnginePayload} TranslationsEnginePayload
|
||||
* @typedef {import("../translations").LanguageTranslationModelFiles} LanguageTranslationModelFiles
|
||||
* @typedef {import("../translations").WasmRecord} WasmRecord
|
||||
* @typedef {import("../translations").LangTags} LangTags
|
||||
@@ -1587,7 +1588,11 @@ export class TranslationsParent extends JSWindowActorParent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the payload required to construct the TranslationsEngine for the given language pair.
|
||||
*
|
||||
* @param {LanguagePair} languagePair
|
||||
*
|
||||
* @returns {Promise<TranslationsEnginePayload>}
|
||||
*/
|
||||
static async getTranslationsEnginePayload(languagePair) {
|
||||
const wasmStartTime = Cu.now();
|
||||
|
||||
Reference in New Issue
Block a user