Commit 9b75bb0c authored by Jose Lopes's avatar Jose Lopes Committed by Commit Bot

media: Migrate PacketReceiverCallbackWithStatus to repeating callback.

This is a repeating callback because it is run by an event handler:
* https://cs.chromium.org/chromium/src/components/mirroring/service/udp_socket_client.cc?rcl=9de1b156267c48a11dcd12948c1ab7bfe81fd008&l=164

and it is also called repeatedly from a while loop:
* https://cs.chromium.org/chromium/src/media/cast/net/udp_transport_impl.cc?rcl=9de1b156267c48a11dcd12948c1ab7bfe81fd008&l=208
* https://cs.chromium.org/chromium/src/media/cast/net/udp_transport_impl.cc?rcl=9de1b156267c48a11dcd12948c1ab7bfe81fd008&l=217

This is part of the base::Callback migration.

Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40

Bug: 714018
Change-Id: I265bfe00a5063e85a3461533019bfbc4f598f609
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073763
Commit-Queue: Jose Lopes <jabolopes@google.com>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745421}
parent 2d18a660
...@@ -101,9 +101,9 @@ int64_t UdpSocketClient::GetBytesSent() { ...@@ -101,9 +101,9 @@ int64_t UdpSocketClient::GetBytesSent() {
} }
void UdpSocketClient::StartReceiving( void UdpSocketClient::StartReceiving(
const media::cast::PacketReceiverCallbackWithStatus& packet_receiver) { media::cast::PacketReceiverCallbackWithStatus packet_receiver) {
DVLOG(1) << __func__; DVLOG(1) << __func__;
packet_receiver_callback_ = packet_receiver; packet_receiver_callback_ = std::move(packet_receiver);
network_context_->CreateUDPSocket(udp_socket_.BindNewPipeAndPassReceiver(), network_context_->CreateUDPSocket(udp_socket_.BindNewPipeAndPassReceiver(),
receiver_.BindNewPipeAndPassRemote()); receiver_.BindNewPipeAndPassRemote());
network::mojom::UDPSocketOptionsPtr options; network::mojom::UDPSocketOptionsPtr options;
......
...@@ -36,8 +36,8 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) UdpSocketClient final ...@@ -36,8 +36,8 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) UdpSocketClient final
bool SendPacket(media::cast::PacketRef packet, bool SendPacket(media::cast::PacketRef packet,
const base::RepeatingClosure& cb) override; const base::RepeatingClosure& cb) override;
int64_t GetBytesSent() override; int64_t GetBytesSent() override;
void StartReceiving(const media::cast::PacketReceiverCallbackWithStatus& void StartReceiving(
packet_receiver) override; media::cast::PacketReceiverCallbackWithStatus packet_receiver) override;
void StopReceiving() override; void StopReceiving() override;
// network::mojom::UDPSocketListener implementation. // network::mojom::UDPSocketListener implementation.
......
...@@ -117,8 +117,8 @@ struct EncodedFrame { ...@@ -117,8 +117,8 @@ struct EncodedFrame {
using PacketReceiverCallback = using PacketReceiverCallback =
base::RepeatingCallback<void(std::unique_ptr<Packet> packet)>; base::RepeatingCallback<void(std::unique_ptr<Packet> packet)>;
typedef base::Callback<bool(std::unique_ptr<Packet> packet)> using PacketReceiverCallbackWithStatus =
PacketReceiverCallbackWithStatus; base::RepeatingCallback<bool(std::unique_ptr<Packet> packet)>;
class PacketTransport { class PacketTransport {
public: public:
...@@ -134,7 +134,7 @@ class PacketTransport { ...@@ -134,7 +134,7 @@ class PacketTransport {
// Start receiving packets. Pakets are submitted to |packet_receiver|. // Start receiving packets. Pakets are submitted to |packet_receiver|.
virtual void StartReceiving( virtual void StartReceiving(
const PacketReceiverCallbackWithStatus& packet_receiver) = 0; PacketReceiverCallbackWithStatus packet_receiver) = 0;
// Stop receiving packets. // Stop receiving packets.
virtual void StopReceiving() = 0; virtual void StopReceiving() = 0;
......
...@@ -134,8 +134,8 @@ CastTransportImpl::CastTransportImpl( ...@@ -134,8 +134,8 @@ CastTransportImpl::CastTransportImpl(
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
logging_flush_interval_); logging_flush_interval_);
} }
transport_->StartReceiving( transport_->StartReceiving(base::BindRepeating(
base::Bind(&CastTransportImpl::OnReceivedPacket, base::Unretained(this))); &CastTransportImpl::OnReceivedPacket, base::Unretained(this)));
} }
CastTransportImpl::~CastTransportImpl() { CastTransportImpl::~CastTransportImpl() {
......
...@@ -60,8 +60,7 @@ class FakePacketSender : public PacketTransport { ...@@ -60,8 +60,7 @@ class FakePacketSender : public PacketTransport {
int64_t GetBytesSent() final { return bytes_sent_; } int64_t GetBytesSent() final { return bytes_sent_; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -66,8 +66,7 @@ class TestPacketSender : public PacketTransport { ...@@ -66,8 +66,7 @@ class TestPacketSender : public PacketTransport {
int64_t GetBytesSent() final { return bytes_sent_; } int64_t GetBytesSent() final { return bytes_sent_; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -81,8 +81,7 @@ class TestRtpPacketTransport : public PacketTransport { ...@@ -81,8 +81,7 @@ class TestRtpPacketTransport : public PacketTransport {
int64_t GetBytesSent() final { return 0; } int64_t GetBytesSent() final { return 0; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -75,7 +75,7 @@ UdpTransportImpl::UdpTransportImpl( ...@@ -75,7 +75,7 @@ UdpTransportImpl::UdpTransportImpl(
UdpTransportImpl::~UdpTransportImpl() = default; UdpTransportImpl::~UdpTransportImpl() = default;
void UdpTransportImpl::StartReceiving( void UdpTransportImpl::StartReceiving(
const PacketReceiverCallbackWithStatus& packet_receiver) { PacketReceiverCallbackWithStatus packet_receiver) {
DCHECK(io_thread_proxy_->RunsTasksInCurrentSequence()); DCHECK(io_thread_proxy_->RunsTasksInCurrentSequence());
if (!udp_socket_) { if (!udp_socket_) {
...@@ -83,7 +83,7 @@ void UdpTransportImpl::StartReceiving( ...@@ -83,7 +83,7 @@ void UdpTransportImpl::StartReceiving(
return; return;
} }
packet_receiver_ = packet_receiver; packet_receiver_ = std::move(packet_receiver);
udp_socket_->SetMulticastLoopbackMode(true); udp_socket_->SetMulticastLoopbackMode(true);
if (!IsEmpty(local_addr_)) { if (!IsEmpty(local_addr_)) {
if (udp_socket_->Open(local_addr_.GetFamily()) < 0 || if (udp_socket_->Open(local_addr_.GetFamily()) < 0 ||
......
...@@ -52,8 +52,7 @@ class UdpTransportImpl final : public PacketTransport, public UdpTransport { ...@@ -52,8 +52,7 @@ class UdpTransportImpl final : public PacketTransport, public UdpTransport {
bool SendPacket(PacketRef packet, const base::RepeatingClosure& cb) final; bool SendPacket(PacketRef packet, const base::RepeatingClosure& cb) final;
int64_t GetBytesSent() final; int64_t GetBytesSent() final;
// Start receiving packets. Packets are submitted to |packet_receiver|. // Start receiving packets. Packets are submitted to |packet_receiver|.
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final;
const PacketReceiverCallbackWithStatus& packet_receiver) final;
void StopReceiving() final; void StopReceiving() final;
// UdpTransport implementations. // UdpTransport implementations.
......
...@@ -75,8 +75,7 @@ class TestPacketSender : public PacketTransport { ...@@ -75,8 +75,7 @@ class TestPacketSender : public PacketTransport {
int64_t GetBytesSent() final { return 0; } int64_t GetBytesSent() final { return 0; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -79,8 +79,7 @@ class TestPacketSender : public PacketTransport { ...@@ -79,8 +79,7 @@ class TestPacketSender : public PacketTransport {
int64_t GetBytesSent() final { return 0; } int64_t GetBytesSent() final { return 0; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -209,8 +209,7 @@ class LoopBackTransport : public PacketTransport { ...@@ -209,8 +209,7 @@ class LoopBackTransport : public PacketTransport {
int64_t GetBytesSent() final { return bytes_sent_; } int64_t GetBytesSent() final { return bytes_sent_; }
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
...@@ -37,8 +37,7 @@ class LoopBackTransport : public PacketTransport { ...@@ -37,8 +37,7 @@ class LoopBackTransport : public PacketTransport {
int64_t GetBytesSent() final; int64_t GetBytesSent() final;
void StartReceiving( void StartReceiving(PacketReceiverCallbackWithStatus packet_receiver) final {}
const PacketReceiverCallbackWithStatus& packet_receiver) final {}
void StopReceiving() final {} void StopReceiving() final {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment