Bug 1100501 - Avoid a late shutdown of chromium's StatisticsRecorder. r=georg, a=sledru
authorJim Mathies <jmathies@mozilla.com>
Sat, 11 Apr 2015 07:02:07 -0500
changeset 260236 8661ed4cbdb9
parent 260235 71d1d59db847
child 260237 a6fe316e7571
push id724
push userryanvm@gmail.com
push date2015-04-23 01:08 +0000
treeherdermozilla-release@db41e8e267ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeorg, sledru
bugs1100501
milestone38.0
Bug 1100501 - Avoid a late shutdown of chromium's StatisticsRecorder. r=georg, a=sledru
toolkit/components/telemetry/Telemetry.cpp
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -802,19 +802,16 @@ private:
   const nsCString mName;
   const nsCString mExpiration;
   const uint32_t mHistogramType;
   const uint32_t mMin;
   const uint32_t mMax;
   const uint32_t mBucketCount;
 };
 
-// A initializer to initialize histogram collection
-StatisticsRecorder gStatisticsRecorder;
-
 // Hardcoded probes
 struct TelemetryHistogram {
   uint32_t min;
   uint32_t max;
   uint32_t bucketCount;
   uint32_t histogramType;
   uint32_t id_offset;
   uint32_t expiration_offset;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -80,16 +80,18 @@
 #include "nsPIDOMWindow.h"
 #include "nsIBaseWindow.h"
 #include "nsIWidget.h"
 #include "nsIDocShell.h"
 #include "nsAppShellCID.h"
 #include "mozilla/scache/StartupCache.h"
 #include "nsIGfxInfo.h"
 
+#include "base/histogram.h"
+
 #include "mozilla/unused.h"
 
 #ifdef XP_WIN
 #include "nsIWinAppHelper.h"
 #include <windows.h>
 #include "cairo/cairo-features.h"
 #include "mozilla/WindowsVersion.h"
 #ifdef MOZ_METRO
@@ -2985,54 +2987,50 @@ SetLastWinRunType(AHE_TYPE aType)
 
 #include "GeckoProfiler.h"
 
 // Encapsulates startup and shutdown state for XRE_main
 class XREMain
 {
 public:
   XREMain() :
-    mScopedXPCOM(nullptr)
-    , mAppData(nullptr)
-    , mStartOffline(false)
+    mStartOffline(false)
     , mShuttingDown(false)
 #ifdef MOZ_ENABLE_XREMOTE
     , mDisableRemote(false)
 #endif
 #if defined(MOZ_WIDGET_GTK)
     , mGdkDisplay(nullptr)
 #endif
   {};
 
   ~XREMain() {
-    if (mAppData) {
-      delete mAppData;
-    }
-    if (mScopedXPCOM) {
-      NS_WARNING("Scoped xpcom should have been deleted!");
-      delete mScopedXPCOM;
-    }
+    mScopedXPCOM = nullptr;
+    mStatisticsRecorder = nullptr;
+    mAppData = nullptr;
   }
 
   int XRE_main(int argc, char* argv[], const nsXREAppData* aAppData);
   int XRE_mainInit(bool* aExitFlag);
   int XRE_mainStartup(bool* aExitFlag);
   nsresult XRE_mainRun();
   
   nsCOMPtr<nsINativeAppSupport> mNativeApp;
   nsCOMPtr<nsIToolkitProfileService> mProfileSvc;
   nsCOMPtr<nsIFile> mProfD;
   nsCOMPtr<nsIFile> mProfLD;
   nsCOMPtr<nsIProfileLock> mProfileLock;
 #ifdef MOZ_ENABLE_XREMOTE
   nsCOMPtr<nsIRemoteService> mRemoteService;
 #endif
 
-  ScopedXPCOMStartup* mScopedXPCOM;
-  ScopedAppData* mAppData;
+  UniquePtr<ScopedXPCOMStartup> mScopedXPCOM;
+  UniquePtr<base::StatisticsRecorder> mStatisticsRecorder;
+  nsAutoPtr<mozilla::ScopedAppData> mAppData;
+
   nsXREDirProvider mDirProvider;
   nsAutoCString mProfileName;
   nsAutoCString mDesktopStartupID;
 
   bool mStartOffline;
   bool mShuttingDown;
 #ifdef MOZ_ENABLE_XREMOTE
   bool mDisableRemote;
@@ -3141,17 +3139,17 @@ XREMain::XRE_mainInit(bool* aExitFlag)
   else if (ar == ARG_FOUND) {
     nsCOMPtr<nsIFile> overrideLF;
     rv = XRE_GetFileFromPath(override, getter_AddRefs(overrideLF));
     if (NS_FAILED(rv)) {
       Output(true, "Error: unrecognized override.ini path.\n");
       return 1;
     }
 
-    rv = XRE_ParseAppData(overrideLF, mAppData);
+    rv = XRE_ParseAppData(overrideLF, mAppData.get());
     if (NS_FAILED(rv)) {
       Output(true, "Couldn't read override.ini");
       return 1;
     }
   }
 
   // Check sanity and correctness of app data.
 
@@ -4253,16 +4251,20 @@ XREMain::XRE_main(int argc, char* argv[]
 
   nsresult rv = NS_OK;
 
   gArgc = argc;
   gArgv = argv;
 
   NS_ENSURE_TRUE(aAppData, 2);
 
+  // A initializer to initialize histogram collection, a chromium
+  // thing used by Telemetry.
+  mStatisticsRecorder = MakeUnique<base::StatisticsRecorder>();
+
   mAppData = new ScopedAppData(aAppData);
   if (!mAppData)
     return 1;
   if (!mAppData->remotingName) {
     SetAllocatedString(mAppData->remotingName, mAppData->name);
   }
   // used throughout this file
   gAppData = mAppData;
@@ -4290,17 +4292,17 @@ XREMain::XRE_main(int argc, char* argv[]
   // startup
   result = XRE_mainStartup(&exit);
   if (result != 0 || exit)
     return result;
 
   bool appInitiatedRestart = false;
 
   // Start the real application
-  mScopedXPCOM = new ScopedXPCOMStartup();
+  mScopedXPCOM = MakeUnique<ScopedXPCOMStartup>();
   if (!mScopedXPCOM)
     return 1;
 
   rv = mScopedXPCOM->Initialize();
   NS_ENSURE_SUCCESS(rv, 1);
 
   // run!
   rv = XRE_mainRun();
@@ -4325,18 +4327,18 @@ XREMain::XRE_main(int argc, char* argv[]
 #ifdef MOZ_ENABLE_XREMOTE
     // shut down the x remote proxy window
     if (mRemoteService) {
       mRemoteService->Shutdown();
     }
 #endif /* MOZ_ENABLE_XREMOTE */
   }
 
-  delete mScopedXPCOM;
   mScopedXPCOM = nullptr;
+  mStatisticsRecorder = nullptr;
 
   // unlock the profile after ScopedXPCOMStartup object (xpcom) 
   // has gone out of scope.  see bug #386739 for more details
   mProfileLock->Unlock();
   gProfileLock = nullptr;
 
 #if defined(MOZ_WIDGET_QT)
   nsQAppInstance::Release();
@@ -4404,34 +4406,33 @@ XRE_metroStartup(bool runXREMain)
   // the main thread. (see bug 1033358)
   ScopedLogging log;
 
   bool exit = false;
   if (xreMainPtr->XRE_mainStartup(&exit) != 0 || exit)
     return NS_ERROR_FAILURE;
 
   // Start the real application
-  xreMainPtr->mScopedXPCOM = new ScopedXPCOMStartup();
+  xreMainPtr->mScopedXPCOM = MakeUnique<ScopedXPCOMStartup>();
   if (!xreMainPtr->mScopedXPCOM)
     return NS_ERROR_FAILURE;
 
   rv = xreMainPtr->mScopedXPCOM->Initialize();
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (runXREMain) {
     rv = xreMainPtr->XRE_mainRun();
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 void
 XRE_metroShutdown()
 {
-  delete xreMainPtr->mScopedXPCOM;
   xreMainPtr->mScopedXPCOM = nullptr;
 
 #ifdef MOZ_INSTRUMENT_EVENT_LOOP
   mozilla::ShutdownEventTracing();
 #endif
 
   // unlock the profile after ScopedXPCOMStartup object (xpcom) 
   // has gone out of scope.  see bug #386739 for more details