Bug 1337358 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in media/webrtc/signaling/ r?=jesup draft
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 07 Feb 2017 14:12:10 +0100
changeset 479856 b4dd94fc69cd74f6be26847b34d6c0c5b839d272
parent 479651 af8a2573d0f1e9cc6f2ba0ab67d7a702a197f177
child 479857 fdc56e589a4e3aaf33d8cf01a86f4aae09b4eeb9
push id44391
push userbmo:sledru@mozilla.com
push dateTue, 07 Feb 2017 13:22:28 +0000
bugs1337358
milestone54.0a1
Bug 1337358 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in media/webrtc/signaling/ r?=jesup MozReview-Commit-ID: 7VFZqMB9B3s
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
media/webrtc/signaling/test/signaling_unittests.cpp
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -1806,18 +1806,18 @@ JsepSessionImpl::SetRemoteDescriptionAns
   SetState(kJsepStateStable);
   return NS_OK;
 }
 
 nsresult
 JsepSessionImpl::SetRemoteTracksFromDescription(const Sdp* remoteDescription)
 {
   // Unassign all remote tracks
-  for (auto i = mRemoteTracks.begin(); i != mRemoteTracks.end(); ++i) {
-    i->mAssignedMLine.reset();
+  for (auto & mRemoteTrack : mRemoteTracks) {
+    mRemoteTrack.mAssignedMLine.reset();
   }
 
   // This will not exist if we're rolling back the first remote description
   if (remoteDescription) {
     size_t numMlines = remoteDescription->GetMediaSectionCount();
     nsresult rv;
 
     // Iterate over the sdp, re-assigning or creating remote tracks as we go
@@ -2087,19 +2087,18 @@ JsepSessionImpl::CreateGenericSDP(Unique
 
   if (mDtlsFingerprints.empty()) {
     JSEP_SET_ERROR("Missing DTLS fingerprint");
     return NS_ERROR_FAILURE;
   }
 
   UniquePtr<SdpFingerprintAttributeList> fpl =
       MakeUnique<SdpFingerprintAttributeList>();
-  for (auto fp = mDtlsFingerprints.begin(); fp != mDtlsFingerprints.end();
-       ++fp) {
-    fpl->PushEntry(fp->mAlgorithm, fp->mValue);
+  for (auto & mDtlsFingerprint : mDtlsFingerprints) {
+    fpl->PushEntry(mDtlsFingerprint.mAlgorithm, mDtlsFingerprint.mValue);
   }
   sdp->GetAttributeList().SetAttribute(fpl.release());
 
   auto* iceOpts = new SdpOptionsAttribute(SdpAttribute::kIceOptionsAttribute);
   iceOpts->PushEntry("trickle");
   sdp->GetAttributeList().SetAttribute(iceOpts);
 
   // This assumes content doesn't add a bunch of msid attributes with a
@@ -2538,18 +2537,18 @@ const std::string
 JsepSessionImpl::GetLastError() const
 {
   return mLastError;
 }
 
 bool
 JsepSessionImpl::AllLocalTracksAreAssigned() const
 {
-  for (auto i = mLocalTracks.begin(); i != mLocalTracks.end(); ++i) {
-    if (!i->mAssignedMLine.isSome()) {
+  for (const auto & mLocalTrack : mLocalTracks) {
+    if (!mLocalTrack.mAssignedMLine.isSome()) {
       return false;
     }
   }
 
   return true;
 }
 
 } // namespace mozilla
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -64,19 +64,19 @@ RefPtr<AudioSessionConduit> AudioSession
 /**
  * Destruction defines for our super-classes
  */
 WebrtcAudioConduit::~WebrtcAudioConduit()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   CSFLogDebug(logTag,  "%s ", __FUNCTION__);
-  for(std::vector<AudioCodecConfig*>::size_type i=0;i < mRecvCodecList.size();i++)
+  for(auto & codec : mRecvCodecList)
   {
-    delete mRecvCodecList[i];
+    delete codec;
   }
 
   // The first one of a pair to be deleted shuts down media for both
   if(mPtrVoEXmedia)
   {
     mPtrVoEXmedia->SetExternalRecordingStatus(false);
     mPtrVoEXmedia->SetExternalPlayoutStatus(false);
   }
@@ -511,41 +511,41 @@ WebrtcAudioConduit::ConfigureRecvMediaCo
   {
     CSFLogError(logTag, "%s Zero number of codecs to configure", __FUNCTION__);
     return kMediaConduitMalformedArgument;
   }
 
   // Try Applying the codecs in the list.
   // We succeed if at least one codec was applied and reception was
   // started successfully.
-  for(std::vector<AudioCodecConfig*>::size_type i=0 ;i<codecConfigList.size();i++)
+  for(auto codec : codecConfigList)
   {
     //if the codec param is invalid or diplicate, return error
-    if((condError = ValidateCodecConfig(codecConfigList[i],false)) != kMediaConduitNoError)
+    if((condError = ValidateCodecConfig(codec,false)) != kMediaConduitNoError)
     {
       return condError;
     }
 
     webrtc::CodecInst cinst;
-    if(!CodecConfigToWebRTCCodec(codecConfigList[i],cinst))
+    if(!CodecConfigToWebRTCCodec(codec,cinst))
     {
       CSFLogError(logTag,"%s CodecConfig to WebRTC Codec Failed ",__FUNCTION__);
       continue;
     }
 
     if(mPtrVoECodec->SetRecPayloadType(mChannel,cinst) == -1)
     {
       error = mPtrVoEBase->LastError();
       CSFLogError(logTag,  "%s SetRecvCodec Failed %d ",__FUNCTION__, error);
       continue;
     } else {
       CSFLogDebug(logTag, "%s Successfully Set RecvCodec %s", __FUNCTION__,
-                                          codecConfigList[i]->mName.c_str());
+                                          codec->mName.c_str());
       //copy this to local database
-      if(CopyCodecToDB(codecConfigList[i]))
+      if(CopyCodecToDB(codec))
       {
         success = true;
       } else {
         CSFLogError(logTag,"%s Unable to updated Codec Database", __FUNCTION__);
         return kMediaConduitUnknownError;
       }
 
     }
@@ -1069,19 +1069,19 @@ WebrtcAudioConduit::CheckCodecsForMatch(
 
 /**
  * Checks if the codec is already in Conduit's database
  */
 bool
 WebrtcAudioConduit::CheckCodecForMatch(const AudioCodecConfig* codecInfo) const
 {
   //the db should have atleast one codec
-  for(std::vector<AudioCodecConfig*>::size_type i=0;i < mRecvCodecList.size();i++)
+  for(auto codec : mRecvCodecList)
   {
-    if(CheckCodecsForMatch(mRecvCodecList[i],codecInfo))
+    if(CheckCodecsForMatch(codec,codecInfo))
     {
       //match
       return true;
     }
   }
   //no match or empty local db
   return false;
 }
@@ -1132,19 +1132,19 @@ WebrtcAudioConduit::ValidateCodecConfig(
     CSFLogDebug(logTag, "%s Codec %s Already Applied  ", __FUNCTION__, codecInfo->mName.c_str());
   }
   return kMediaConduitNoError;
 }
 
 void
 WebrtcAudioConduit::DumpCodecDB() const
  {
-    for(std::vector<AudioCodecConfig*>::size_type i=0;i < mRecvCodecList.size();i++)
+    for(auto codec : mRecvCodecList)
     {
-      CSFLogDebug(logTag,"Payload Name: %s", mRecvCodecList[i]->mName.c_str());
-      CSFLogDebug(logTag,"Payload Type: %d", mRecvCodecList[i]->mType);
-      CSFLogDebug(logTag,"Payload Frequency: %d", mRecvCodecList[i]->mFreq);
-      CSFLogDebug(logTag,"Payload PacketSize: %d", mRecvCodecList[i]->mPacSize);
-      CSFLogDebug(logTag,"Payload Channels: %d", mRecvCodecList[i]->mChannels);
-      CSFLogDebug(logTag,"Payload Sampling Rate: %d", mRecvCodecList[i]->mRate);
+      CSFLogDebug(logTag,"Payload Name: %s", codec->mName.c_str());
+      CSFLogDebug(logTag,"Payload Type: %d", codec->mType);
+      CSFLogDebug(logTag,"Payload Frequency: %d", codec->mFreq);
+      CSFLogDebug(logTag,"Payload PacketSize: %d", codec->mPacSize);
+      CSFLogDebug(logTag,"Payload Channels: %d", codec->mChannels);
+      CSFLogDebug(logTag,"Payload Sampling Rate: %d", codec->mRate);
     }
  }
 }// end namespace
--- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
@@ -186,19 +186,18 @@ FinalizeTransportFlow_s(RefPtr<PeerConne
 {
   TransportLayerIce* ice =
       static_cast<TransportLayerIce*>(aLayerList->values.front());
   ice->SetParameters(aPCMedia->ice_ctx(),
                      aPCMedia->ice_media_stream(aLevel),
                      aIsRtcp ? 2 : 1);
   nsAutoPtr<std::queue<TransportLayer*> > layerQueue(
       new std::queue<TransportLayer*>);
-  for (auto i = aLayerList->values.begin(); i != aLayerList->values.end();
-       ++i) {
-    layerQueue->push(*i);
+  for (auto & value : aLayerList->values) {
+    layerQueue->push(value);
   }
   aLayerList->values.clear();
   (void)aFlow->PushLayers(layerQueue); // TODO(bug 854518): Process errors.
 }
 
 static void
 AddNewIceStreamForRestart_s(RefPtr<PeerConnectionMedia> aPCMedia,
                             RefPtr<TransportFlow> aFlow,
@@ -260,23 +259,21 @@ MediaPipelineFactory::CreateOrGetTranspo
   if (!pcid) {
     MOZ_MTLOG(ML_ERROR, "Failed to get DTLS identity.");
     return NS_ERROR_FAILURE;
   }
   dtls->SetIdentity(pcid);
 
   const SdpFingerprintAttributeList& fingerprints =
       aTransport.mDtls->GetFingerprints();
-  for (auto fp = fingerprints.mFingerprints.begin();
-       fp != fingerprints.mFingerprints.end();
-       ++fp) {
+  for (const auto & mFingerprint : fingerprints.mFingerprints) {
     std::ostringstream ss;
-    ss << fp->hashFunc;
-    rv = dtls->SetVerificationDigest(ss.str(), &fp->fingerprint[0],
-                                     fp->fingerprint.size());
+    ss << mFingerprint.hashFunc;
+    rv = dtls->SetVerificationDigest(ss.str(), &mFingerprint.fingerprint[0],
+                                     mFingerprint.fingerprint.size());
     if (NS_FAILED(rv)) {
       MOZ_MTLOG(ML_ERROR, "Could not set fingerprint");
       return rv;
     }
   }
 
   std::vector<uint16_t> srtpCiphers;
   srtpCiphers.push_back(SRTP_AES128_CM_HMAC_SHA1_80);
@@ -358,27 +355,26 @@ MediaPipelineFactory::GetTransportParame
   if (aTrackPair.mBundleLevel.isSome()) {
     bool receiving = aTrack.GetDirection() == sdp::kRecv;
 
     *aFilterOut = new MediaPipelineFilter;
 
     if (receiving) {
       // Add remote SSRCs so we can distinguish which RTP packets actually
       // belong to this pipeline (also RTCP sender reports).
-      for (auto i = aTrack.GetSsrcs().begin();
-          i != aTrack.GetSsrcs().end(); ++i) {
-        (*aFilterOut)->AddRemoteSSRC(*i);
+      for (unsigned int ssrc : aTrack.GetSsrcs()) {
+        (*aFilterOut)->AddRemoteSSRC(ssrc);
       }
 
       // TODO(bug 1105005): Tell the filter about the mid for this track
 
       // Add unique payload types as a last-ditch fallback
       auto uniquePts = aTrack.GetNegotiatedDetails()->GetUniquePayloadTypes();
-      for (auto i = uniquePts.begin(); i != uniquePts.end(); ++i) {
-        (*aFilterOut)->AddUniquePT(*i);
+      for (unsigned char & uniquePt : uniquePts) {
+        (*aFilterOut)->AddUniquePT(uniquePt);
       }
     }
   }
 
   return NS_OK;
 }
 
 nsresult
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -230,19 +230,19 @@ static void
 EverySecondTelemetryCallback_s(nsAutoPtr<RTCStatsQueries> aQueryList) {
   using namespace Telemetry;
 
   if(!PeerConnectionCtx::isActive()) {
     return;
   }
   PeerConnectionCtx *ctx = PeerConnectionCtx::GetInstance();
 
-  for (auto q = aQueryList->begin(); q != aQueryList->end(); ++q) {
-    PeerConnectionImpl::ExecuteStatsQuery_s(*q);
-    auto& r = *(*q)->report;
+  for (auto & q : *aQueryList) {
+    PeerConnectionImpl::ExecuteStatsQuery_s(q);
+    auto& r = *q->report;
     if (r.mInboundRTPStreamStats.WasPassed()) {
       // First, get reports from a second ago, if any, for calculations below
       const Sequence<RTCInboundRTPStreamStats> *lastInboundStats = nullptr;
       {
         auto i = FindId(ctx->mLastReports, r.mPcid);
         if (i != ctx->mLastReports.NoIndex) {
           lastInboundStats = &ctx->mLastReports[i]->mInboundRTPStreamStats.Value();
         }
@@ -311,18 +311,18 @@ EverySecondTelemetryCallback_s(nsAutoPtr
             }
           }
         }
       }
     }
   }
   // Steal and hang on to reports for the next second
   ctx->mLastReports.Clear();
-  for (auto q = aQueryList->begin(); q != aQueryList->end(); ++q) {
-    ctx->mLastReports.AppendElement((*q)->report.forget()); // steal avoids copy
+  for (auto & q : *aQueryList) {
+    ctx->mLastReports.AppendElement(q->report.forget()); // steal avoids copy
   }
   // Container must be freed back on main thread
   NS_DispatchToMainThread(WrapRunnableNM(&FreeOnMain_m, aQueryList),
                           NS_DISPATCH_NORMAL);
 }
 
 void
 PeerConnectionCtx::EverySecondTelemetryCallback_m(nsITimer* timer, void *closure) {
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1175,19 +1175,17 @@ PeerConnectionImpl::EnsureDataConnection
 nsresult
 PeerConnectionImpl::GetDatachannelParameters(
     uint32_t* channels,
     uint16_t* localport,
     uint16_t* remoteport,
     uint16_t* level) const {
 
   auto trackPairs = mJsepSession->GetNegotiatedTrackPairs();
-  for (auto j = trackPairs.begin(); j != trackPairs.end(); ++j) {
-    JsepTrackPair& trackPair = *j;
-
+  for (auto & trackPair : trackPairs) {
     bool sendDataChannel =
       trackPair.mSending &&
       trackPair.mSending->GetMediaType() == SdpMediaSection::kApplication;
     bool recvDataChannel =
       trackPair.mReceiving &&
       trackPair.mReceiving->GetMediaType() == SdpMediaSection::kApplication;
     (void)recvDataChannel;
     MOZ_ASSERT(sendDataChannel == recvDataChannel);
@@ -1899,30 +1897,28 @@ PeerConnectionImpl::CreateNewRemoteTrack
 {
   JSErrorResult jrv;
 
   std::vector<RefPtr<JsepTrack>> newTracks =
     mJsepSession->GetRemoteTracksAdded();
 
   // Group new tracks by stream id
   std::map<std::string, std::vector<RefPtr<JsepTrack>>> tracksByStreamId;
-  for (auto i = newTracks.begin(); i != newTracks.end(); ++i) {
-    RefPtr<JsepTrack> track = *i;
-
+  for (auto track : newTracks) {
     if (track->GetMediaType() == mozilla::SdpMediaSection::kApplication) {
       // Ignore datachannel
       continue;
     }
 
     tracksByStreamId[track->GetStreamId()].push_back(track);
   }
 
-  for (auto i = tracksByStreamId.begin(); i != tracksByStreamId.end(); ++i) {
-    std::string streamId = i->first;
-    std::vector<RefPtr<JsepTrack>>& tracks = i->second;
+  for (auto & sId : tracksByStreamId) {
+    std::string streamId = sId.first;
+    std::vector<RefPtr<JsepTrack>>& tracks = sId.second;
 
     bool newStream = false;
     RefPtr<RemoteSourceStreamInfo> info =
       mMedia->GetRemoteStreamById(streamId);
     if (!info) {
       newStream = true;
       nsresult nrv = CreateRemoteSourceStreamInfo(&info, streamId);
       if (NS_FAILED(nrv)) {
@@ -2049,19 +2045,19 @@ PeerConnectionImpl::CreateNewRemoteTrack
 void
 PeerConnectionImpl::RemoveOldRemoteTracks(RefPtr<PeerConnectionObserver>& aPco)
 {
   JSErrorResult jrv;
 
   std::vector<RefPtr<JsepTrack>> removedTracks =
     mJsepSession->GetRemoteTracksRemoved();
 
-  for (auto i = removedTracks.begin(); i != removedTracks.end(); ++i) {
-    const std::string& streamId = (*i)->GetStreamId();
-    const std::string& trackId = (*i)->GetTrackId();
+  for (auto & removedTrack : removedTracks) {
+    const std::string& streamId = removedTrack->GetStreamId();
+    const std::string& trackId = removedTrack->GetTrackId();
 
     RefPtr<RemoteSourceStreamInfo> info = mMedia->GetRemoteStreamById(streamId);
     if (!info) {
       MOZ_ASSERT(false, "A stream/track was removed that wasn't in PCMedia. "
                         "This is a bug.");
       continue;
     }
 
@@ -3680,33 +3676,33 @@ PeerConnectionImpl::BuildStatsQuery_m(
 static void ToRTCIceCandidateStats(
     const std::vector<NrIceCandidate>& candidates,
     RTCStatsType candidateType,
     const nsString& componentId,
     DOMHighResTimeStamp now,
     RTCStatsReportInternal* report) {
 
   MOZ_ASSERT(report);
-  for (auto c = candidates.begin(); c != candidates.end(); ++c) {
+  for (const auto & candidate : candidates) {
     RTCIceCandidateStats cand;
     cand.mType.Construct(candidateType);
-    NS_ConvertASCIItoUTF16 codeword(c->codeword.c_str());
+    NS_ConvertASCIItoUTF16 codeword(candidate.codeword.c_str());
     cand.mComponentId.Construct(componentId);
     cand.mId.Construct(codeword);
     cand.mTimestamp.Construct(now);
     cand.mCandidateType.Construct(
-        RTCStatsIceCandidateType(c->type));
+        RTCStatsIceCandidateType(candidate.type));
     cand.mIpAddress.Construct(
-        NS_ConvertASCIItoUTF16(c->cand_addr.host.c_str()));
-    cand.mPortNumber.Construct(c->cand_addr.port);
+        NS_ConvertASCIItoUTF16(candidate.cand_addr.host.c_str()));
+    cand.mPortNumber.Construct(candidate.cand_addr.port);
     cand.mTransport.Construct(
-        NS_ConvertASCIItoUTF16(c->cand_addr.transport.c_str()));
+        NS_ConvertASCIItoUTF16(candidate.cand_addr.transport.c_str()));
     if (candidateType == RTCStatsType::Local_candidate) {
       cand.mMozLocalTransport.Construct(
-          NS_ConvertASCIItoUTF16(c->local_addr.transport.c_str()));
+          NS_ConvertASCIItoUTF16(candidate.local_addr.transport.c_str()));
     }
     report->mIceCandidateStats.Value().AppendElement(cand, fallible);
   }
 }
 
 static void RecordIceStats_s(
     NrIceMediaStream& mediaStream,
     bool internalStats,
@@ -3717,34 +3713,34 @@ static void RecordIceStats_s(
 
   std::vector<NrIceCandidatePair> candPairs;
   nsresult res = mediaStream.GetCandidatePairs(&candPairs);
   if (NS_FAILED(res)) {
     CSFLogError(logTag, "%s: Error getting candidate pairs", __FUNCTION__);
     return;
   }
 
-  for (auto p = candPairs.begin(); p != candPairs.end(); ++p) {
-    NS_ConvertASCIItoUTF16 codeword(p->codeword.c_str());
-    NS_ConvertASCIItoUTF16 localCodeword(p->local.codeword.c_str());
-    NS_ConvertASCIItoUTF16 remoteCodeword(p->remote.codeword.c_str());
+  for (auto & candPair : candPairs) {
+    NS_ConvertASCIItoUTF16 codeword(candPair.codeword.c_str());
+    NS_ConvertASCIItoUTF16 localCodeword(candPair.local.codeword.c_str());
+    NS_ConvertASCIItoUTF16 remoteCodeword(candPair.remote.codeword.c_str());
     // Only expose candidate-pair statistics to chrome, until we've thought
     // through the implications of exposing it to content.
 
     RTCIceCandidatePairStats s;
     s.mId.Construct(codeword);
     s.mComponentId.Construct(componentId);
     s.mTimestamp.Construct(now);
     s.mType.Construct(RTCStatsType::Candidate_pair);
     s.mLocalCandidateId.Construct(localCodeword);
     s.mRemoteCandidateId.Construct(remoteCodeword);
-    s.mNominated.Construct(p->nominated);
-    s.mPriority.Construct(p->priority);
-    s.mSelected.Construct(p->selected);
-    s.mState.Construct(RTCStatsIceCandidatePairState(p->state));
+    s.mNominated.Construct(candPair.nominated);
+    s.mPriority.Construct(candPair.priority);
+    s.mSelected.Construct(candPair.selected);
+    s.mState.Construct(RTCStatsIceCandidatePairState(candPair.state));
     report->mIceCandidatePairStats.Value().AppendElement(s, fallible);
   }
 
   std::vector<NrIceCandidate> candidates;
   if (NS_SUCCEEDED(mediaStream.GetLocalCandidates(&candidates))) {
     ToRTCIceCandidateStats(candidates,
                            RTCStatsType::Local_candidate,
                            componentId,
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
@@ -168,29 +168,29 @@ SourceStreamInfo::RemoveTrack(const std:
   }
 }
 
 void SourceStreamInfo::DetachTransport_s()
 {
   ASSERT_ON_THREAD(mParent->GetSTSThread());
   // walk through all the MediaPipelines and call the shutdown
   // transport functions. Must be on the STS thread.
-  for (auto it = mPipelines.begin(); it != mPipelines.end(); ++it) {
-    it->second->DetachTransport_s();
+  for (auto & mPipeline : mPipelines) {
+    mPipeline.second->DetachTransport_s();
   }
 }
 
 void SourceStreamInfo::DetachMedia_m()
 {
   ASSERT_ON_THREAD(mParent->GetMainThread());
 
   // walk through all the MediaPipelines and call the shutdown
   // media functions. Must be on the main thread.
-  for (auto it = mPipelines.begin(); it != mPipelines.end(); ++it) {
-    it->second->ShutdownMedia_m();
+  for (auto & mPipeline : mPipelines) {
+    mPipeline.second->ShutdownMedia_m();
   }
   mMediaStream = nullptr;
 }
 
 already_AddRefed<PeerConnectionImpl>
 PeerConnectionImpl::Constructor(const dom::GlobalObject& aGlobal, ErrorResult& rv)
 {
   RefPtr<PeerConnectionImpl> pc = new PeerConnectionImpl(&aGlobal);
@@ -546,18 +546,18 @@ PeerConnectionMedia::ActivateOrRemoveTra
 
   if (!stream->HasParsedAttributes()) {
     CSFLogDebug(logTag, "%s: Activating ICE media stream=%u components=%u",
                 mParentHandle.c_str(),
                 static_cast<unsigned>(aMLine),
                 static_cast<unsigned>(aComponentCount));
 
     std::vector<std::string> attrs;
-    for (auto i = aCandidateList.begin(); i != aCandidateList.end(); ++i) {
-      attrs.push_back("candidate:" + *i);
+    for (const auto & candidate : aCandidateList) {
+      attrs.push_back("candidate:" + candidate);
     }
     attrs.push_back("ice-ufrag:" + aUfrag);
     attrs.push_back("ice-pwd:" + aPassword);
 
     nsresult rv = stream->ParseAttributes(attrs);
     if (NS_FAILED(rv)) {
       CSFLogError(logTag, "Couldn't parse ICE attributes, rv=%u",
                           static_cast<unsigned>(rv));
@@ -579,19 +579,17 @@ PeerConnectionMedia::RemoveTransportsAtO
 }
 
 nsresult PeerConnectionMedia::UpdateMediaPipelines(
     const JsepSession& session) {
   auto trackPairs = session.GetNegotiatedTrackPairs();
   MediaPipelineFactory factory(this);
   nsresult rv;
 
-  for (auto i = trackPairs.begin(); i != trackPairs.end(); ++i) {
-    JsepTrackPair pair = *i;
-
+  for (auto pair : trackPairs) {
     if (pair.mReceiving) {
 
       rv = factory.CreateOrUpdateMediaPipeline(pair, *pair.mReceiving);
       if (NS_FAILED(rv)) {
         return rv;
       }
     }
 
@@ -635,18 +633,18 @@ PeerConnectionMedia::StartIceChecks_s(
 
   std::vector<std::string> attributes;
   if (aIsIceLite) {
     attributes.push_back("ice-lite");
   }
 
   if (!aIceOptionsList.empty()) {
     attributes.push_back("ice-options:");
-    for (auto i = aIceOptionsList.begin(); i != aIceOptionsList.end(); ++i) {
-      attributes.back() += *i + ' ';
+    for (const auto & option : aIceOptionsList) {
+      attributes.back() += option + ' ';
     }
   }
 
   nsresult rv = mIceCtxHdlr->ctx()->ParseGlobalAttributes(attributes);
   if (NS_FAILED(rv)) {
     CSFLogError(logTag, "%s: couldn't parse global parameters", __FUNCTION__ );
   }
 
@@ -736,20 +734,18 @@ PeerConnectionMedia::FinalizeIceRestart(
 }
 
 void
 PeerConnectionMedia::FinalizeIceRestart_s()
 {
   ASSERT_ON_THREAD(mSTSThread);
 
   // reset old streams since we don't need them anymore
-  for (auto i = mTransportFlows.begin();
-       i != mTransportFlows.end();
-       ++i) {
-    RefPtr<TransportFlow> aFlow = i->second;
+  for (auto & mTransportFlow : mTransportFlows) {
+    RefPtr<TransportFlow> aFlow = mTransportFlow.second;
     if (!aFlow) continue;
     TransportLayerIce* ice =
       static_cast<TransportLayerIce*>(aFlow->GetLayer(TransportLayerIce::ID()));
     ice->ResetOldStream();
   }
 
   mIceCtxHdlr->FinalizeIceRestart();
 }
@@ -775,20 +771,18 @@ void
 PeerConnectionMedia::RollbackIceRestart_s()
 {
   ASSERT_ON_THREAD(mSTSThread);
 
   // hold the restart context so we can disconnect signals
   RefPtr<NrIceCtx> restartCtx = mIceCtxHdlr->ctx();
 
   // restore old streams since we're rolling back
-  for (auto i = mTransportFlows.begin();
-       i != mTransportFlows.end();
-       ++i) {
-    RefPtr<TransportFlow> aFlow = i->second;
+  for (auto & mTransportFlow : mTransportFlows) {
+    RefPtr<TransportFlow> aFlow = mTransportFlow.second;
     if (!aFlow) continue;
     TransportLayerIce* ice =
       static_cast<TransportLayerIce*>(aFlow->GetLayer(TransportLayerIce::ID()));
     ice->RestoreOldStream();
   }
 
   mIceCtxHdlr->RollbackIceRestart();
   ConnectSignals(mIceCtxHdlr->ctx().get(), restartCtx.get());
@@ -909,20 +903,18 @@ PeerConnectionMedia::UpdateNetworkState_
 }
 
 void
 PeerConnectionMedia::FlushIceCtxOperationQueueIfReady()
 {
   ASSERT_ON_THREAD(mMainThread);
 
   if (IsIceCtxReady()) {
-    for (auto i = mQueuedIceCtxOperations.begin();
-         i != mQueuedIceCtxOperations.end();
-         ++i) {
-      GetSTSThread()->Dispatch(*i, NS_DISPATCH_NORMAL);
+    for (auto & mQueuedIceCtxOperation : mQueuedIceCtxOperations) {
+      GetSTSThread()->Dispatch(mQueuedIceCtxOperation, NS_DISPATCH_NORMAL);
     }
     mQueuedIceCtxOperations.clear();
   }
 }
 
 void
 PeerConnectionMedia::PerformOrEnqueueIceCtxOperation(nsIRunnable* runnable)
 {
@@ -1534,19 +1526,19 @@ PeerConnectionMedia::UpdateSinkIdentity_
   }
 }
 
 void
 LocalSourceStreamInfo::UpdateSinkIdentity_m(MediaStreamTrack* aTrack,
                                             nsIPrincipal* aPrincipal,
                                             const PeerIdentity* aSinkIdentity)
 {
-  for (auto it = mPipelines.begin(); it != mPipelines.end(); ++it) {
+  for (auto & mPipeline : mPipelines) {
     MediaPipelineTransmit* pipeline =
-      static_cast<MediaPipelineTransmit*>((*it).second.get());
+      static_cast<MediaPipelineTransmit*>(mPipeline.second.get());
     pipeline->UpdateSinkIdentity_m(aTrack, aPrincipal, aSinkIdentity);
   }
 }
 
 void RemoteSourceStreamInfo::UpdatePrincipal_m(nsIPrincipal* aPrincipal)
 {
   // This blasts away the existing principal.
   // We only do this when we become certain that the all tracks are safe to make
@@ -1582,18 +1574,18 @@ PeerConnectionMedia::AnyCodecHasPluginID
   }
   return false;
 }
 
 bool
 SourceStreamInfo::AnyCodecHasPluginID(uint64_t aPluginID)
 {
   // Scan the videoConduits for this plugin ID
-  for (auto it = mPipelines.begin(); it != mPipelines.end(); ++it) {
-    if (it->second->Conduit()->CodecPluginID() == aPluginID) {
+  for (auto & mPipeline : mPipelines) {
+    if (mPipeline.second->Conduit()->CodecPluginID() == aPluginID) {
       return true;
     }
   }
   return false;
 }
 
 nsresult
 SourceStreamInfo::StorePipeline(
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -1097,19 +1097,19 @@ static void StoreLongTermICEStatisticsIm
     // stream ID. This is just the way the stats API is standardized right now.
     // Very confusing.
     std::string streamId(
       NS_ConvertUTF16toUTF8(cand.mComponentId.Value()).get());
 
     streamResults[streamId].candidateTypeBitpattern |= candBitmask;
   }
 
-  for (auto i = streamResults.begin(); i != streamResults.end(); ++i) {
-    Telemetry::RecordWebrtcIceCandidates(i->second.candidateTypeBitpattern,
-                                         i->second.streamSucceeded);
+  for (auto & streamResult : streamResults) {
+    Telemetry::RecordWebrtcIceCandidates(streamResult.second.candidateTypeBitpattern,
+                                         streamResult.second.streamSucceeded);
   }
 
   // Beyond ICE, accumulate telemetry for various PER_CALL settings here.
 
   if (query->report->mOutboundRTPStreamStats.WasPassed()) {
     auto& array = query->report->mOutboundRTPStreamStats.Value();
     for (decltype(array.Length()) i = 0; i < array.Length(); i++) {
       auto& s = array[i];
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -113,22 +113,22 @@ namespace test {
 
 class SignalingAgent;
 
 std::string indent(const std::string &s, int width = 4) {
   std::string prefix;
   std::string out;
   char previous = '\n';
   prefix.assign(width, ' ');
-  for (std::string::const_iterator i = s.begin(); i != s.end(); i++) {
+  for (char i : s) {
     if (previous == '\n') {
       out += prefix;
     }
-    out += *i;
-    previous = *i;
+    out += i;
+    previous = i;
   }
   return out;
 }
 
 static const std::string strSampleSdpAudioVideoNoIce =
   "v=0\r\n"
   "o=Mozilla-SIPUA 4949 0 IN IP4 10.86.255.143\r\n"
   "s=SIP Call\r\n"
@@ -220,18 +220,18 @@ public:
     lastAddIceStatusCode(PeerConnectionImpl::kNoError),
     peerAgent(nullptr),
     trickleCandidates(true)
     {}
 
   size_t MatchingCandidates(const std::string& cand) {
     size_t count = 0;
 
-    for (size_t i=0; i<candidates.size(); ++i) {
-      if (candidates[i].find(cand) != std::string::npos)
+    for (auto & candidate : candidates) {
+      if (candidate.find(cand) != std::string::npos)
         ++count;
     }
 
     return count;
   }
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_IMETHOD OnCreateOfferSuccess(const char* offer, ER&) override;
@@ -607,19 +607,19 @@ class ParsedSDP {
     }
   }
 
   // Returns the values for all lines of the indicated type
   // Removes trailing "\r\n" from values.
   std::vector<std::string> GetLines(std::string objType) const
   {
     std::vector<std::string> values;
-    for (auto it = sdp_lines_.begin(); it != sdp_lines_.end(); ++it) {
-      if (it->first == objType) {
-        std::string value = it->second;
+    for (const auto & sdp_line : sdp_lines_) {
+      if (sdp_line.first == objType) {
+        std::string value = sdp_line.second;
         if (value.find("\r") != std::string::npos) {
           value = value.substr(0, value.find("\r"));
         } else {
           ADD_FAILURE() << "SDP line had no endline; this should never happen.";
         }
         values.push_back(value);
       }
     }
@@ -644,22 +644,22 @@ class ParsedSDP {
     }
   }
 
   //Convert Internal SDP representation into String representation
   std::string getSdp() const
   {
     std::string sdp;
 
-    for (auto it = sdp_lines_.begin(); it != sdp_lines_.end(); ++it) {
-      sdp += it->first;
-      if (it->second != "\r\n") {
+    for (const auto & sdp_line : sdp_lines_) {
+      sdp += sdp_line.first;
+      if (sdp_line.second != "\r\n") {
         sdp += " ";
       }
-      sdp += it->second;
+      sdp += sdp_line.second;
     }
 
     return sdp;
   }
 
   void IncorporateCandidate(uint16_t level, const std::string &candidate)
   {
     std::string candidate_attribute("a=" + candidate + "\r\n");
@@ -1146,19 +1146,19 @@ class SignalingAgent {
   }
 
   // I would love to make this an overload of operator<<, but there's no way to
   // declare it in a way that works with gtest's header files.
   std::string DumpTracks(
       const std::map<Msid, SdpMediaSection::MediaType>& tracks) const
   {
     std::ostringstream oss;
-    for (auto it = tracks.begin(); it != tracks.end(); ++it) {
-      oss << it->first.streamId << "/" << it->first.trackId
-          << " (" << it->second << ")" << std::endl;
+    for (const auto & track : tracks) {
+      oss << track.first.streamId << "/" << track.first.trackId
+          << " (" << track.second << ")" << std::endl;
     }
 
     return oss.str();
   }
 
   void ExpectMissingTracks(SdpMediaSection::MediaType type)
   {
     for (auto it = mAddedTracks.begin(); it != mAddedTracks.end();) {
@@ -1413,23 +1413,21 @@ class SignalingAgent {
     pObserver->state = TestObserver::stateNoResponse;
     ASSERT_EQ(pc->SetRemoteDescription(action, remote.c_str()), NS_OK);
     ASSERT_EQ(signaling_state(), endState);
     if (!ignoreError) {
       ASSERT_EQ(pObserver->state, TestObserver::stateSuccess);
     }
 
     mRemoteDescriptionSet = true;
-    for (auto i = deferredCandidates_.begin();
-         i != deferredCandidates_.end();
-         ++i) {
-      AddIceCandidate(i->candidate.c_str(),
-                      i->mid.c_str(),
-                      i->level,
-                      i->expectSuccess);
+    for (auto & deferredCandidate : deferredCandidates_) {
+      AddIceCandidate(deferredCandidate.candidate.c_str(),
+                      deferredCandidate.mid.c_str(),
+                      deferredCandidate.level,
+                      deferredCandidate.expectSuccess);
     }
     deferredCandidates_.clear();
   }
 
   void SetLocal(TestObserver::Action action, const std::string& local,
                 bool ignoreError = false,
                 PCImplSignalingState endState =
                 PCImplSignalingState::SignalingInvalid) {
@@ -1529,28 +1527,28 @@ class SignalingAgent {
 
     return static_cast<Fake_MediaStreamBase *>(
         domMediaStreams_[stream]->GetStream())->GetSegmentsAdded();
   }
 
   //Stops generating new audio data for transmission.
   //Should be called before Cleanup of the peer connection.
   void CloseSendStreams() {
-    for (auto i = domMediaStreams_.begin(); i != domMediaStreams_.end(); ++i) {
-      static_cast<Fake_MediaStream*>((*i)->GetStream())->StopStream();
+    for (auto & domMediaStream : domMediaStreams_) {
+      static_cast<Fake_MediaStream*>(domMediaStream->GetStream())->StopStream();
     }
   }
 
   //Stops pulling audio data off the receivers.
   //Should be called before Cleanup of the peer connection.
   void CloseReceiveStreams() {
     std::vector<DOMMediaStream *> streams =
                             pObserver->GetStreams();
-    for (size_t i = 0; i < streams.size(); i++) {
-      streams[i]->GetStream()->AsSourceStream()->StopStream();
+    for (auto & stream : streams) {
+      stream->GetStream()->AsSourceStream()->StopStream();
     }
   }
 
   // Right now we have no convenient way for this unit-test to learn the track
   // ids of the tracks, so they can be queried later. We could either expose
   // the JsepSessionImpl in some way, or we could parse the identifiers out of
   // the SDP. For now, we just specify audio/video, since a given DOMMediaStream
   // can have only one of each anyway. Once this is fixed, we will need to
@@ -1571,20 +1569,20 @@ class SignalingAgent {
     }
 
     if (!streamInfo) {
       return nullptr;
     }
 
     const auto &pipelines = streamInfo->GetPipelines();
 
-    for (auto i = pipelines.begin(); i != pipelines.end(); ++i) {
-      if (i->second->IsVideo() == video) {
-        std::cout << "Got MediaPipeline " << i->second->trackid();
-        return i->second;
+    for (const auto & pipeline : pipelines) {
+      if (pipeline.second->IsVideo() == video) {
+        std::cout << "Got MediaPipeline " << pipeline.second->trackid();
+        return pipeline.second;
       }
     }
     return nullptr;
   }
 
   void SetPeer(SignalingAgent* peer) {
     pObserver->peerAgent = peer;
   }
@@ -1678,18 +1676,18 @@ class SignalingEnvironment : public ::te
 
 class SignalingAgentTest : public ::testing::Test {
  public:
   static void SetUpTestCase() {
   }
 
   void TearDown() {
     // Delete all the agents.
-    for (size_t i=0; i < agents_.size(); i++) {
-      delete agents_[i];
+    for (auto & agent : agents_) {
+      delete agent;
     }
   }
 
   bool CreateAgent() {
     return CreateAgent(g_stun_server_address, g_stun_server_port);
   }
 
   bool CreateAgent(const std::string stun_addr, uint16_t stun_port) {