Bug 1348738 - (Part 0) Convert nsRepeatService::gInstance to be a file-scoped StaticRefPtr. r?dholbert
MozReview-Commit-ID: KSLs2tEFf7m
--- a/layout/xul/nsRepeatService.cpp
+++ b/layout/xul/nsRepeatService.cpp
@@ -8,42 +8,43 @@
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsRepeatService.h"
#include "nsIServiceManager.h"
-nsRepeatService* nsRepeatService::gInstance = nullptr;
+using namespace mozilla;
+
+static StaticRefPtr<nsRepeatService> gRepeatService;
nsRepeatService::nsRepeatService()
: mCallback(nullptr), mCallbackData(nullptr)
{
}
nsRepeatService::~nsRepeatService()
{
NS_ASSERTION(!mCallback && !mCallbackData, "Callback was not removed before shutdown");
}
-nsRepeatService*
+/* static */ nsRepeatService*
nsRepeatService::GetInstance()
{
- if (!gInstance) {
- gInstance = new nsRepeatService();
- NS_IF_ADDREF(gInstance);
+ if (!gRepeatService) {
+ gRepeatService = new nsRepeatService();
}
- return gInstance;
+ return gRepeatService;
}
/*static*/ void
nsRepeatService::Shutdown()
{
- NS_IF_RELEASE(gInstance);
+ gRepeatService = nullptr;
}
void nsRepeatService::Start(Callback aCallback, void* aCallbackData,
uint32_t aInitialDelay)
{
NS_PRECONDITION(aCallback != nullptr, "null ptr");
mCallback = aCallback;
--- a/layout/xul/nsRepeatService.h
+++ b/layout/xul/nsRepeatService.h
@@ -48,13 +48,12 @@ public:
protected:
nsRepeatService();
virtual ~nsRepeatService();
private:
Callback mCallback;
void* mCallbackData;
nsCOMPtr<nsITimer> mRepeatTimer;
- static nsRepeatService* gInstance;
}; // class nsRepeatService
#endif