Bug 1492894 - part 2 - eliminate already_AddRefed variables in netwerk/; r=valentin
authorNathan Froyd <froydnj@mozilla.com>
Fri, 21 Sep 2018 16:45:49 -0400
changeset 437731 bb0e08fb9530dae213926269ec20495920bd2788
parent 437730 a14c288aec85e9e772dbb5e118a16c16cb95cc83
child 437732 0088198b811d115eaa4957ce8b2c9ecee32a4537
push id108141
push usernfroyd@mozilla.com
push dateFri, 21 Sep 2018 20:46:06 +0000
treeherdermozilla-inbound@b186c6699920 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1492894
milestone64.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 1492894 - part 2 - eliminate already_AddRefed variables in netwerk/; r=valentin We need to disallow these to fix our static analysis, which should have already been disallowing them.
netwerk/base/AutoClose.h
netwerk/protocol/http/HttpChannelParent.cpp
--- a/netwerk/base/AutoClose.h
+++ b/netwerk/base/AutoClose.h
@@ -33,35 +33,31 @@ public:
   already_AddRefed<T> forget()
   {
     MutexAutoLock lock(mMutex);
     return mPtr.forget();
   }
 
   void takeOver(nsCOMPtr<T> & rhs)
   {
-    already_AddRefed<T> other = rhs.forget();
-    TakeOverInternal(&other);
+    TakeOverInternal(rhs.forget());
   }
 
   void CloseAndRelease()
   {
     TakeOverInternal(nullptr);
   }
 
 private:
-  void TakeOverInternal(already_AddRefed<T> *aOther)
+  void TakeOverInternal(already_AddRefed<T>&& aOther)
   {
-    nsCOMPtr<T> ptr;
+    nsCOMPtr<T> ptr(std::move(aOther));
     {
       MutexAutoLock lock(mMutex);
       ptr.swap(mPtr);
-      if (aOther) {
-        mPtr = *aOther;
-      }
     }
 
     if (ptr) {
       ptr->Close();
     }
   }
 
   void operator=(const AutoClose<T> &) = delete;
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -729,20 +729,20 @@ HttpChannelParent::WaitForBgParent()
 
 
   nsCOMPtr<nsIBackgroundChannelRegistrar> registrar =
     do_GetService(NS_BACKGROUNDCHANNELREGISTRAR_CONTRACTID);
   MOZ_ASSERT(registrar);
   registrar->LinkHttpChannel(mChannel->ChannelId(), this);
 
   if (mBgParent) {
-    already_AddRefed<GenericPromise> promise = mPromise.Ensure(__func__);
+    RefPtr<GenericPromise> promise = mPromise.Ensure(__func__);
     // resolve promise immediatedly if bg channel is ready.
     mPromise.Resolve(true, __func__);
-    return promise;
+    return promise.forget();
   }
 
   return mPromise.Ensure(__func__);;
 }
 
 bool
 HttpChannelParent::ConnectChannel(const uint32_t& registrarId, const bool& shouldIntercept)
 {