Chromium Code Reviews| Index: webrtc/p2p/base/transport.cc |
| diff --git a/webrtc/p2p/base/transport.cc b/webrtc/p2p/base/transport.cc |
| index 3e5f1b9f3a98ed1b953eb67a541d205a37965a4b..a14d9182fba636f65530023d8e4f257f750f2550 100644 |
| --- a/webrtc/p2p/base/transport.cc |
| +++ b/webrtc/p2p/base/transport.cc |
| @@ -72,47 +72,9 @@ Transport::~Transport() { |
| ASSERT(channels_destroyed_); |
| } |
| -bool Transport::AllChannelsCompleted() const { |
| - // We aren't completed until at least one channel is complete, so if there |
| - // are no channels, we aren't complete yet. |
| - if (channels_.empty()) { |
| - LOG(LS_INFO) << name() << " transport is not complete" |
| - << " because it has no TransportChannels"; |
| - return false; |
| - } |
| - |
| - // A Transport's ICE process is completed if all of its channels are writable, |
| - // have finished allocating candidates, and have pruned all but one of their |
| - // connections. |
| - for (const auto& iter : channels_) { |
| - const TransportChannelImpl* channel = iter.second.get(); |
| - bool complete = |
| - channel->writable() && |
| - channel->GetState() == TransportChannelState::STATE_COMPLETED && |
| - channel->GetIceRole() == ICEROLE_CONTROLLING && |
| - channel->gathering_state() == kIceGatheringComplete; |
| - if (!complete) { |
| - LOG(LS_INFO) << name() << " transport is not complete" |
| - << " because a channel is still incomplete."; |
| - return false; |
| - } |
| - } |
| - |
| - return true; |
| -} |
| - |
| -bool Transport::AnyChannelFailed() const { |
| - for (const auto& iter : channels_) { |
| - if (iter.second->GetState() == TransportChannelState::STATE_FAILED) { |
| - return true; |
| - } |
| - } |
| - return false; |
| -} |
| - |
| void Transport::SetIceRole(IceRole role) { |
| ice_role_ = role; |
| - for (auto& iter : channels_) { |
| + for (const auto& iter : channels_) { |
| iter.second->SetIceRole(ice_role_); |
| } |
| } |
| @@ -127,8 +89,8 @@ bool Transport::GetRemoteSSLCertificate(rtc::SSLCertificate** cert) { |
| void Transport::SetIceConfig(const IceConfig& config) { |
| ice_config_ = config; |
| - for (const auto& kv : channels_) { |
| - kv.second->SetIceConfig(ice_config_); |
| + for (const auto& iter : channels_) { |
| + iter.second->SetIceConfig(ice_config_); |
| } |
| } |
| @@ -155,8 +117,8 @@ bool Transport::SetLocalTransportDescription( |
| local_description_.reset(new TransportDescription(description)); |
| - for (auto& iter : channels_) { |
| - ret &= ApplyLocalTransportDescription(iter.second.get(), error_desc); |
| + for (const auto& iter : channels_) { |
| + ret &= ApplyLocalTransportDescription(iter.second, error_desc); |
| } |
| if (!ret) { |
| return false; |
| @@ -186,8 +148,8 @@ bool Transport::SetRemoteTransportDescription( |
| } |
| remote_description_.reset(new TransportDescription(description)); |
| - for (auto& iter : channels_) { |
| - ret &= ApplyRemoteTransportDescription(iter.second.get(), error_desc); |
| + for (const auto& iter : channels_) { |
| + ret &= ApplyRemoteTransportDescription(iter.second, error_desc); |
| } |
| // If PRANSWER/ANSWER is set, we should decide transport protocol type. |
| @@ -209,20 +171,18 @@ TransportChannelImpl* Transport::CreateChannel(int component) { |
| auto iterator = channels_.find(component); |
| if (iterator == channels_.end()) { |
| impl = CreateTransportChannel(component); |
| - iterator = channels_.insert(std::pair<int, ChannelMapEntry>( |
| - component, ChannelMapEntry(impl))).first; |
| + iterator = |
| + channels_.insert(std::pair<int, TransportChannelImpl*>(component, impl)) |
| + .first; |
|
pthatcher1
2015/09/29 23:50:58
Is iterator even used in this function? Can we ju
Taylor Brandstetter
2015/09/30 01:01:20
Done.
|
| } else { |
| - impl = iterator->second.get(); |
| + impl = iterator->second; |
| impl_exists = true; |
| } |
| - // Increase the ref count. |
| - iterator->second.AddRef(); |
| channels_destroyed_ = false; |
| if (impl_exists) { |
| - // If this is an existing channel, we should just return it without |
| - // connecting to all the signal again. |
| + // If this is an existing channel, we should just return it. |
| return impl; |
| } |
| @@ -239,30 +199,15 @@ TransportChannelImpl* Transport::CreateChannel(int component) { |
| if (local_description_ && remote_description_) |
| ApplyNegotiatedTransportDescription(impl, NULL); |
| - impl->SignalWritableState.connect(this, &Transport::OnChannelWritableState); |
| - impl->SignalReceivingState.connect(this, &Transport::OnChannelReceivingState); |
| - impl->SignalGatheringState.connect(this, &Transport::OnChannelGatheringState); |
| - impl->SignalCandidateGathered.connect(this, |
| - &Transport::OnChannelCandidateGathered); |
| - impl->SignalRouteChange.connect(this, &Transport::OnChannelRouteChange); |
| - impl->SignalRoleConflict.connect(this, &Transport::OnRoleConflict); |
| - impl->SignalConnectionRemoved.connect( |
| - this, &Transport::OnChannelConnectionRemoved); |
| - |
| if (connect_requested_) { |
| impl->Connect(); |
| - if (channels_.size() == 1) { |
| - // If this is the first channel, then indicate that we have started |
| - // connecting. |
| - SignalConnecting(this); |
| - } |
| } |
| return impl; |
| } |
| TransportChannelImpl* Transport::GetChannel(int component) { |
| ChannelMap::iterator iter = channels_.find(component); |
| - return (iter != channels_.end()) ? iter->second.get() : NULL; |
| + return (iter != channels_.end()) ? iter->second : NULL; |
| } |
| bool Transport::HasChannels() { |
| @@ -274,28 +219,9 @@ void Transport::DestroyChannel(int component) { |
| if (iter == channels_.end()) |
| return; |
| - TransportChannelImpl* impl = NULL; |
| - |
| - iter->second.DecRef(); |
| - if (!iter->second.ref()) { |
| - impl = iter->second.get(); |
| - channels_.erase(iter); |
| - } |
| - |
| - if (connect_requested_ && channels_.empty()) { |
| - // We're no longer attempting to connect. |
| - SignalConnecting(this); |
| - } |
| - |
| - if (impl) { |
| - DestroyTransportChannel(impl); |
| - // Need to update aggregate state after destroying a channel, |
| - // for example if it was the only one that wasn't yet writable. |
| - UpdateWritableState(); |
| - UpdateReceivingState(); |
| - UpdateGatheringState(); |
| - MaybeSignalCompleted(); |
| - } |
| + TransportChannelImpl* impl = iter->second; |
| + channels_.erase(iter); |
| + DestroyTransportChannel(impl); |
| } |
| void Transport::ConnectChannels() { |
| @@ -321,9 +247,6 @@ void Transport::ConnectChannels() { |
| } |
| CallChannels(&TransportChannelImpl::Connect); |
| - if (HasChannels()) { |
| - SignalConnecting(this); |
| - } |
| } |
| void Transport::MaybeStartGathering() { |
| @@ -333,24 +256,16 @@ void Transport::MaybeStartGathering() { |
| } |
| void Transport::DestroyAllChannels() { |
| - std::vector<TransportChannelImpl*> impls; |
| - for (auto& iter : channels_) { |
| - iter.second.DecRef(); |
| - if (!iter.second.ref()) |
| - impls.push_back(iter.second.get()); |
| + for (const auto& iter : channels_) { |
| + DestroyTransportChannel(iter.second); |
| } |
| - |
| channels_.clear(); |
| - |
| - for (TransportChannelImpl* impl : impls) { |
| - DestroyTransportChannel(impl); |
| - } |
| channels_destroyed_ = true; |
| } |
| void Transport::CallChannels(TransportChannelFunc func) { |
| for (const auto& iter : channels_) { |
| - ((iter.second.get())->*func)(); |
| + (iter.second->*func)(); |
| } |
| } |
| @@ -390,12 +305,12 @@ bool Transport::GetStats(TransportStats* stats) { |
| stats->transport_name = name(); |
| stats->channel_stats.clear(); |
| for (auto iter : channels_) { |
| - ChannelMapEntry& entry = iter.second; |
| + TransportChannelImpl* impl = iter.second; |
| TransportChannelStats substats; |
| - substats.component = entry->component(); |
| - entry->GetSrtpCipher(&substats.srtp_cipher); |
| - entry->GetSslCipher(&substats.ssl_cipher); |
| - if (!entry->GetStats(&substats.connection_infos)) { |
| + substats.component = impl->component(); |
| + impl->GetSrtpCipher(&substats.srtp_cipher); |
| + impl->GetSslCipher(&substats.ssl_cipher); |
| + if (!impl->GetStats(&substats.connection_infos)) { |
| return false; |
| } |
| stats->channel_stats.push_back(substats); |
| @@ -429,159 +344,6 @@ bool Transport::AddRemoteCandidates(const std::vector<Candidate>& candidates, |
| return true; |
| } |
| -void Transport::OnChannelWritableState(TransportChannel* channel) { |
| - LOG(LS_INFO) << name() << " TransportChannel " << channel->component() |
| - << " writability changed to " << channel->writable() |
| - << ". Check if transport is complete."; |
| - UpdateWritableState(); |
| - MaybeSignalCompleted(); |
| -} |
| - |
| -void Transport::OnChannelReceivingState(TransportChannel* channel) { |
| - UpdateReceivingState(); |
| -} |
| - |
| -TransportState Transport::GetTransportState(TransportStateType state_type) { |
| - bool any = false; |
| - bool all = !channels_.empty(); |
| - for (const auto iter : channels_) { |
| - bool b = false; |
| - switch (state_type) { |
| - case TRANSPORT_WRITABLE_STATE: |
| - b = iter.second->writable(); |
| - break; |
| - case TRANSPORT_RECEIVING_STATE: |
| - b = iter.second->receiving(); |
| - break; |
| - default: |
| - ASSERT(false); |
| - } |
| - any |= b; |
| - all &= b; |
| - } |
| - |
| - if (all) { |
| - return TRANSPORT_STATE_ALL; |
| - } else if (any) { |
| - return TRANSPORT_STATE_SOME; |
| - } |
| - |
| - return TRANSPORT_STATE_NONE; |
| -} |
| - |
| -void Transport::OnChannelGatheringState(TransportChannelImpl* channel) { |
| - ASSERT(channels_.find(channel->component()) != channels_.end()); |
| - UpdateGatheringState(); |
| - if (gathering_state_ == kIceGatheringComplete) { |
| - // If UpdateGatheringState brought us to kIceGatheringComplete, check if |
| - // our connection state is also "Completed". Otherwise, there's no point in |
| - // checking (since it would only produce log messages). |
| - MaybeSignalCompleted(); |
| - } |
| -} |
| - |
| -void Transport::OnChannelCandidateGathered(TransportChannelImpl* channel, |
| - const Candidate& candidate) { |
| - // We should never signal peer-reflexive candidates. |
| - if (candidate.type() == PRFLX_PORT_TYPE) { |
| - ASSERT(false); |
| - return; |
| - } |
| - |
| - ASSERT(connect_requested_); |
| - std::vector<Candidate> candidates; |
| - candidates.push_back(candidate); |
| - SignalCandidatesGathered(this, candidates); |
| -} |
| - |
| -void Transport::OnChannelRouteChange(TransportChannel* channel, |
| - const Candidate& remote_candidate) { |
| - SignalRouteChange(this, remote_candidate.component(), remote_candidate); |
| -} |
| - |
| -void Transport::OnRoleConflict(TransportChannelImpl* channel) { |
| - SignalRoleConflict(); |
| -} |
| - |
| -void Transport::OnChannelConnectionRemoved(TransportChannelImpl* channel) { |
| - LOG(LS_INFO) << name() << " TransportChannel " << channel->component() |
| - << " connection removed. Check if transport is complete."; |
| - MaybeSignalCompleted(); |
| - |
| - // Check if the state is now Failed. |
| - // Failed is only available in the Controlling ICE role. |
| - if (channel->GetIceRole() != ICEROLE_CONTROLLING) { |
| - return; |
| - } |
| - |
| - // Failed can only occur after candidate gathering has stopped. |
| - if (channel->gathering_state() != kIceGatheringComplete) { |
| - return; |
| - } |
| - |
| - if (channel->GetState() == TransportChannelState::STATE_FAILED) { |
| - // A Transport has failed if any of its channels have no remaining |
| - // connections. |
| - SignalFailed(this); |
| - } |
| -} |
| - |
| -void Transport::MaybeSignalCompleted() { |
| - if (AllChannelsCompleted()) { |
| - LOG(LS_INFO) << name() << " transport is complete" |
| - << " because all the channels are complete."; |
| - SignalCompleted(this); |
| - } |
| - // TODO(deadbeef): Should we do anything if we previously were completed, |
| - // but now are not (if, for example, a new remote candidate is added)? |
| -} |
| - |
| -void Transport::UpdateGatheringState() { |
| - IceGatheringState new_state = kIceGatheringNew; |
| - bool any_gathering = false; |
| - bool all_complete = !channels_.empty(); |
| - for (const auto& kv : channels_) { |
| - any_gathering = |
| - any_gathering || kv.second->gathering_state() != kIceGatheringNew; |
| - all_complete = |
| - all_complete && kv.second->gathering_state() == kIceGatheringComplete; |
| - } |
| - if (all_complete) { |
| - new_state = kIceGatheringComplete; |
| - } else if (any_gathering) { |
| - new_state = kIceGatheringGathering; |
| - } |
| - |
| - if (gathering_state_ != new_state) { |
| - gathering_state_ = new_state; |
| - if (gathering_state_ == kIceGatheringGathering) { |
| - LOG(LS_INFO) << "Transport: " << name_ << ", gathering candidates"; |
| - } else if (gathering_state_ == kIceGatheringComplete) { |
| - LOG(LS_INFO) << "Transport " << name() << " gathering complete."; |
| - } |
| - SignalGatheringState(this); |
| - } |
| -} |
| - |
| -void Transport::UpdateReceivingState() { |
| - TransportState receiving = GetTransportState(TRANSPORT_RECEIVING_STATE); |
| - if (receiving_ != receiving) { |
| - receiving_ = receiving; |
| - SignalReceivingState(this); |
| - } |
| -} |
| - |
| -void Transport::UpdateWritableState() { |
| - TransportState writable = GetTransportState(TRANSPORT_WRITABLE_STATE); |
| - LOG(LS_INFO) << name() << " transport writable state changed? " << writable_ |
| - << " => " << writable; |
| - if (writable_ != writable) { |
| - was_writable_ = (writable_ == TRANSPORT_STATE_ALL); |
| - writable_ = writable; |
| - SignalWritableState(this); |
| - } |
| -} |
| - |
| bool Transport::ApplyLocalTransportDescription(TransportChannelImpl* ch, |
| std::string* error_desc) { |
| ch->SetIceCredentials(local_description_->ice_ufrag, |
| @@ -623,9 +385,10 @@ bool Transport::NegotiateTransportDescription(ContentAction local_role, |
| // between future SetRemote/SetLocal invocations and new channel |
| // creation, we have the negotiation state saved until a new |
| // negotiation happens. |
| - for (auto& iter : channels_) { |
| - if (!ApplyNegotiatedTransportDescription(iter.second.get(), error_desc)) |
| + for (const auto& iter : channels_) { |
| + if (!ApplyNegotiatedTransportDescription(iter.second, error_desc)) { |
| return false; |
| + } |
| } |
| return true; |
| } |