| Index: remoting/protocol/ice_transport_channel.cc
|
| diff --git a/remoting/protocol/ice_transport_channel.cc b/remoting/protocol/ice_transport_channel.cc
|
| index 7e47bceaa65396cedbe70afc1f4913792ebd9b6d..1ef4d7dcbe6004f733be441649036ef524ef27f4 100644
|
| --- a/remoting/protocol/ice_transport_channel.cc
|
| +++ b/remoting/protocol/ice_transport_channel.cc
|
| @@ -13,6 +13,7 @@
|
| #include "jingle/glue/utils.h"
|
| #include "net/base/net_errors.h"
|
| #include "remoting/protocol/channel_socket_adapter.h"
|
| +#include "remoting/protocol/transport_context.h"
|
| #include "third_party/webrtc/base/network.h"
|
| #include "third_party/webrtc/p2p/base/constants.h"
|
| #include "third_party/webrtc/p2p/base/p2ptransportchannel.h"
|
| @@ -46,16 +47,11 @@ TransportRoute::RouteType CandidateTypeToTransportRouteType(
|
|
|
| } // namespace
|
|
|
| -IceTransportChannel::IceTransportChannel(cricket::PortAllocator* port_allocator,
|
| - const NetworkSettings& network_settings,
|
| - TransportRole role)
|
| - : port_allocator_(port_allocator),
|
| - network_settings_(network_settings),
|
| - role_(role),
|
| - delegate_(nullptr),
|
| +IceTransportChannel::IceTransportChannel(
|
| + scoped_refptr<TransportContext> transport_context)
|
| + : transport_context_(transport_context),
|
| ice_username_fragment_(
|
| rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)),
|
| - can_start_(false),
|
| connect_attempts_left_(kMaxReconnectAttempts),
|
| weak_factory_(this) {
|
| DCHECK(!ice_username_fragment_.empty());
|
| @@ -66,32 +62,11 @@ IceTransportChannel::~IceTransportChannel() {
|
|
|
| delegate_->OnTransportDeleted(this);
|
|
|
| - if (channel_.get()) {
|
| - base::ThreadTaskRunnerHandle::Get()->DeleteSoon(
|
| - FROM_HERE, channel_.release());
|
| - }
|
| -}
|
| -
|
| -void IceTransportChannel::OnCanStart() {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| - DCHECK(!can_start_);
|
| - can_start_ = true;
|
| -
|
| - // If Connect() has been called then start connection.
|
| - if (!callback_.is_null())
|
| - DoStart();
|
| -
|
| - // Pass pending ICE credentials and candidates to the channel.
|
| - if (!remote_ice_username_fragment_.empty()) {
|
| - channel_->SetRemoteIceCredentials(remote_ice_username_fragment_,
|
| - remote_ice_password_);
|
| - }
|
| -
|
| - while (!pending_candidates_.empty()) {
|
| - channel_->AddRemoteCandidate(pending_candidates_.front());
|
| - pending_candidates_.pop_front();
|
| - }
|
| + auto task_runner = base::ThreadTaskRunnerHandle::Get();
|
| + if (channel_)
|
| + task_runner->DeleteSoon(FROM_HERE, channel_.release());
|
| + if (port_allocator_)
|
| + task_runner->DeleteSoon(FROM_HERE, port_allocator_.release());
|
| }
|
|
|
| void IceTransportChannel::Connect(const std::string& name,
|
| @@ -107,20 +82,24 @@ void IceTransportChannel::Connect(const std::string& name,
|
| delegate_ = delegate;
|
| callback_ = callback;
|
|
|
| - if (can_start_)
|
| - DoStart();
|
| + transport_context_->CreatePortAllocator(
|
| + base::Bind(&IceTransportChannel::OnPortAllocatorCreated,
|
| + weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| -void IceTransportChannel::DoStart() {
|
| +void IceTransportChannel::OnPortAllocatorCreated(
|
| + scoped_ptr<cricket::PortAllocator> port_allocator){
|
| DCHECK(!channel_.get());
|
|
|
| + port_allocator_ = port_allocator.Pass();
|
| +
|
| // Create P2PTransportChannel, attach signal handlers and connect it.
|
| // TODO(sergeyu): Specify correct component ID for the channel.
|
| channel_.reset(new cricket::P2PTransportChannel(
|
| - std::string(), 0, nullptr, port_allocator_));
|
| + std::string(), 0, nullptr, port_allocator_.get()));
|
| std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH);
|
| channel_->SetIceProtocolType(cricket::ICEPROTO_RFC5245);
|
| - channel_->SetIceRole((role_ == TransportRole::CLIENT)
|
| + channel_->SetIceRole((transport_context_->role() == TransportRole::CLIENT)
|
| ? cricket::ICEROLE_CONTROLLING
|
| : cricket::ICEROLE_CONTROLLED);
|
| delegate_->OnTransportIceCredentials(this, ice_username_fragment_,
|
| @@ -134,12 +113,23 @@ void IceTransportChannel::DoStart() {
|
| this, &IceTransportChannel::OnReceivingState);
|
| channel_->SignalWritableState.connect(
|
| this, &IceTransportChannel::OnWritableState);
|
| - channel_->set_incoming_only(
|
| - !(network_settings_.flags & NetworkSettings::NAT_TRAVERSAL_OUTGOING));
|
| + channel_->set_incoming_only(!(transport_context_->network_settings().flags &
|
| + NetworkSettings::NAT_TRAVERSAL_OUTGOING));
|
|
|
| channel_->Connect();
|
| channel_->MaybeStartGathering();
|
|
|
| + // Pass pending ICE credentials and candidates to the channel.
|
| + if (!remote_ice_username_fragment_.empty()) {
|
| + channel_->SetRemoteIceCredentials(remote_ice_username_fragment_,
|
| + remote_ice_password_);
|
| + }
|
| +
|
| + while (!pending_candidates_.empty()) {
|
| + channel_->AddRemoteCandidate(pending_candidates_.front());
|
| + pending_candidates_.pop_front();
|
| + }
|
| +
|
| --connect_attempts_left_;
|
|
|
| // Start reconnection timer.
|
| @@ -158,7 +148,7 @@ void IceTransportChannel::NotifyConnected() {
|
| }
|
|
|
| void IceTransportChannel::SetRemoteCredentials(const std::string& ufrag,
|
| - const std::string& password) {
|
| + const std::string& password) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| remote_ice_username_fragment_ = ufrag;
|
| @@ -174,7 +164,7 @@ void IceTransportChannel::AddRemoteCandidate(
|
|
|
| // To enforce the no-relay setting, it's not enough to not produce relay
|
| // candidates. It's also necessary to discard remote relay candidates.
|
| - bool relay_allowed = (network_settings_.flags &
|
| + bool relay_allowed = (transport_context_->network_settings().flags &
|
| NetworkSettings::NAT_TRAVERSAL_RELAY) != 0;
|
| if (!relay_allowed && candidate.type() == cricket::RELAY_PORT_TYPE)
|
| return;
|
|
|