diff options
author | sergeyu <sergeyu@chromium.org> | 2015-02-02 16:23:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-03 00:24:53 +0000 |
commit | dfb5e220446194f22436e2434f198f76f350e5b8 (patch) | |
tree | 6e0af2ef22f4bab1c5dd57d64e47527ace041cff /remoting/protocol | |
parent | 86bf1a4d7f179f5373bfeab5e8543d954762001d (diff) | |
download | chromium_src-dfb5e220446194f22436e2434f198f76f350e5b8.zip chromium_src-dfb5e220446194f22436e2434f198f76f350e5b8.tar.gz chromium_src-dfb5e220446194f22436e2434f198f76f350e5b8.tar.bz2 |
Fix LibjingleTransport to notify about route changes only when connected.
Previously LibjingleTransport was emitting RouteChange notification
even before connection is established. As result the reported results
were incorrect and confusing. Specifically it was always reporting
connection as direct first even if it ends up going through the relay.
Review URL: https://codereview.chromium.org/889043002
Cr-Commit-Position: refs/heads/master@{#314221}
Diffstat (limited to 'remoting/protocol')
-rw-r--r-- | remoting/protocol/libjingle_transport_factory.cc | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/remoting/protocol/libjingle_transport_factory.cc b/remoting/protocol/libjingle_transport_factory.cc index fe8a076..2c68d45 100644 --- a/remoting/protocol/libjingle_transport_factory.cc +++ b/remoting/protocol/libjingle_transport_factory.cc @@ -86,6 +86,8 @@ class LibjingleTransport // socket is destroyed. void OnChannelDestroyed(); + void NotifyRouteChanged(); + // Tries to connect by restarting ICE. Called by |reconnect_timer_|. void TryReconnect(); @@ -258,6 +260,44 @@ void LibjingleTransport::OnCandidateReady( void LibjingleTransport::OnRouteChange( cricket::TransportChannel* channel, const cricket::Candidate& candidate) { + // Ignore notifications if the channel is not writable. + if (channel_->writable()) + NotifyRouteChanged(); +} + +void LibjingleTransport::OnWritableState( + cricket::TransportChannel* channel) { + DCHECK_EQ(channel, channel_.get()); + + if (channel->writable()) { + 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(); + + // Route change notifications are ignored when the |channel_| is not + // writable. Notify the event handler about the current route once the + // channel is writable. + NotifyRouteChanged(); + } else if (!channel->writable() && channel_was_writable_) { + reconnect_timer_.Reset(); + TryReconnect(); + } +} + +void LibjingleTransport::OnChannelDestroyed() { + if (is_connected()) { + // The connection socket is being deleted, so delete the transport too. + delete this; + } +} + +void LibjingleTransport::NotifyRouteChanged() { TransportRoute route; DCHECK(channel_->best_connection()); @@ -276,7 +316,7 @@ void LibjingleTransport::OnRouteChange( CandidateTypeToTransportRouteType(connection->remote_candidate().type())); if (!jingle_glue::SocketAddressToIPEndPoint( - candidate.address(), &route.remote_address)) { + connection->remote_candidate().address(), &route.remote_address)) { LOG(FATAL) << "Failed to convert peer IP address."; } @@ -290,33 +330,6 @@ void LibjingleTransport::OnRouteChange( event_handler_->OnTransportRouteChange(this, route); } -void LibjingleTransport::OnWritableState( - cricket::TransportChannel* channel) { - DCHECK_EQ(channel, channel_.get()); - - if (channel->writable()) { - 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_) { - reconnect_timer_.Reset(); - TryReconnect(); - } -} - -void LibjingleTransport::OnChannelDestroyed() { - if (is_connected()) { - // The connection socket is being deleted, so delete the transport too. - delete this; - } -} - void LibjingleTransport::TryReconnect() { DCHECK(!channel_->writable()); |