Bug 1157803 - Clean up Canonical assigment to avoid accidentally tripping the default operator= implementation. r=jww
authorBobby Holley <bobbyholley@gmail.com>
Tue, 28 Apr 2015 16:56:07 -0700
changeset 241531 3eee65370b2babc3234b267c86a03a8d9e8df26a
parent 241530 cd9eec88aa05c33f7f4d18fdc4206a5cff188d14
child 241532 5b8e33d6ad7123b4e90a134c4e9409bb2a6ae18b
push id28665
push userkwierso@gmail.com
push dateWed, 29 Apr 2015 23:43:43 +0000
treeherdermozilla-central@a86ed85747d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjww
bugs1157803
milestone40.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 1157803 - Clean up Canonical assigment to avoid accidentally tripping the default operator= implementation. r=jww
dom/media/StateMirroring.h
--- a/dom/media/StateMirroring.h
+++ b/dom/media/StateMirroring.h
@@ -150,22 +150,22 @@ public:
   }
 
   operator const T&()
   {
     MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
     return mValue;
   }
 
-  Canonical& operator=(const T& aNewValue)
+  void Set(const T& aNewValue)
   {
     MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
 
     if (aNewValue == mValue) {
-      return *this;
+      return;
     }
 
     // Notify same-thread watchers. The state watching machinery will make sure
     // that notifications run at the right time.
     NotifyWatchers();
 
     // Check if we've already got a pending update. If so we won't schedule another
     // one.
@@ -179,19 +179,21 @@ public:
 
     // We wait until things have stablized before sending state updates so that
     // we can avoid sending multiple updates, and possibly avoid sending any
     // updates at all if the value ends up where it started.
     if (!alreadyNotifying) {
       nsCOMPtr<nsIRunnable> r = NS_NewRunnableMethod(this, &Canonical::DoNotify);
       AbstractThread::GetCurrent()->TailDispatcher().AddDirectTask(r.forget());
     }
+  }
 
-    return *this;
-  }
+  Canonical& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
+  Canonical& operator=(const Canonical& aOther) { Set(aOther); return *this; }
+  Canonical(const Canonical& aOther) = delete;
 
   class Holder
   {
   public:
     Holder() {}
     ~Holder() { MOZ_DIAGNOSTIC_ASSERT(mCanonical, "Should have initialized me"); }
 
     // NB: Because mirror-initiated disconnection can race with canonical-
@@ -206,17 +208,20 @@ public:
 
     // Access to the Canonical<T>.
     operator Canonical<T>&() { return *mCanonical; }
     Canonical<T>* operator&() { return mCanonical; }
 
     // Access to the T.
     const T& Ref() const { return *mCanonical; }
     operator const T&() const { return Ref(); }
-    Holder& operator=(const T& aNewValue) { *mCanonical = aNewValue; return *this; }
+    void Set(const T& aNewValue) { mCanonical->Set(aNewValue); }
+    Holder& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
+    Holder& operator=(const Holder& aOther) { Set(aOther); return *this; }
+    Holder(const Holder& aOther) = delete;
 
   private:
     nsRefPtr<Canonical<T>> mCanonical;
   };
 
 protected:
   ~Canonical() { MOZ_DIAGNOSTIC_ASSERT(mMirrors.IsEmpty()); }