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
> {
24 virtual void OnAckNotification() = 0;
27 friend class base::RefCounted
<DelegateInterface
>;
29 // Delegates are ref counted.
30 virtual ~DelegateInterface();
33 // QuicAckNotifier is expected to keep its own reference to the delegate.
34 explicit QuicAckNotifier(DelegateInterface
* delegate
);
35 virtual ~QuicAckNotifier();
37 // Register a sequence number that this AckNotifier should be interested in.
38 void AddSequenceNumber(const QuicPacketSequenceNumber
& sequence_number
);
40 // Register a set of sequence numbers that this AckNotifier should be
42 void AddSequenceNumbers(const SequenceNumberSet
& sequence_numbers
);
44 // Called by the QuicConnection on receipt of new ACK frame, with the sequence
45 // number referenced by the ACK frame.
46 // Deletes the matching sequence number from the stored set of sequence
47 // numbers. If this set is now empty, call the stored delegate's
48 // OnAckNotification method.
50 // Returns true if the provided sequence_number caused the delegate to be
51 // called, false otherwise.
52 bool OnAck(QuicPacketSequenceNumber sequence_number
);
54 bool IsEmpty() { return sequence_numbers_
.empty(); }
56 // If a packet is retransmitted by the connection it will be sent with a
57 // different sequence number. Updates our internal set of sequence_numbers to
58 // track the latest number.
59 void UpdateSequenceNumber(QuicPacketSequenceNumber old_sequence_number
,
60 QuicPacketSequenceNumber new_sequence_number
);
63 // The delegate's OnAckNotification() method will be called once we have been
64 // notified of ACKs for all the sequence numbers we are tracking.
65 // This is not owned by OnAckNotifier and must outlive it.
66 scoped_refptr
<DelegateInterface
> delegate_
;
68 // Set of sequence numbers this notifier is waiting to hear about. The
69 // delegate will not be called until this is an empty set.
70 SequenceNumberSet sequence_numbers_
;
75 #endif // NET_QUIC_QUIC_ACK_NOTIFIER_H_