Bug 1613531: Eliminate the a11y telemetry thread in favour of background task; r=Jamie

We replace the a11y telemetry thread with a call to the new
`NS_DispatchBackgroundTask` infrastructure. We use `NS_DISPATCH_EVENT_MAY_BLOCK`
because the task performs some I/O to load the instantiator's version info.

I also took the opportunity to eliminate some redundant copying.

Differential Revision: https://phabricator.services.mozilla.com/D61769

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Aaron Klotz 2020-02-06 00:24:26 +00:00
Родитель 38f55cdb70
Коммит e9f01af788
1 изменённых файлов: 14 добавлений и 10 удалений

Просмотреть файл

@ -319,13 +319,15 @@ static void GatherInstantiatorTelemetry(nsIFile* aClientExe) {
AppendVersionInfo(aClientExe, value);
}
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction(
"a11y::AccumulateInstantiatorTelemetry",
[value]() -> void { AccumulateInstantiatorTelemetry(value); }));
nsCOMPtr<nsIRunnable> runnable(
NS_NewRunnableFunction("a11y::AccumulateInstantiatorTelemetry",
[value = std::move(value)]() -> void {
AccumulateInstantiatorTelemetry(value);
}));
// Now that we've (possibly) obtained version info, send the resulting
// string back to the main thread to accumulate in telemetry.
NS_DispatchToMainThread(runnable);
NS_DispatchToMainThread(runnable.forget());
}
#endif // defined(MOZ_TELEMETRY_REPORTING) || defined(MOZ_CRASHREPORTER)
@ -355,13 +357,15 @@ void a11y::SetInstantiator(const uint32_t aPid) {
gInstantiator = clientExe;
#if defined(MOZ_TELEMETRY_REPORTING) || defined(MOZ_CRASHREPORTER)
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction(
"a11y::GatherInstantiatorTelemetry",
[clientExe]() -> void { GatherInstantiatorTelemetry(clientExe); }));
nsCOMPtr<nsIRunnable> runnable(
NS_NewRunnableFunction("a11y::GatherInstantiatorTelemetry",
[clientExe = std::move(clientExe)]() -> void {
GatherInstantiatorTelemetry(clientExe);
}));
nsCOMPtr<nsIThread> telemetryThread;
NS_NewNamedThread("a11y telemetry", getter_AddRefs(telemetryThread),
runnable);
DebugOnly<nsresult> rv =
NS_DispatchBackgroundTask(runnable.forget(), NS_DISPATCH_EVENT_MAY_BLOCK);
MOZ_ASSERT(NS_SUCCEEDED(rv));
#endif // defined(MOZ_TELEMETRY_REPORTING) || defined(MOZ_CRASHREPORTER)
}