Chromium Code Reviews| Index: webrtc/p2p/client/basicportallocator.cc |
| diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc |
| index dba68f177e5120a496a39d603d622971ac776ac4..8a3bbcea43b5d6b8f139ad94618e9f0253474d0d 100644 |
| --- a/webrtc/p2p/client/basicportallocator.cc |
| +++ b/webrtc/p2p/client/basicportallocator.cc |
| @@ -14,6 +14,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "webrtc/api/peerconnectioninterface.h" |
| #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
| #include "webrtc/p2p/base/common.h" |
| #include "webrtc/p2p/base/port.h" |
| @@ -156,8 +157,11 @@ BasicPortAllocator::~BasicPortAllocator() { |
| PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( |
| const std::string& content_name, int component, |
| const std::string& ice_ufrag, const std::string& ice_pwd) { |
| - return new BasicPortAllocatorSession( |
| + PortAllocatorSession* session = new BasicPortAllocatorSession( |
| this, content_name, component, ice_ufrag, ice_pwd); |
| + session->SignalIceRegatheringReason.connect( |
| + this, &BasicPortAllocator::OnIceRegatheringReason); |
| + return session; |
| } |
| void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { |
| @@ -167,6 +171,15 @@ void BasicPortAllocator::AddTurnServer(const RelayServerConfig& turn_server) { |
| prune_turn_ports()); |
| } |
| +void BasicPortAllocator::OnIceRegatheringReason(PortAllocatorSession* session, |
| + IceRegatheringReason reason) { |
| + if (metrics_observer()) { |
| + metrics_observer()->IncrementEnumCounter( |
| + webrtc::kEnumCounterIceRegatheringReason, static_cast<int>(reason), |
| + static_cast<int>(IceRegatheringReason::MAX_VALUE)); |
|
Taylor Brandstetter
2016/10/03 20:33:35
Unless I'm mistaken, pooled BasicPortAllocatorSess
honghaiz3
2016/10/04 01:03:55
It is true but only under the circumstances where
Taylor Brandstetter
2016/10/04 02:42:32
If we do count regathering that occurs for pooled
honghaiz3
2016/10/05 05:01:53
Do not count the regathering for pooled sessions f
|
| + } |
| +} |
| + |
| // BasicPortAllocatorSession |
| BasicPortAllocatorSession::BasicPortAllocatorSession( |
| BasicPortAllocator* allocator, |
| @@ -247,7 +260,7 @@ void BasicPortAllocatorSession::StartGettingPorts() { |
| network_thread_->Post(RTC_FROM_HERE, this, MSG_CONFIG_START); |
| - LOG(LS_INFO) << "Pruning turn ports " |
| + LOG(LS_INFO) << "Start getting ports with prune_turn_ports " |
| << (prune_turn_ports_ ? "enabled" : "disabled"); |
| } |
| @@ -296,12 +309,20 @@ std::vector<rtc::Network*> BasicPortAllocatorSession::GetFailedNetworks() { |
| } |
| void BasicPortAllocatorSession::RegatherOnFailedNetworks() { |
| + // Do not regather if the allocations has not started, the network manager has |
| + // not started, or the session has stopped. |
| + if (!allocation_started_ || !network_manager_started_ || IsStopped()) { |
|
Taylor Brandstetter
2016/10/03 20:33:35
This seems separate to adding stats. Could you put
honghaiz3
2016/10/04 01:03:55
Moved away from this CL.
|
| + return; |
| + } |
| + |
| // Find the list of networks that have no connection. |
| std::vector<rtc::Network*> failed_networks = GetFailedNetworks(); |
| if (failed_networks.empty()) { |
| return; |
| } |
| + LOG(LS_INFO) << "Regather candidates on failed networks"; |
| + |
| // Mark a sequence as "network failed" if its network is in the list of failed |
| // networks, so that it won't be considered as equivalent when the session |
| // regathers ports and candidates. |
| @@ -321,9 +342,10 @@ void BasicPortAllocatorSession::RegatherOnFailedNetworks() { |
| PrunePortsAndRemoveCandidates(ports_to_prune); |
| } |
| - if (allocation_started_ && network_manager_started_) { |
| - DoAllocate(); |
| - } |
| + SignalIceRegatheringReason( |
| + this, IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_FAILURE); |
| + |
| + DoAllocate(); |
| } |
| std::vector<PortInterface*> BasicPortAllocatorSession::ReadyPorts() const { |
| @@ -501,7 +523,7 @@ void BasicPortAllocatorSession::AllocatePorts() { |
| } |
| void BasicPortAllocatorSession::OnAllocate() { |
| - if (network_manager_started_) |
| + if (network_manager_started_ && !IsStopped()) |
|
Taylor Brandstetter
2016/10/03 20:33:35
Same here.
honghaiz3
2016/10/04 01:03:55
This is not a behavior change.
I just moved the c
Taylor Brandstetter
2016/10/04 02:42:32
Acknowledged.
honghaiz3
2016/10/05 05:01:53
Acknowledged.
|
| DoAllocate(); |
| allocation_started_ = true; |
| @@ -553,10 +575,6 @@ std::vector<rtc::Network*> BasicPortAllocatorSession::GetNetworks() { |
| void BasicPortAllocatorSession::DoAllocate() { |
| bool done_signal_needed = false; |
| std::vector<rtc::Network*> networks = GetNetworks(); |
| - |
| - if (IsStopped()) { |
| - return; |
| - } |
| if (networks.empty()) { |
| LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; |
| done_signal_needed = true; |
| @@ -627,12 +645,19 @@ void BasicPortAllocatorSession::OnNetworksChanged() { |
| PrunePortsAndRemoveCandidates(ports_to_prune); |
| } |
| + if (allocation_started_ && !IsStopped()) { |
| + if (network_manager_started_) { |
| + // If the network manager has started, it must be a regathering. |
| + SignalIceRegatheringReason( |
| + this, IceRegatheringReason::CONTINUAL_GATHERING_BY_NETWORK_CHANGE); |
| + } |
| + DoAllocate(); |
| + } |
| + |
| if (!network_manager_started_) { |
| - LOG(LS_INFO) << "Network manager is started"; |
| + LOG(LS_INFO) << "Network manager has started"; |
| network_manager_started_ = true; |
| } |
| - if (allocation_started_) |
| - DoAllocate(); |
| } |
| void BasicPortAllocatorSession::DisableEquivalentPhases( |