diff --git a/remoting/protocol/channel_multiplexer.cc b/remoting/protocol/channel_multiplexer.cc index 6674d84bde9fb..88098be399d13 100644 --- a/remoting/protocol/channel_multiplexer.cc +++ b/remoting/protocol/channel_multiplexer.cc @@ -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( diff --git a/remoting/protocol/channel_multiplexer.h b/remoting/protocol/channel_multiplexer.h index 4846bdf949251..c7fe5456767be 100644 --- a/remoting/protocol/channel_multiplexer.h +++ b/remoting/protocol/channel_multiplexer.h @@ -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: diff --git a/remoting/protocol/datagram_channel_factory.h b/remoting/protocol/datagram_channel_factory.h index d82960a796fb9..daa9648542c7d 100644 --- a/remoting/protocol/datagram_channel_factory.h +++ b/remoting/protocol/datagram_channel_factory.h @@ -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 diff --git a/remoting/protocol/fake_datagram_socket.cc b/remoting/protocol/fake_datagram_socket.cc index 016726fa86326..f1f648d5d6507 100644 --- a/remoting/protocol/fake_datagram_socket.cc +++ b/remoting/protocol/fake_datagram_socket.cc @@ -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( diff --git a/remoting/protocol/fake_datagram_socket.h b/remoting/protocol/fake_datagram_socket.h index 71884b6d3da99..9456bdcf9da6b 100644 --- a/remoting/protocol/fake_datagram_socket.h +++ b/remoting/protocol/fake_datagram_socket.h @@ -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_; diff --git a/remoting/protocol/fake_stream_socket.cc b/remoting/protocol/fake_stream_socket.cc index 7d12d4f62fa81..3f653b45ad602 100644 --- a/remoting/protocol/fake_stream_socket.cc +++ b/remoting/protocol/fake_stream_socket.cc @@ -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) { diff --git a/remoting/protocol/fake_stream_socket.h b/remoting/protocol/fake_stream_socket.h index 1d2e7a6167c69..088049b9b0573 100644 --- a/remoting/protocol/fake_stream_socket.h +++ b/remoting/protocol/fake_stream_socket.h @@ -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; diff --git a/remoting/protocol/ice_transport.cc b/remoting/protocol/ice_transport.cc index 8663647c30783..a4e658c2a154d 100644 --- a/remoting/protocol/ice_transport.cc +++ b/remoting/protocol/ice_transport.cc @@ -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(); } diff --git a/remoting/protocol/ice_transport.h b/remoting/protocol/ice_transport.h index 7f1b715ce0d03..21b6df28716df 100644 --- a/remoting/protocol/ice_transport.h +++ b/remoting/protocol/ice_transport.h @@ -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 diff --git a/remoting/protocol/ice_transport_channel.cc b/remoting/protocol/ice_transport_channel.cc index 4b5183364c428..fe6ea988f82ad 100644 --- a/remoting/protocol/ice_transport_channel.cc +++ b/remoting/protocol/ice_transport_channel.cc @@ -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( diff --git a/remoting/protocol/ice_transport_channel.h b/remoting/protocol/ice_transport_channel.h index 9f0d182a02a40..c89f2773be9d8 100644 --- a/remoting/protocol/ice_transport_channel.h +++ b/remoting/protocol/ice_transport_channel.h @@ -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, diff --git a/remoting/protocol/message_channel_factory.h b/remoting/protocol/message_channel_factory.h index a9ecc44b7e543..d0cd6f0ca0a20 100644 --- a/remoting/protocol/message_channel_factory.h +++ b/remoting/protocol/message_channel_factory.h @@ -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 diff --git a/remoting/protocol/performance_tracker.h b/remoting/protocol/performance_tracker.h index 1f3c6b6629543..a8acc337dcae3 100644 --- a/remoting/protocol/performance_tracker.h +++ b/remoting/protocol/performance_tracker.h @@ -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; diff --git a/remoting/protocol/pseudotcp_adapter.cc b/remoting/protocol/pseudotcp_adapter.cc index 9c8164650b6a9..bdb467f87c2e6 100644 --- a/remoting/protocol/pseudotcp_adapter.cc +++ b/remoting/protocol/pseudotcp_adapter.cc @@ -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)); } diff --git a/remoting/protocol/pseudotcp_adapter.h b/remoting/protocol/pseudotcp_adapter.h index 937530c9b89ae..54725c5dfaed4 100644 --- a/remoting/protocol/pseudotcp_adapter.h +++ b/remoting/protocol/pseudotcp_adapter.h @@ -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); diff --git a/remoting/protocol/pseudotcp_adapter_unittest.cc b/remoting/protocol/pseudotcp_adapter_unittest.cc index 1f0a8d7fc2b81..bd22c32d26429 100644 --- a/remoting/protocol/pseudotcp_adapter_unittest.cc +++ b/remoting/protocol/pseudotcp_adapter_unittest.cc @@ -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(), diff --git a/remoting/protocol/pseudotcp_channel_factory.cc b/remoting/protocol/pseudotcp_channel_factory.cc index 1fe4cfaace9c9..6d6669094c6a1 100644 --- a/remoting/protocol/pseudotcp_channel_factory.cc +++ b/remoting/protocol/pseudotcp_channel_factory.cc @@ -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 diff --git a/remoting/protocol/pseudotcp_channel_factory.h b/remoting/protocol/pseudotcp_channel_factory.h index a8a509dc14a86..bf21d3b76f684 100644 --- a/remoting/protocol/pseudotcp_channel_factory.h +++ b/remoting/protocol/pseudotcp_channel_factory.h @@ -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_; diff --git a/remoting/protocol/secure_channel_factory.cc b/remoting/protocol/secure_channel_factory.cc index d87063e9b0628..f52fa3bd520be 100644 --- a/remoting/protocol/secure_channel_factory.cc +++ b/remoting/protocol/secure_channel_factory.cc @@ -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 diff --git a/remoting/protocol/secure_channel_factory.h b/remoting/protocol/secure_channel_factory.h index b348ffe77b74d..0212e2c371c5c 100644 --- a/remoting/protocol/secure_channel_factory.h +++ b/remoting/protocol/secure_channel_factory.h @@ -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); diff --git a/remoting/protocol/stream_channel_factory.h b/remoting/protocol/stream_channel_factory.h index e078659a6b31e..8014d5dcf253c 100644 --- a/remoting/protocol/stream_channel_factory.h +++ b/remoting/protocol/stream_channel_factory.h @@ -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 diff --git a/remoting/protocol/stream_message_pipe_adapter.cc b/remoting/protocol/stream_message_pipe_adapter.cc index afae55e914a2c..17ba74d06abb8 100644 --- a/remoting/protocol/stream_message_pipe_adapter.cc +++ b/remoting/protocol/stream_message_pipe_adapter.cc @@ -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 diff --git a/remoting/protocol/stream_message_pipe_adapter.h b/remoting/protocol/stream_message_pipe_adapter.h index 2901250c0e441..3bcb96c2156aa 100644 --- a/remoting/protocol/stream_message_pipe_adapter.h +++ b/remoting/protocol/stream_message_pipe_adapter.h @@ -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_; diff --git a/remoting/protocol/transport.h b/remoting/protocol/transport.h index 7d06ab54a081d..cf4b7e3182211 100644 --- a/remoting/protocol/transport.h +++ b/remoting/protocol/transport.h @@ -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() {} diff --git a/remoting/protocol/transport_context.cc b/remoting/protocol/transport_context.cc index f35d0a3b1092f..ff9c0e08e0847 100644 --- a/remoting/protocol/transport_context.cc +++ b/remoting/protocol/transport_context.cc @@ -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(); } } diff --git a/remoting/protocol/transport_context.h b/remoting/protocol/transport_context.h index 149e5a36ee139..c1ccc9cb53b7b 100644 --- a/remoting/protocol/transport_context.h +++ b/remoting/protocol/transport_context.h @@ -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();