Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix LibjingleTransport not to wait for channel to be writable.
Browse files Browse the repository at this point in the history
Previously LibjingleTransport was waiting for channel to be become
writable before considering it to be connected. As result it was loosing
all data that's received before the channel is marked as writable.

BUG=477142

Review URL: https://codereview.chromium.org/1080633005

Cr-Commit-Position: refs/heads/master@{#325347}
(cherry picked from commit 42df610)

TBR=sergeyu@chromium.org

Review URL: https://codereview.chromium.org/1101723003

Cr-Commit-Position: refs/branch-heads/2357@{#198}
Cr-Branched-From: 59d4494-refs/heads/master@{#323860}
  • Loading branch information
SergeyUlanov committed Apr 22, 2015
1 parent 92f7816 commit 49ecf0e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions remoting/protocol/libjingle_transport_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "base/timer/timer.h"
Expand Down Expand Up @@ -56,7 +57,7 @@ class LibjingleTransport
public sigslot::has_slots<> {
public:
LibjingleTransport(cricket::PortAllocator* port_allocator,
const NetworkSettings& network_settings);
const NetworkSettings& network_settings);
~LibjingleTransport() override;

// Called by JingleTransportFactory when it has fresh Jingle info.
Expand Down Expand Up @@ -104,7 +105,6 @@ class LibjingleTransport

std::list<cricket::Candidate> pending_candidates_;
scoped_ptr<cricket::P2PTransportChannel> channel_;
bool channel_was_writable_;
int connect_attempts_left_;
base::RepeatingTimer<LibjingleTransport> reconnect_timer_;

Expand All @@ -122,7 +122,6 @@ LibjingleTransport::LibjingleTransport(cricket::PortAllocator* port_allocator,
rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)),
ice_password_(rtc::CreateRandomString(cricket::ICE_PWD_LENGTH)),
can_start_(false),
channel_was_writable_(false),
connect_attempts_left_(kMaxReconnectAttempts),
weak_factory_(this) {
DCHECK(!ice_username_fragment_.empty());
Expand Down Expand Up @@ -202,6 +201,10 @@ void LibjingleTransport::DoStart() {
reconnect_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(kReconnectDelaySeconds),
this, &LibjingleTransport::TryReconnect);

base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&LibjingleTransport::NotifyConnected,
weak_factory_.GetWeakPtr()));
}

void LibjingleTransport::NotifyConnected() {
Expand All @@ -210,10 +213,7 @@ void LibjingleTransport::NotifyConnected() {
new jingle_glue::TransportChannelSocketAdapter(channel_.get()));
socket->SetOnDestroyedCallback(base::Bind(
&LibjingleTransport::OnChannelDestroyed, base::Unretained(this)));

Transport::ConnectedCallback callback = callback_;
callback_.Reset();
callback.Run(socket.Pass());
base::ResetAndReturn(&callback_).Run(socket.Pass());
}

void LibjingleTransport::AddRemoteCandidate(
Expand Down Expand Up @@ -270,31 +270,22 @@ void LibjingleTransport::OnWritableState(
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_) {
} else {
reconnect_timer_.Reset();
TryReconnect();
}
}

void LibjingleTransport::OnChannelDestroyed() {
if (is_connected()) {
// The connection socket is being deleted, so delete the transport too.
delete this;
}
// The connection socket is being deleted, so delete the transport too.
delete this;
}

void LibjingleTransport::NotifyRouteChanged() {
Expand Down

0 comments on commit 49ecf0e

Please sign in to comment.