Bug 1274881 - Get rid of imgLoader::GetInstance. r=tnikkel
authorJonathan Watt <jwatt@jwatt.org>
Wed, 18 May 2016 10:19:19 +0100
changeset 298719 e866748db4e36ea28cddc9902f6bb3fbcb8af9ea
parent 298718 1ae4cfe35d7157c4c0d3bc1b39224053e5cd84ba
child 298720 303f10857c8e7a7de7fa095fbff7f1291cb6bf6e
push id30285
push usercbook@mozilla.com
push dateWed, 25 May 2016 13:06:07 +0000
treeherdermozilla-central@d6d4e8417d2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1274881
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274881 - Get rid of imgLoader::GetInstance. r=tnikkel
embedding/browser/nsContextMenuInfo.cpp
image/imgLoader.cpp
image/imgLoader.h
widget/cocoa/OSXNotificationCenter.mm
--- a/embedding/browser/nsContextMenuInfo.cpp
+++ b/embedding/browser/nsContextMenuInfo.cpp
@@ -291,17 +291,17 @@ nsContextMenuInfo::GetBackgroundImageReq
       primitiveValue = do_QueryInterface(cssValue);
       if (primitiveValue) {
         primitiveValue->GetStringValue(bgStringValue);
         if (!bgStringValue.EqualsLiteral("none")) {
           nsCOMPtr<nsIURI> bgUri;
           NS_NewURI(getter_AddRefs(bgUri), bgStringValue);
           NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE);
 
-          RefPtr<imgLoader> il = imgLoader::GetInstance();
+          imgLoader* il = imgLoader::Singleton();
           NS_ENSURE_TRUE(il, NS_ERROR_FAILURE);
 
           return il->LoadImage(bgUri, nullptr, nullptr,
                                doc->GetReferrerPolicy(), principal, nullptr,
                                nullptr, nullptr, nullptr, nsIRequest::LOAD_NORMAL,
                                nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE,
                                EmptyString(), aRequest);
         }
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1157,31 +1157,16 @@ imgLoader::PBSingleton()
 
 imgLoader::imgLoader()
 : mUncachedImagesMutex("imgLoader::UncachedImages"), mRespectPrivacy(false)
 {
   sMemReporter->AddRef();
   sMemReporter->RegisterLoader(this);
 }
 
-already_AddRefed<imgLoader>
-imgLoader::GetInstance()
-{
-  static RefPtr<imgLoader> singleton;
-  if (!singleton) {
-    singleton = imgLoader::Create();
-    if (!singleton) {
-        return nullptr;
-    }
-    ClearOnShutdown(&singleton);
-  }
-  RefPtr<imgLoader> loader = singleton.get();
-  return loader.forget();
-}
-
 imgLoader::~imgLoader()
 {
   ClearChromeImageCache();
   ClearImageCache();
   {
     // If there are any of our imgRequest's left they are in the uncached
     // images set, so clear their pointer to us.
     MutexAutoLock lock(mUncachedImagesMutex);
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -262,19 +262,16 @@ public:
       // the image module instead of calling new imgLoader
       // directly.
       nsCOMPtr<imgILoader> loader = do_CreateInstance("@mozilla.org/image/loader;1");
       // There's only one imgLoader implementation so we
       // can safely cast to it.
       return loader.forget().downcast<imgLoader>();
   }
 
-  static already_AddRefed<imgLoader>
-  GetInstance();
-
   nsresult LoadImage(nsIURI* aURI,
                      nsIURI* aInitialDocumentURI,
                      nsIURI* aReferrerURI,
                      ReferrerPolicy aReferrerPolicy,
                      nsIPrincipal* aLoadingPrincipal,
                      nsILoadGroup* aLoadGroup,
                      imgINotificationObserver* aObserver,
                      nsINode* aContext,
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -386,17 +386,18 @@ OSXNotificationCenter::ShowAlertWithIcon
     [GetNotificationCenter() deliverNotification:notification];
     [notification release];
     if (aAlertListener) {
       aAlertListener->Observe(nullptr, "alertshow", cookie.get());
     }
   } else {
     mPendingAlerts.AppendElement(osxni);
     osxni->mPendingNotifiction = notification;
-    RefPtr<imgLoader> il = imgLoader::GetInstance();
+    imgLoader* il =
+      inPrivateBrowsing ? imgLoader::PBSingleton() : imgLoader::Singleton();
     if (il) {
       nsCOMPtr<nsIURI> imageUri;
       NS_NewURI(getter_AddRefs(imageUri), imageUrl);
       if (imageUri) {
         nsCOMPtr<nsIPrincipal> principal;
         rv = aAlert->GetPrincipal(getter_AddRefs(principal));
         if (NS_SUCCEEDED(rv)) {
           rv = il->LoadImage(imageUri, nullptr, nullptr,