Bug 1348738 - (Part 0) Convert nsRepeatService::gInstance to be a file-scoped StaticRefPtr. r?dholbert draft
authorKuoE0 <kuoe0.tw@gmail.com>
Wed, 29 Mar 2017 11:48:56 +0800
changeset 555982 599d6de4062828530baf5827c0eb37d3e01fac62
parent 555725 b043233ec04f06768d59dcdfb9e928142280f3cc
child 555983 564ded2cb66cccbcb08c9fe95d7438d42b3b6431
push id52390
push userbmo:kuoe0@mozilla.com
push dateWed, 05 Apr 2017 06:40:09 +0000
reviewersdholbert
bugs1348738
milestone55.0a1
Bug 1348738 - (Part 0) Convert nsRepeatService::gInstance to be a file-scoped StaticRefPtr. r?dholbert MozReview-Commit-ID: KSLs2tEFf7m
layout/xul/nsRepeatService.cpp
layout/xul/nsRepeatService.h
--- 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