bug 1314818 - Revert "bug 1304660 - Don't dispatch to main once xpcom starts shutting down." r=froydnj
authorChris H-C <chutten@mozilla.com>
Tue, 08 Nov 2016 14:18:31 -0500
changeset 351872 0e9e97d11bbb81e0f576e4e92927500831e1d650
parent 351871 c06f9e99eeb80b4695f0b44b6e2e6675b272bd00
child 351873 fcd1172e075a043e2ea47122cacece0299b9b2c8
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1314818, 1304660
milestone52.0a1
bug 1314818 - Revert "bug 1304660 - Don't dispatch to main once xpcom starts shutting down." r=froydnj This didn't quite work, as we still managed to try to dispatch during shutdown. MozReview-Commit-ID: lnWoCrJUtu
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -198,19 +198,16 @@ base::StatisticsRecorder* gStatisticsRec
 
 // For batching and sending child process accumulations to the parent
 nsITimer* gIPCTimer = nullptr;
 mozilla::Atomic<bool, mozilla::Relaxed> gIPCTimerArmed(false);
 mozilla::Atomic<bool, mozilla::Relaxed> gIPCTimerArming(false);
 StaticAutoPtr<nsTArray<Accumulation>> gAccumulations;
 StaticAutoPtr<nsTArray<KeyedAccumulation>> gKeyedAccumulations;
 
-// Has XPCOM started shutting down?
-mozilla::Atomic<bool, mozilla::Relaxed>  gShuttingDown(false);
-
 } // namespace
 
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 //
 // PRIVATE CONSTANTS
 
@@ -338,36 +335,25 @@ HistogramInfo::label_id(const char* labe
       *labelId = i;
       return NS_OK;
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
-struct TelemetryShutdownObserver : public nsIObserver
+bool
+StringEndsWith(const std::string& name, const std::string& suffix)
 {
-  NS_DECL_ISUPPORTS
-
-  NS_IMETHOD Observe(nsISupports*, const char* aTopic, const char16_t*) override
-  {
-    if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) != 0) {
-      return NS_OK;
-    }
-    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-    if (obs) {
-      obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
-    }
-    gShuttingDown = true;
-    return NS_OK;
+  if (name.size() < suffix.size()) {
+    return false;
   }
-private:
-  virtual ~TelemetryShutdownObserver() { }
-};
-NS_IMPL_ISUPPORTS(TelemetryShutdownObserver, nsIObserver)
+
+  return name.compare(name.size() - suffix.size(), suffix.size(), suffix) == 0;
+}
 
 } // namespace
 
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
 //
 // PRIVATE: Histogram Get, Add, Clone, Clear functions
@@ -1363,17 +1349,17 @@ void internal_armIPCTimerMainThread()
 void internal_armIPCTimer()
 {
   if (gIPCTimerArmed || gIPCTimerArming) {
     return;
   }
   gIPCTimerArming = true;
   if (NS_IsMainThread()) {
     internal_armIPCTimerMainThread();
-  } else if (!gShuttingDown) {
+  } else {
     NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
       StaticMutexAutoLock locker(gTelemetryHistogramMutex);
       internal_armIPCTimerMainThread();
     }));
   }
 }
 
 bool
@@ -2117,20 +2103,16 @@ void TelemetryHistogram::InitializeGloba
       "and update the n_values for the following in Histograms.json: "
       "GC_MINOR_REASON, GC_MINOR_REASON_LONG, GC_REASON_2");
   static_assert((mozilla::StartupTimeline::MAX_EVENT_ID == 16),
       "MAX_EVENT_ID is assumed to be a fixed value in Histograms.json.  If this"
       " was an intentional change, update this assert with its value and update"
       " the n_values for the following in Histograms.json:"
       " STARTUP_MEASUREMENT_ERRORS");
 
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-  MOZ_ASSERT(obs);
-  obs->AddObserver(new TelemetryShutdownObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
-
   gInitDone = true;
 }
 
 void TelemetryHistogram::DeInitializeGlobalState()
 {
   StaticMutexAutoLock locker(gTelemetryHistogramMutex);
   gCanRecordBase = false;
   gCanRecordExtended = false;