Bug 1453591 - Add a signal for checking when persisted probes loading completes. r?janerik,chutten,esawin draft
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Thu, 26 Apr 2018 14:32:42 +0200
changeset 795175 eda708bacfd34f10d166b79cc702bb515d3feeb4
parent 795174 466da9e172e654f6b5d43d1ed5d8968c87c8ef04
child 795176 65683ae851faa4532bf313d75c88053fe13876c5
push id109885
push userbmo:alessio.placitelli@gmail.com
push dateTue, 15 May 2018 07:22:25 +0000
reviewersjanerik, chutten, esawin
bugs1453591
milestone62.0a1
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
toolkit/components/telemetry/geckoview/TelemetryGeckoViewPersistence.cpp
--- 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))) {