1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_QUIC_ACK_NOTIFIER_H_
6 #define NET_QUIC_QUIC_ACK_NOTIFIER_H_
8 #include "base/memory/ref_counted.h"
9 #include "net/quic/quic_protocol.h"
13 // Used to register with a QuicConnection for notification once a set of packets
14 // have all been ACKed.
15 // The connection informs this class of newly ACKed sequence numbers, and once
16 // we have seen ACKs for all the sequence numbers we are interested in, we
17 // trigger a call to a provided Closure.
18 class NET_EXPORT_PRIVATE QuicAckNotifier
{
20 class NET_EXPORT_PRIVATE DelegateInterface
21 : public base::RefCounted
<DelegateInterface
> {
25 // num_original_packets - Number of packets in the original transmission.
26 // num_original_bytes - Number of packets in the original transmission.
27 // num_retransmitted_packets - Number of packets that had to be
29 // num_retransmitted_bytes - Number of bytes that had to be retransmitted.
30 virtual void OnAckNotification(int num_original_packets
,
31 int num_original_bytes
,
32 int num_retransmitted_packets
,
33 int num_retransmitted_bytes
) = 0;
35 friend class base::RefCounted
<DelegateInterface
>;
37 // Delegates are ref counted.
38 virtual ~DelegateInterface();
41 // QuicAckNotifier is expected to keep its own reference to the delegate.
42 explicit QuicAckNotifier(DelegateInterface
* delegate
);
43 virtual ~QuicAckNotifier();
45 // Register a sequence number that this AckNotifier should be interested in.
46 void AddSequenceNumber(const QuicPacketSequenceNumber
& sequence_number
,
47 int packet_payload_size
);
49 // Called by the QuicConnection on receipt of new ACK frame, with the sequence
50 // number referenced by the ACK frame.
51 // Deletes the matching sequence number from the stored set of sequence
52 // numbers. If this set is now empty, call the stored delegate's
53 // OnAckNotification method.
55 // Returns true if the provided sequence_number caused the delegate to be
56 // called, false otherwise.
57 bool OnAck(QuicPacketSequenceNumber sequence_number
);
59 bool IsEmpty() { return sequence_numbers_
.empty(); }
61 // If a packet is retransmitted by the connection it will be sent with a
62 // different sequence number. Updates our internal set of sequence_numbers to
63 // track the latest number.
64 void UpdateSequenceNumber(QuicPacketSequenceNumber old_sequence_number
,
65 QuicPacketSequenceNumber new_sequence_number
);
70 explicit PacketInfo(int payload_size
);
72 int packet_payload_size
;
75 // The delegate's OnAckNotification() method will be called once we have been
76 // notified of ACKs for all the sequence numbers we are tracking.
77 // This is not owned by OnAckNotifier and must outlive it.
78 scoped_refptr
<DelegateInterface
> delegate_
;
80 // Sequence numbers this notifier is waiting to hear about. The
81 // delegate will not be called until this is empty.
82 base::hash_map
<QuicPacketSequenceNumber
, PacketInfo
> sequence_numbers_
;
84 // Transmission and retransmission stats.
85 // Number of packets in the original transmission.
86 int original_packet_count_
;
87 // Number of packets in the original transmission.
88 int original_byte_count_
;
89 // Number of packets that had to be retransmitted.
90 int retransmitted_packet_count_
;
91 // Number of bytes that had to be retransmitted.
92 int retransmitted_byte_count_
;
97 #endif // NET_QUIC_QUIC_ACK_NOTIFIER_H_