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 794660 2e9be520d3ab4f85e336c67dd886d19e84340a3e
parent 794659 11655d3e0e2f57fc7b9d90e1cdb9764311bcb986
child 794661 832001ea759fcaeea8d9071d2cc68f3c2ccedcad
push id109751
push userbmo:alessio.placitelli@gmail.com
push dateMon, 14 May 2018 09:26:57 +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();
@@ -379,16 +384,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))) {