Bug 1453591 - Add a signal for checking when persisted probes loading completes. r?janerik,chutten,esawin
This patch adds a new topic, for internal use only, which is notified once the
Telemetry core completes loading all the persisted measurements. This will be
useful for applications to have a signal for when is the right time to start
requesting snapshots/clears.
MozReview-Commit-ID: 5tBxV6L1bkh
--- a/toolkit/components/telemetry/geckoview/TelemetryGeckoViewPersistence.cpp
+++ b/toolkit/components/telemetry/geckoview/TelemetryGeckoViewPersistence.cpp
@@ -62,16 +62,21 @@ using PathCharPtr = const PathChar*;
// have very short lived sessions. The persistence timeout governs
// how frequently measurements are saved to disk.
const uint32_t kDefaultPersistenceTimeoutMs = 60 * 1000; // 60s
// The name of the persistence file used for saving the
// measurements.
const char16_t kPersistenceFileName[] = u"gv_measurements.json";
+// This topic is notified and propagated up to the application to
+// make sure it knows that data loading has complete and that snapshotting
+// can now be performed.
+const char kLoadCompleteTopic[] = "internal-telemetry-geckoview-load-complete";
+
// The timer used for persisting measurements data.
nsITimer* gPersistenceTimer;
// The worker thread to perform persistence.
StaticRefPtr<nsIThread> gPersistenceThread;
namespace {
void PersistenceThreadPersist();
@@ -381,16 +386,20 @@ PersistenceThreadLoadData()
NS_NewRunnableFunction("MainThreadArmPersistenceTimer", [fileContent]() -> void {
// Try to parse the probes if the file was not empty.
if (!fileContent.IsEmpty()) {
MainThreadParsePersistedProbes(fileContent);
}
// Arm the timer.
MainThreadArmPersistenceTimer();
// Notify that we're good to take snapshots!
+ nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+ if (os) {
+ os->NotifyObservers(nullptr, kLoadCompleteTopic, nullptr);
+ }
}));
});
// Attempt to load the persistence file. This could fail if we're not able
// to allocate enough memory for the content. See bug 1460911.
nsCOMPtr<nsIFile> persistenceFile;
if (NS_FAILED(GetPersistenceFile(persistenceFile))
|| NS_FAILED(ReadFromFile(persistenceFile, fileContent))) {