0

Update some callbacks to Once/Repeating in //remoting/protocol.

Bug: 1007826
Change-Id: I5bc7931f3e9f7009f6566f03028c07df3ae1695a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225486
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774457}
This commit is contained in:
Evan Stade
2020-06-03 02:34:33 +00:00
committed by Commit Bot
parent 33ae7ac6aa
commit 3f80bc3cc7
26 changed files with 123 additions and 123 deletions

@ -55,10 +55,8 @@ class PendingPacket {
const char ChannelMultiplexer::kMuxChannelName[] = "mux";
struct ChannelMultiplexer::PendingChannel {
PendingChannel(const std::string& name,
const ChannelCreatedCallback& callback)
: name(name), callback(callback) {
}
PendingChannel(const std::string& name, ChannelCreatedCallback callback)
: name(name), callback(std::move(callback)) {}
std::string name;
ChannelCreatedCallback callback;
};
@ -325,17 +323,17 @@ ChannelMultiplexer::~ChannelMultiplexer() {
}
void ChannelMultiplexer::CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
if (base_channel_.get()) {
// Already have |base_channel_|. Create new multiplexed channel
// synchronously.
callback.Run(GetOrCreateChannel(name)->CreateSocket());
std::move(callback).Run(GetOrCreateChannel(name)->CreateSocket());
} else if (!base_channel_.get() && !base_channel_factory_) {
// Fail synchronously if we failed to create |base_channel_|.
callback.Run(nullptr);
std::move(callback).Run(nullptr);
} else {
// Still waiting for the |base_channel_|.
pending_channels_.push_back(PendingChannel(name, callback));
pending_channels_.emplace_back(name, std::move(callback));
// If this is the first multiplexed channel then create the base channel.
if (pending_channels_.size() == 1U) {
@ -390,12 +388,12 @@ void ChannelMultiplexer::DoCreatePendingChannels() {
FROM_HERE, base::BindOnce(&ChannelMultiplexer::DoCreatePendingChannels,
weak_factory_.GetWeakPtr()));
PendingChannel c = pending_channels_.front();
PendingChannel c = std::move(pending_channels_.front());
pending_channels_.erase(pending_channels_.begin());
std::unique_ptr<P2PStreamSocket> socket;
if (base_channel_.get())
socket = GetOrCreateChannel(c.name)->CreateSocket();
c.callback.Run(std::move(socket));
std::move(c.callback).Run(std::move(socket));
}
ChannelMultiplexer::MuxChannel* ChannelMultiplexer::GetOrCreateChannel(

@ -29,7 +29,7 @@ class ChannelMultiplexer : public StreamChannelFactory {
// StreamChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:

@ -18,7 +18,7 @@ class P2PDatagramSocket;
class DatagramChannelFactory {
public:
typedef base::Callback<void(std::unique_ptr<P2PDatagramSocket>)>
typedef base::OnceCallback<void(std::unique_ptr<P2PDatagramSocket>)>
ChannelCreatedCallback;
DatagramChannelFactory() {}
@ -30,7 +30,7 @@ class DatagramChannelFactory {
// CancelChannelCreation() called for any pending channels, before the factory
// is destroyed.
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) = 0;
ChannelCreatedCallback callback) = 0;
// Cancels a pending CreateChannel() operation for the named channel. If the
// channel creation already completed then canceling it has no effect. When

@ -148,7 +148,7 @@ FakeDatagramSocket* FakeDatagramChannelFactory::GetFakeChannel(
void FakeDatagramChannelFactory::CreateChannel(
const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
EXPECT_FALSE(channels_[name]);
std::unique_ptr<FakeDatagramSocket> channel(new FakeDatagramSocket());
@ -168,18 +168,18 @@ void FakeDatagramChannelFactory::CreateChannel(
FROM_HERE,
base::BindOnce(&FakeDatagramChannelFactory::NotifyChannelCreated,
weak_factory_.GetWeakPtr(), std::move(channel), name,
callback));
std::move(callback)));
} else {
NotifyChannelCreated(std::move(channel), name, callback);
NotifyChannelCreated(std::move(channel), name, std::move(callback));
}
}
void FakeDatagramChannelFactory::NotifyChannelCreated(
std::unique_ptr<FakeDatagramSocket> owned_socket,
const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
if (channels_.find(name) != channels_.end())
callback.Run(std::move(owned_socket));
std::move(callback).Run(std::move(owned_socket));
}
void FakeDatagramChannelFactory::CancelChannelCreation(

@ -120,7 +120,7 @@ class FakeDatagramChannelFactory : public DatagramChannelFactory {
// DatagramChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:
@ -128,7 +128,7 @@ class FakeDatagramChannelFactory : public DatagramChannelFactory {
void NotifyChannelCreated(std::unique_ptr<FakeDatagramSocket> owned_socket,
const std::string& name,
const ChannelCreatedCallback& callback);
ChannelCreatedCallback callback);
base::WeakPtr<FakeDatagramChannelFactory> peer_factory_;

@ -168,9 +168,8 @@ void FakeStreamChannelFactory::PairWith(
peer_factory->peer_factory_ = weak_factory_.GetWeakPtr();
}
void FakeStreamChannelFactory::CreateChannel(
const std::string& name,
const ChannelCreatedCallback& callback) {
void FakeStreamChannelFactory::CreateChannel(const std::string& name,
ChannelCreatedCallback callback) {
std::unique_ptr<FakeStreamSocket> channel(new FakeStreamSocket());
channels_[name] = channel->GetWeakPtr();
channel->set_async_write(async_write_);
@ -189,18 +188,18 @@ void FakeStreamChannelFactory::CreateChannel(
FROM_HERE,
base::BindOnce(&FakeStreamChannelFactory::NotifyChannelCreated,
weak_factory_.GetWeakPtr(), std::move(channel), name,
callback));
std::move(callback)));
} else {
NotifyChannelCreated(std::move(channel), name, callback);
NotifyChannelCreated(std::move(channel), name, std::move(callback));
}
}
void FakeStreamChannelFactory::NotifyChannelCreated(
std::unique_ptr<FakeStreamSocket> owned_channel,
const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
if (channels_.find(name) != channels_.end())
callback.Run(std::move(owned_channel));
std::move(callback).Run(std::move(owned_channel));
}
void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) {

@ -130,13 +130,13 @@ class FakeStreamChannelFactory : public StreamChannelFactory {
// ChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:
void NotifyChannelCreated(std::unique_ptr<FakeStreamSocket> owned_channel,
const std::string& name,
const ChannelCreatedCallback& callback);
ChannelCreatedCallback callback);
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
bool asynchronous_create_ = false;

@ -97,12 +97,12 @@ MessageChannelFactory* IceTransport::GetMultiplexedChannelFactory() {
}
void IceTransport::CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
DCHECK(!channels_[name]);
std::unique_ptr<IceTransportChannel> channel(
new IceTransportChannel(transport_context_));
channel->Connect(name, this, callback);
channel->Connect(name, this, std::move(callback));
AddPendingRemoteTransportInfo(channel.get());
channels_[name] = channel.release();
}

@ -56,7 +56,7 @@ class IceTransport : public Transport,
// DatagramChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
// Passes transport info to a new |channel| in case it was received before the

@ -71,7 +71,7 @@ IceTransportChannel::~IceTransportChannel() {
void IceTransportChannel::Connect(const std::string& name,
Delegate* delegate,
const ConnectedCallback& callback) {
ConnectedCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!name.empty());
DCHECK(delegate);
@ -80,7 +80,7 @@ void IceTransportChannel::Connect(const std::string& name,
DCHECK(name_.empty());
name_ = name;
delegate_ = delegate;
callback_ = callback;
callback_ = std::move(callback);
port_allocator_ =
transport_context_->port_allocator_factory()->CreatePortAllocator(

@ -65,7 +65,7 @@ class IceTransportChannel : public sigslot::has_slots<> {
virtual void OnChannelDeleted(IceTransportChannel* transport) = 0;
};
typedef base::Callback<void(std::unique_ptr<P2PDatagramSocket>)>
typedef base::OnceCallback<void(std::unique_ptr<P2PDatagramSocket>)>
ConnectedCallback;
explicit IceTransportChannel(
@ -75,7 +75,7 @@ class IceTransportChannel : public sigslot::has_slots<> {
// Connects the channel and calls the |callback| after that.
void Connect(const std::string& name,
Delegate* delegate,
const ConnectedCallback& callback);
ConnectedCallback callback);
// Sets remote ICE credentials.
void SetRemoteCredentials(const std::string& ufrag,

@ -17,7 +17,7 @@ class MessagePipe;
class MessageChannelFactory {
public:
typedef base::Callback<void(std::unique_ptr<MessagePipe>)>
typedef base::OnceCallback<void(std::unique_ptr<MessagePipe>)>
ChannelCreatedCallback;
virtual ~MessageChannelFactory() {}
@ -28,7 +28,7 @@ class MessageChannelFactory {
// channels must be destroyed, and CancelChannelCreation() called for any
// pending channels, before the factory is destroyed.
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) = 0;
ChannelCreatedCallback callback) = 0;
// Cancels a pending CreateChannel() operation for the named channel. If the
// channel creation already completed then canceling it has no effect. When

@ -22,15 +22,15 @@ namespace protocol {
class PerformanceTracker : public FrameStatsConsumer {
public:
// Callback that updates UMA custom counts or custom times histograms.
typedef base::Callback<void(const std::string& histogram_name,
int64_t value,
int histogram_min,
int histogram_max,
int histogram_buckets)>
typedef base::RepeatingCallback<void(const std::string& histogram_name,
int64_t value,
int histogram_min,
int histogram_max,
int histogram_buckets)>
UpdateUmaCustomHistogramCallback;
// Callback that updates UMA enumeration histograms.
typedef base::Callback<
typedef base::RepeatingCallback<
void(const std::string& histogram_name, int64_t value, int histogram_max)>
UpdateUmaEnumHistogramCallback;

@ -44,7 +44,7 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
int buffer_size,
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation);
int Connect(net::CompletionOnceCallback callback);
net::CompletionOnceCallback Connect(net::CompletionOnceCallback callback);
// cricket::IPseudoTcpNotify interface.
// These notifications are triggered from NotifyPacket.
@ -200,7 +200,8 @@ int PseudoTcpAdapter::Core::Write(
return result;
}
int PseudoTcpAdapter::Core::Connect(net::CompletionOnceCallback callback) {
net::CompletionOnceCallback PseudoTcpAdapter::Core::Connect(
net::CompletionOnceCallback callback) {
DCHECK_EQ(pseudo_tcp_.State(), cricket::PseudoTcp::TCP_LISTEN);
// Reference the Core in case a callback deletes the adapter.
@ -209,22 +210,21 @@ int PseudoTcpAdapter::Core::Connect(net::CompletionOnceCallback callback) {
// Start the connection attempt.
int result = pseudo_tcp_.Connect();
if (result < 0)
return net::ERR_FAILED;
return callback;
AdjustClock();
connect_callback_ = std::move(callback);
DoReadFromSocket();
return net::ERR_IO_PENDING;
return {};
}
void PseudoTcpAdapter::Core::OnTcpOpen(PseudoTcp* tcp) {
DCHECK(tcp == &pseudo_tcp_);
if (!connect_callback_.is_null()) {
if (connect_callback_)
std::move(connect_callback_).Run(net::OK);
}
OnTcpReadable(tcp);
OnTcpWriteable(tcp);
@ -482,7 +482,8 @@ int PseudoTcpAdapter::SetSendBufferSize(int32_t size) {
return net::OK;
}
int PseudoTcpAdapter::Connect(net::CompletionOnceCallback callback) {
net::CompletionOnceCallback PseudoTcpAdapter::Connect(
net::CompletionOnceCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return core_->Connect(std::move(callback));
}

@ -43,7 +43,10 @@ class PseudoTcpAdapter : public P2PStreamSocket {
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) override;
int Connect(net::CompletionOnceCallback callback);
// If the connection succeeds, this will take ownership of |callback| and
// return a null callback. If it fails, |callback| will be passed back to the
// caller.
net::CompletionOnceCallback Connect(net::CompletionOnceCallback callback);
// Set receive and send buffer sizes.
int SetReceiveBufferSize(int32_t size);

@ -322,15 +322,15 @@ TEST_F(PseudoTcpAdapterTest, DataTransfer) {
net::TestCompletionCallback host_connect_cb;
net::TestCompletionCallback client_connect_cb;
int rv1 = host_pseudotcp_->Connect(host_connect_cb.callback());
int rv2 = client_pseudotcp_->Connect(client_connect_cb.callback());
net::CompletionOnceCallback rv1 =
host_pseudotcp_->Connect(host_connect_cb.callback());
ASSERT_FALSE(rv1);
net::CompletionOnceCallback rv2 =
client_pseudotcp_->Connect(client_connect_cb.callback());
ASSERT_FALSE(rv2);
if (rv1 == net::ERR_IO_PENDING)
rv1 = host_connect_cb.WaitForResult();
if (rv2 == net::ERR_IO_PENDING)
rv2 = client_connect_cb.WaitForResult();
ASSERT_EQ(net::OK, rv1);
ASSERT_EQ(net::OK, rv2);
EXPECT_EQ(net::OK, host_connect_cb.WaitForResult());
EXPECT_EQ(net::OK, client_connect_cb.WaitForResult());
scoped_refptr<TCPChannelTester> tester =
new TCPChannelTester(base::ThreadTaskRunnerHandle::Get(),
@ -357,15 +357,15 @@ TEST_F(PseudoTcpAdapterTest, LimitedChannel) {
net::TestCompletionCallback host_connect_cb;
net::TestCompletionCallback client_connect_cb;
int rv1 = host_pseudotcp_->Connect(host_connect_cb.callback());
int rv2 = client_pseudotcp_->Connect(client_connect_cb.callback());
net::CompletionOnceCallback rv1 =
host_pseudotcp_->Connect(host_connect_cb.callback());
ASSERT_FALSE(rv1);
net::CompletionOnceCallback rv2 =
client_pseudotcp_->Connect(client_connect_cb.callback());
ASSERT_FALSE(rv2);
if (rv1 == net::ERR_IO_PENDING)
rv1 = host_connect_cb.WaitForResult();
if (rv2 == net::ERR_IO_PENDING)
rv2 = client_connect_cb.WaitForResult();
ASSERT_EQ(net::OK, rv1);
ASSERT_EQ(net::OK, rv2);
EXPECT_EQ(net::OK, host_connect_cb.WaitForResult());
EXPECT_EQ(net::OK, client_connect_cb.WaitForResult());
scoped_refptr<TCPChannelTester> tester =
new TCPChannelTester(base::ThreadTaskRunnerHandle::Get(),
@ -419,15 +419,15 @@ TEST_F(PseudoTcpAdapterTest, WriteWaitsForSendLetsDataThrough) {
// enabled.
host_pseudotcp_->SetNoDelay(true);
int rv1 = host_pseudotcp_->Connect(host_connect_cb.callback());
int rv2 = client_pseudotcp_->Connect(client_connect_cb.callback());
net::CompletionOnceCallback rv1 =
host_pseudotcp_->Connect(host_connect_cb.callback());
ASSERT_FALSE(rv1);
net::CompletionOnceCallback rv2 =
client_pseudotcp_->Connect(client_connect_cb.callback());
ASSERT_FALSE(rv2);
if (rv1 == net::ERR_IO_PENDING)
rv1 = host_connect_cb.WaitForResult();
if (rv2 == net::ERR_IO_PENDING)
rv2 = client_connect_cb.WaitForResult();
ASSERT_EQ(net::OK, rv1);
ASSERT_EQ(net::OK, rv2);
EXPECT_EQ(net::OK, host_connect_cb.WaitForResult());
EXPECT_EQ(net::OK, client_connect_cb.WaitForResult());
scoped_refptr<TCPChannelTester> tester =
new TCPChannelTester(base::ThreadTaskRunnerHandle::Get(),

@ -39,13 +39,11 @@ PseudoTcpChannelFactory::~PseudoTcpChannelFactory() {
DCHECK(pending_sockets_.empty());
}
void PseudoTcpChannelFactory::CreateChannel(
const std::string& name,
const ChannelCreatedCallback& callback) {
void PseudoTcpChannelFactory::CreateChannel(const std::string& name,
ChannelCreatedCallback callback) {
datagram_channel_factory_->CreateChannel(
name,
base::Bind(&PseudoTcpChannelFactory::OnDatagramChannelCreated,
base::Unretained(this), name, callback));
name, base::BindOnce(&PseudoTcpChannelFactory::OnDatagramChannelCreated,
base::Unretained(this), name, std::move(callback)));
}
void PseudoTcpChannelFactory::CancelChannelCreation(const std::string& name) {
@ -60,7 +58,7 @@ void PseudoTcpChannelFactory::CancelChannelCreation(const std::string& name) {
void PseudoTcpChannelFactory::OnDatagramChannelCreated(
const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
std::unique_ptr<P2PDatagramSocket> datagram_socket) {
PseudoTcpAdapter* adapter = new PseudoTcpAdapter(std::move(datagram_socket));
pending_sockets_[name] = adapter;
@ -75,16 +73,16 @@ void PseudoTcpChannelFactory::OnDatagramChannelCreated(
if (name == kVideoChannelName)
adapter->SetWriteWaitsForSend(true);
int result = adapter->Connect(
net::CompletionOnceCallback returned_callback = adapter->Connect(
base::BindOnce(&PseudoTcpChannelFactory::OnPseudoTcpConnected,
base::Unretained(this), name, callback));
if (result != net::ERR_IO_PENDING)
OnPseudoTcpConnected(name, callback, result);
base::Unretained(this), name, std::move(callback)));
if (returned_callback)
std::move(returned_callback).Run(net::ERR_FAILED);
}
void PseudoTcpChannelFactory::OnPseudoTcpConnected(
const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
int result) {
auto it = pending_sockets_.find(name);
DCHECK(it != pending_sockets_.end());
@ -94,7 +92,7 @@ void PseudoTcpChannelFactory::OnPseudoTcpConnected(
if (result != net::OK)
socket.reset();
callback.Run(std::move(socket));
std::move(callback).Run(std::move(socket));
}
} // namespace protocol

@ -27,17 +27,17 @@ class PseudoTcpChannelFactory : public StreamChannelFactory {
// StreamChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:
typedef std::map<std::string, P2PStreamSocket*> PendingSocketsMap;
void OnDatagramChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
std::unique_ptr<P2PDatagramSocket> socket);
void OnPseudoTcpConnected(const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
int result);
DatagramChannelFactory* datagram_channel_factory_;

@ -27,14 +27,12 @@ SecureChannelFactory::~SecureChannelFactory() {
DCHECK(channel_authenticators_.empty());
}
void SecureChannelFactory::CreateChannel(
const std::string& name,
const ChannelCreatedCallback& callback) {
void SecureChannelFactory::CreateChannel(const std::string& name,
ChannelCreatedCallback callback) {
DCHECK(!callback.is_null());
channel_factory_->CreateChannel(
name,
base::Bind(&SecureChannelFactory::OnBaseChannelCreated,
base::Unretained(this), name, callback));
name, base::BindOnce(&SecureChannelFactory::OnBaseChannelCreated,
base::Unretained(this), name, std::move(callback)));
}
void SecureChannelFactory::CancelChannelCreation(
@ -50,10 +48,10 @@ void SecureChannelFactory::CancelChannelCreation(
void SecureChannelFactory::OnBaseChannelCreated(
const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
std::unique_ptr<P2PStreamSocket> socket) {
if (!socket) {
callback.Run(nullptr);
std::move(callback).Run(nullptr);
return;
}
@ -63,12 +61,13 @@ void SecureChannelFactory::OnBaseChannelCreated(
channel_authenticator->SecureAndAuthenticate(
std::move(socket),
base::Bind(&SecureChannelFactory::OnSecureChannelCreated,
base::Unretained(this), name, callback));
base::Unretained(this), name,
base::Passed(std::move(callback))));
}
void SecureChannelFactory::OnSecureChannelCreated(
const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
int error,
std::unique_ptr<P2PStreamSocket> socket) {
DCHECK((socket && error == net::OK) || (!socket && error != net::OK));
@ -78,7 +77,7 @@ void SecureChannelFactory::OnSecureChannelCreated(
delete it->second;
channel_authenticators_.erase(it);
callback.Run(std::move(socket));
std::move(callback).Run(std::move(socket));
}
} // namespace protocol

@ -31,18 +31,18 @@ class SecureChannelFactory : public StreamChannelFactory {
// StreamChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:
typedef std::map<std::string, ChannelAuthenticator*> AuthenticatorMap;
void OnBaseChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
std::unique_ptr<P2PStreamSocket> socket);
void OnSecureChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
int error,
std::unique_ptr<P2PStreamSocket> socket);

@ -21,7 +21,7 @@ class StreamChannelFactory {
public:
// TODO(sergeyu): Specify connection error code when channel
// connection fails.
typedef base::Callback<void(std::unique_ptr<P2PStreamSocket>)>
typedef base::OnceCallback<void(std::unique_ptr<P2PStreamSocket>)>
ChannelCreatedCallback;
StreamChannelFactory() {}
@ -32,7 +32,7 @@ class StreamChannelFactory {
// call returns. All channels must be destroyed, and CancelChannelCreation()
// called for any pending channels, before the factory is destroyed.
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) = 0;
ChannelCreatedCallback callback) = 0;
// Cancels a pending CreateChannel() operation for the named channel. If the
// channel creation already completed then canceling it has no effect. When

@ -104,10 +104,11 @@ StreamMessageChannelFactoryAdapter::~StreamMessageChannelFactoryAdapter() =
void StreamMessageChannelFactoryAdapter::CreateChannel(
const std::string& name,
const ChannelCreatedCallback& callback) {
ChannelCreatedCallback callback) {
stream_channel_factory_->CreateChannel(
name, base::Bind(&StreamMessageChannelFactoryAdapter::OnChannelCreated,
base::Unretained(this), callback));
name,
base::BindOnce(&StreamMessageChannelFactoryAdapter::OnChannelCreated,
base::Unretained(this), std::move(callback)));
}
void StreamMessageChannelFactoryAdapter::CancelChannelCreation(
@ -116,14 +117,14 @@ void StreamMessageChannelFactoryAdapter::CancelChannelCreation(
}
void StreamMessageChannelFactoryAdapter::OnChannelCreated(
const ChannelCreatedCallback& callback,
ChannelCreatedCallback callback,
std::unique_ptr<P2PStreamSocket> socket) {
if (!socket) {
error_callback_.Run(net::ERR_FAILED);
return;
}
callback.Run(std::make_unique<StreamMessagePipeAdapter>(std::move(socket),
error_callback_));
std::move(callback).Run(std::make_unique<StreamMessagePipeAdapter>(
std::move(socket), error_callback_));
}
} // namespace protocol

@ -58,11 +58,11 @@ class StreamMessageChannelFactoryAdapter : public MessageChannelFactory {
// MessageChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
ChannelCreatedCallback callback) override;
void CancelChannelCreation(const std::string& name) override;
private:
void OnChannelCreated(const ChannelCreatedCallback& callback,
void OnChannelCreated(ChannelCreatedCallback callback,
std::unique_ptr<P2PStreamSocket> socket);
StreamChannelFactory* stream_channel_factory_;

@ -51,7 +51,8 @@ struct TransportRoute {
// Implementations should provide other methods to send and receive data.
class Transport {
public:
typedef base::Callback<void(std::unique_ptr<jingle_xmpp::XmlElement> transport_info)>
typedef base::RepeatingCallback<void(
std::unique_ptr<jingle_xmpp::XmlElement> transport_info)>
SendTransportInfoCallback;
virtual ~Transport() {}

@ -80,17 +80,17 @@ void TransportContext::Prepare() {
EnsureFreshIceConfig();
}
void TransportContext::GetIceConfig(const GetIceConfigCallback& callback) {
void TransportContext::GetIceConfig(GetIceConfigCallback callback) {
EnsureFreshIceConfig();
// If there is a pending |ice_config_request_| then delay the callback until
// the request is finished.
if (ice_config_request_) {
pending_ice_config_callbacks_.push_back(callback);
pending_ice_config_callbacks_.push_back(std::move(callback));
} else {
HOST_LOG << "Using cached ICE Config.";
PrintIceConfig(ice_config_);
callback.Run(ice_config_);
std::move(callback).Run(ice_config_);
}
}
@ -133,7 +133,7 @@ void TransportContext::OnIceConfig(const IceConfig& ice_config) {
auto& callback_list = pending_ice_config_callbacks_;
while (!callback_list.empty()) {
callback_list.begin()->Run(ice_config);
std::move(callback_list.front()).Run(ice_config);
callback_list.pop_front();
}
}

@ -34,7 +34,7 @@ class IceConfigRequest;
// TURN configuration.
class TransportContext : public base::RefCountedThreadSafe<TransportContext> {
public:
typedef base::Callback<void(const IceConfig& ice_config)>
typedef base::OnceCallback<void(const IceConfig& ice_config)>
GetIceConfigCallback;
static scoped_refptr<TransportContext> ForTests(TransportRole role);
@ -69,7 +69,7 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> {
void Prepare();
// Requests fresh STUN and TURN information.
void GetIceConfig(const GetIceConfigCallback& callback);
void GetIceConfig(GetIceConfigCallback callback);
PortAllocatorFactory* port_allocator_factory() {
return port_allocator_factory_.get();