Bug 1353440 - Part 2: Don't register the annotator until after the HangMonitor has started, r=ehsan
authorMichael Layzell <michael@thelayzells.com>
Thu, 11 May 2017 15:51:12 -0400
changeset 577241 a4c22172c7b692ef2438057063116af3876754d7
parent 577240 854dc4d8321504a6654a8ea2c41cae2a767c7952
child 577242 314678959de293fef3e7b4c7cfd9df0cd574f420
push id58649
push usermaglione.k@gmail.com
push dateSat, 13 May 2017 02:33:34 +0000
reviewersehsan
bugs1353440
milestone55.0a1
Bug 1353440 - Part 2: Don't register the annotator until after the HangMonitor has started, r=ehsan MozReview-Commit-ID: 2QJMRAUQraL
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -10506,20 +10506,23 @@ void
 nsContentUtils::UserInteractionObserver::Init()
 {
   // Listen for the observer messages from EventStateManager which are telling
   // us whether or not the user is interacting.
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->AddObserver(this, kUserInteractionInactive, false);
   obs->AddObserver(this, kUserInteractionActive, false);
 
-  // Register ourselves as an annotator for the Background Hang Reporter, so
-  // that hang stacks are annotated with whether or not the user was
-  // interacting with the browser when the hang occurred.
-  HangMonitor::RegisterAnnotator(*this);
+  // We can't register ourselves as an annotator yet, as the HangMonitor hasn't
+  // started yet. It will have started by the time we have the chance to spin
+  // the event loop.
+  RefPtr<UserInteractionObserver> self = this;
+  NS_DispatchToMainThread(NS_NewRunnableFunction([=] () {
+        HangMonitor::RegisterAnnotator(*self);
+      }));
 }
 
 void
 nsContentUtils::UserInteractionObserver::Shutdown()
 {
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (obs) {
     obs->RemoveObserver(this, kUserInteractionInactive);