From 6d8e5c2488a8661d57bcd2c51b30b1d7ce6c802b Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Thu, 9 Apr 2015 15:41:53 -0500 Subject: [PATCH] Bug 1100501 - Avoid a late shutdown of chromium's StatisticsRecorder. r=georg --- toolkit/components/telemetry/Telemetry.cpp | 3 -- toolkit/xre/nsAppRunner.cpp | 35 +++++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index 7f58930cf0a..c134045bf63 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -823,9 +823,6 @@ private: const uint32_t mBucketCount; }; -// A initializer to initialize histogram collection -StatisticsRecorder gStatisticsRecorder; - // Hardcoded probes struct TelemetryHistogram { uint32_t min; diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 536f1385314..614831fdf9b 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -86,6 +86,8 @@ #include "mozilla/scache/StartupCache.h" #include "nsIGfxInfo.h" +#include "base/histogram.h" + #include "mozilla/unused.h" #ifdef XP_WIN @@ -2929,9 +2931,7 @@ class XREMain { public: XREMain() : - mScopedXPCOM(nullptr) - , mAppData(nullptr) - , mStartOffline(false) + mStartOffline(false) , mShuttingDown(false) #ifdef MOZ_ENABLE_XREMOTE , mDisableRemote(false) @@ -2942,13 +2942,9 @@ public: {}; ~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); @@ -2965,8 +2961,10 @@ public: nsCOMPtr mRemoteService; #endif - ScopedXPCOMStartup* mScopedXPCOM; - ScopedAppData* mAppData; + UniquePtr mScopedXPCOM; + UniquePtr mStatisticsRecorder; + nsAutoPtr mAppData; + nsXREDirProvider mDirProvider; nsAutoCString mProfileName; nsAutoCString mDesktopStartupID; @@ -3085,7 +3083,7 @@ XREMain::XRE_mainInit(bool* aExitFlag) 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; @@ -4201,6 +4199,10 @@ XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_ENSURE_TRUE(aAppData, 2); + // A initializer to initialize histogram collection, a chromium + // thing used by Telemetry. + mStatisticsRecorder = MakeUnique(); + mAppData = new ScopedAppData(aAppData); if (!mAppData) return 1; @@ -4238,7 +4240,7 @@ XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) bool appInitiatedRestart = false; // Start the real application - mScopedXPCOM = new ScopedXPCOMStartup(); + mScopedXPCOM = MakeUnique(); if (!mScopedXPCOM) return 1; @@ -4273,8 +4275,8 @@ XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) #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 @@ -4352,7 +4354,7 @@ XRE_metroStartup(bool runXREMain) return NS_ERROR_FAILURE; // Start the real application - xreMainPtr->mScopedXPCOM = new ScopedXPCOMStartup(); + xreMainPtr->mScopedXPCOM = MakeUnique(); if (!xreMainPtr->mScopedXPCOM) return NS_ERROR_FAILURE; @@ -4369,7 +4371,6 @@ XRE_metroStartup(bool runXREMain) void XRE_metroShutdown() { - delete xreMainPtr->mScopedXPCOM; xreMainPtr->mScopedXPCOM = nullptr; #ifdef MOZ_INSTRUMENT_EVENT_LOOP