diff options
author | sergeyu <sergeyu@chromium.org> | 2014-09-20 06:15:34 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-20 13:16:02 +0000 |
commit | bf00a43689c645029d918a42493ab66d8b3aa5b0 (patch) | |
tree | 069a26e85047be048a53e4c54c919aed0cc7732a /remoting | |
parent | 485909aa0c1b35d27fc06df9b09c617784db262a (diff) | |
download | chromium_src-bf00a43689c645029d918a42493ab66d8b3aa5b0.zip chromium_src-bf00a43689c645029d918a42493ab66d8b3aa5b0.tar.gz chromium_src-bf00a43689c645029d918a42493ab66d8b3aa5b0.tar.bz2 |
Don't start PseudoTCP until underlying transport is connect.
Previously LibjingleTransportFactory was creating and returning
transport before the transport is connected. This means that that the
PseudoTCP was trying to start handshake on a broken transport. That was
delaying PseudoTCP/SSL when the transport takes some time to setup
(e.g. over STUN/Relay). Now LibjingleTransportFactory returns the
transport only after it becomes writable. Empirical testing shows that
this change makes connection initiation much faster in cases when NAT
traversal is required (4 vs 10 seconds).
Review URL: https://codereview.chromium.org/587943002
Cr-Commit-Position: refs/heads/master@{#295862}
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/protocol/libjingle_transport_factory.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/remoting/protocol/libjingle_transport_factory.cc b/remoting/protocol/libjingle_transport_factory.cc index 61ed3ea..4044150 100644 --- a/remoting/protocol/libjingle_transport_factory.cc +++ b/remoting/protocol/libjingle_transport_factory.cc @@ -55,6 +55,7 @@ class LibjingleTransport private: void DoStart(); + void NotifyConnected(); // Signal handlers for cricket::TransportChannel. void OnRequestSignaling(cricket::TransportChannelImpl* channel); @@ -88,12 +89,13 @@ class LibjingleTransport int connect_attempts_left_; base::RepeatingTimer<LibjingleTransport> reconnect_timer_; + base::WeakPtrFactory<LibjingleTransport> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(LibjingleTransport); }; -LibjingleTransport::LibjingleTransport( - cricket::PortAllocator* port_allocator, - const NetworkSettings& network_settings) +LibjingleTransport::LibjingleTransport(cricket::PortAllocator* port_allocator, + const NetworkSettings& network_settings) : port_allocator_(port_allocator), network_settings_(network_settings), event_handler_(NULL), @@ -102,7 +104,8 @@ LibjingleTransport::LibjingleTransport( ice_password_(rtc::CreateRandomString(cricket::ICE_PWD_LENGTH)), can_start_(false), channel_was_writable_(false), - connect_attempts_left_(kMaxReconnectAttempts) { + connect_attempts_left_(kMaxReconnectAttempts), + weak_factory_(this) { DCHECK(!ice_username_fragment_.empty()); DCHECK(!ice_password_.empty()); } @@ -180,7 +183,9 @@ void LibjingleTransport::DoStart() { reconnect_timer_.Start( FROM_HERE, base::TimeDelta::FromSeconds(kReconnectDelaySeconds), this, &LibjingleTransport::TryReconnect); +} +void LibjingleTransport::NotifyConnected() { // Create net::Socket adapter for the P2PTransportChannel. scoped_ptr<jingle_glue::TransportChannelSocketAdapter> socket( new jingle_glue::TransportChannelSocketAdapter(channel_.get())); @@ -269,7 +274,13 @@ void LibjingleTransport::OnWritableState( DCHECK_EQ(channel, channel_.get()); if (channel->writable()) { - channel_was_writable_ = true; + if (!channel_was_writable_) { + channel_was_writable_ = true; + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, + base::Bind(&LibjingleTransport::NotifyConnected, + weak_factory_.GetWeakPtr())); + } connect_attempts_left_ = kMaxReconnectAttempts; reconnect_timer_.Stop(); } else if (!channel->writable() && channel_was_writable_) { |