Bug 1208371 - Make PeerIdentity RefCounted. r?mt draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:28 +0800
changeset 342139 4b9a4373acb815d82e937e59d7145d8af0ca8473
parent 342138 70d95aa7d8a177cdb8b969d04cd276bb6e9e0e17
child 342140 78176849b556837d945b61ae63fdbbea088d1aea
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersmt
bugs1208371
milestone47.0a1
Bug 1208371 - Make PeerIdentity RefCounted. r?mt This so it can be shared between multiple tracks. MozReview-Commit-ID: 3mjQImVY0f8
dom/media/DOMMediaStream.h
dom/media/MediaManager.cpp
dom/media/webrtc/PeerIdentity.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
--- a/dom/media/DOMMediaStream.h
+++ b/dom/media/DOMMediaStream.h
@@ -687,17 +687,17 @@ private:
   // If null, this stream can be used by anyone because it has no content yet.
   nsCOMPtr<nsIPrincipal> mPrincipal;
   // Video principal is used by video element as access is requested to its
   // image data.
   nsCOMPtr<nsIPrincipal> mVideoPrincipal;
   nsTArray<dom::PrincipalChangeObserver<DOMMediaStream>*> mPrincipalChangeObservers;
   // this is used in gUM and WebRTC to identify peers that this stream
   // is allowed to be sent to
-  nsAutoPtr<PeerIdentity> mPeerIdentity;
+  RefPtr<PeerIdentity> mPeerIdentity;
   CORSMode mCORSMode;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(DOMMediaStream,
                               NS_DOMMEDIASTREAM_IID)
 
 #define NS_DOMLOCALMEDIASTREAM_IID \
 { 0xb1437260, 0xec61, 0x4dfa, \
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -864,17 +864,17 @@ public:
 
       // Normal case, connect the source stream to the track union stream to
       // avoid us blocking. Pass a null TrackSourceGetter since gUM should never
       // add tracks dynamically.
       domStream =
         DOMLocalMediaStream::CreateSourceStream(window, msg, nullptr);
 
       if (mPeerIdentity) {
-        domStream->SetPeerIdentity(mPeerIdentity.forget());
+        domStream->SetPeerIdentity(mPeerIdentity);
       }
 
       if (mAudioDevice) {
         nsString audioDeviceName;
         mAudioDevice->GetName(audioDeviceName);
         const MediaSourceEnum source =
           mAudioDevice->GetSource()->GetMediaSource();
         RefPtr<MediaStreamTrackSource> audioSource =
@@ -943,17 +943,17 @@ public:
 private:
   nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
   nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
   RefPtr<AudioDevice> mAudioDevice;
   RefPtr<VideoDevice> mVideoDevice;
   uint64_t mWindowID;
   RefPtr<GetUserMediaCallbackMediaStreamListener> mListener;
   nsCString mOrigin;
-  nsAutoPtr<PeerIdentity> mPeerIdentity;
+  RefPtr<PeerIdentity> mPeerIdentity;
   RefPtr<MediaManager> mManager; // get ref to this when creating the runnable
 };
 
 static bool
 IsOn(const OwningBooleanOrMediaTrackConstraints &aUnion) {
   return !aUnion.IsBoolean() || aUnion.GetAsBoolean();
 }
 
--- a/dom/media/webrtc/PeerIdentity.h
+++ b/dom/media/webrtc/PeerIdentity.h
@@ -22,19 +22,21 @@ namespace mozilla {
  * This class implements the identifier used in WebRTC identity.  Peers are
  * identified using a string in the form [<user>@]<domain>, for instance,
  * "user@example.com'. The (optional) user portion is a site-controlled string
  * containing any character other than '@'.  The domain portion is a valid IDN
  * domain name and is compared accordingly.
  *
  * See: http://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-09#section-5.6.5.3.3.1
  */
-class PeerIdentity final
+class PeerIdentity final : public RefCounted<PeerIdentity>
 {
 public:
+  MOZ_DECLARE_REFCOUNTED_TYPENAME(PeerIdentity)
+
   explicit PeerIdentity(const nsAString& aPeerIdentity)
     : mPeerIdentity(aPeerIdentity) {}
   ~PeerIdentity() {}
 
   bool Equals(const PeerIdentity& aOther) const;
   bool Equals(const nsAString& aOtherString) const;
   const nsString& ToString() const { return mPeerIdentity; }
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -767,17 +767,17 @@ private:
   // DTLS fingerprint
   std::string mFingerprint;
   std::string mRemoteFingerprint;
 
   // identity-related fields
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   // The entity on the other end of the peer-to-peer connection;
   // void if they are not yet identified, and no identity setting has been set
-  nsAutoPtr<PeerIdentity> mPeerIdentity;
+  RefPtr<PeerIdentity> mPeerIdentity;
   // The certificate we are using.
   RefPtr<mozilla::dom::RTCCertificate> mCertificate;
 #else
   RefPtr<DtlsIdentity> mIdentity;
 #endif
   // Whether an app should be prevented from accessing media produced by the PC
   // If this is true, then media will not be sent until mPeerIdentity matches
   // local streams PeerIdentity; and remote streams are protected from content