Roll src/third_party/skia 5cc0f6c:01d3319
[chromium-blink-merge.git] / net / quic / quic_ack_notifier.h
blob602d86fefb8024184d4e3436ade27cd89c53ddb4
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"
11 namespace net {
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 {
19 public:
20 class NET_EXPORT_PRIVATE DelegateInterface
21 : public base::RefCounted<DelegateInterface> {
22 public:
23 DelegateInterface();
24 // Args:
25 // num_retransmitted_packets - Number of packets that had to be
26 // retransmitted.
27 // num_retransmitted_bytes - Number of bytes that had to be retransmitted.
28 virtual void OnAckNotification(int num_retransmitted_packets,
29 int num_retransmitted_bytes,
30 QuicTime::Delta delta_largest_observed) = 0;
32 protected:
33 friend class base::RefCounted<DelegateInterface>;
35 // Delegates are ref counted.
36 virtual ~DelegateInterface();
39 // QuicAckNotifier is expected to keep its own reference to the delegate.
40 explicit QuicAckNotifier(DelegateInterface* delegate);
41 virtual ~QuicAckNotifier();
43 // Register a serialized packet the notifier should track.
44 void OnSerializedPacket();
46 // Called on receipt of new ACK frame for an unacked packet.
47 // Decrements the number of unacked packets and if there are none left, calls
48 // the stored delegate's OnAckNotification method.
50 // Returns true if the delegate was called, false otherwise.
51 bool OnAck(QuicTime::Delta delta_largest_observed);
53 // Called when we've given up waiting for a sequence number, typically when
54 // the connection is torn down.
55 // Returns true if there are no more unacked packets being tracked.
56 bool OnPacketAbandoned();
58 bool HasUnackedPackets() const { return unacked_packets_ > 0; }
60 // If a packet is retransmitted by the connection, it will be sent with a
61 // different sequence number.
62 void OnPacketRetransmitted(int packet_payload_size);
64 private:
65 // The delegate's OnAckNotification() method will be called once we have been
66 // notified of ACKs for all the sequence numbers we are tracking.
67 // This is not owned by OnAckNotifier and must outlive it.
68 scoped_refptr<DelegateInterface> delegate_;
70 // The number of unacked packets being tracked.
71 int unacked_packets_;
73 // Number of packets that had to be retransmitted.
74 int retransmitted_packet_count_;
75 // Number of bytes that had to be retransmitted.
76 int retransmitted_byte_count_;
78 DISALLOW_COPY_AND_ASSIGN(QuicAckNotifier);
81 } // namespace net
83 #endif // NET_QUIC_QUIC_ACK_NOTIFIER_H_