Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / quic / quic_unacked_packet_map.h
blob0684b4db9f74407792f77edfa997e7514604a16b
1 // Copyright 2014 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_UNACKED_PACKET_MAP_H_
6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_
8 #include "net/base/linked_hash_map.h"
9 #include "net/quic/quic_protocol.h"
11 namespace net {
13 // Class which tracks unacked packets for three purposes:
14 // 1) Track retransmittable data, including multiple transmissions of frames.
15 // 2) Track packets and bytes in flight for congestion control.
16 // 3) Track sent time of packets to provide RTT measurements from acks.
17 class NET_EXPORT_PRIVATE QuicUnackedPacketMap {
18 public:
19 QuicUnackedPacketMap();
20 ~QuicUnackedPacketMap();
22 // Adds |serialized_packet| to the map. Does not mark it in flight.
23 void AddPacket(const SerializedPacket& serialized_packet);
25 // Called when a packet is retransmitted with a new sequence number.
26 // |old_sequence_number| will remain unacked, but will have no
27 // retransmittable data associated with it. |new_sequence_number| will
28 // be both unacked and associated with retransmittable data.
29 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number,
30 QuicPacketSequenceNumber new_sequence_number,
31 TransmissionType transmission_type);
33 // Returns true if the packet |sequence_number| is unacked.
34 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const;
36 // Sets the nack count to the max of the current nack count and |min_nacks|.
37 void NackPacket(QuicPacketSequenceNumber sequence_number,
38 size_t min_nacks);
40 // Marks |sequence_number| as no longer in flight.
41 void RemoveFromInFlight(QuicPacketSequenceNumber sequence_number);
43 // Returns true if the unacked packet |sequence_number| has retransmittable
44 // frames. This will return false if the packet has been acked, if a
45 // previous transmission of this packet was ACK'd, or if this packet has been
46 // retransmitted as with different sequence number, or if the packet never
47 // had any retransmittable packets in the first place.
48 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const;
50 // Returns true if there are any unacked packets.
51 bool HasUnackedPackets() const;
53 // Returns true if there are any unacked packets which have retransmittable
54 // frames.
55 bool HasUnackedRetransmittableFrames() const;
57 // Returns the largest sequence number that has been sent.
58 QuicPacketSequenceNumber largest_sent_packet() const {
59 return largest_sent_packet_;
62 // Returns the sum of bytes from all packets in flight.
63 QuicByteCount bytes_in_flight() const {
64 return bytes_in_flight_;
67 // Returns the smallest sequence number of a serialized packet which has not
68 // been acked by the peer. If there are no unacked packets, returns 0.
69 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const;
71 // Sets a packet as sent with the sent time |sent_time|. Marks the packet
72 // as in flight if |set_in_flight| is true.
73 // Packets marked as in flight are expected to be marked as missing when they
74 // don't arrive, indicating the need for retransmission.
75 void SetSent(QuicPacketSequenceNumber sequence_number,
76 QuicTime sent_time,
77 QuicByteCount bytes_sent,
78 bool set_in_flight);
80 // Restores the in flight status for a packet that was previously sent.
81 void RestoreInFlight(QuicPacketSequenceNumber sequence_number);
83 // Clears up to |num_to_clear| previous transmissions in order to make room
84 // in the ack frame for new acks.
85 void ClearPreviousRetransmissions(size_t num_to_clear);
87 typedef linked_hash_map<QuicPacketSequenceNumber,
88 TransmissionInfo> UnackedPacketMap;
90 typedef UnackedPacketMap::const_iterator const_iterator;
92 const_iterator begin() const { return unacked_packets_.begin(); }
93 const_iterator end() const { return unacked_packets_.end(); }
95 // Returns true if there are unacked packets that are in flight.
96 bool HasInFlightPackets() const;
98 // Returns the TransmissionInfo associated with |sequence_number|, which
99 // must be unacked.
100 const TransmissionInfo& GetTransmissionInfo(
101 QuicPacketSequenceNumber sequence_number) const;
103 // Returns the time that the last unacked packet was sent.
104 QuicTime GetLastPacketSentTime() const;
106 // Returns the time that the first in flight packet was sent.
107 QuicTime GetFirstInFlightPacketSentTime() const;
109 // Returns the number of unacked packets.
110 size_t GetNumUnackedPackets() const;
112 // Returns true if there are multiple packets in flight.
113 bool HasMultipleInFlightPackets() const;
115 // Returns true if there are any pending crypto packets.
116 bool HasPendingCryptoPackets() const;
118 // Removes any retransmittable frames from this transmission or an associated
119 // transmission. It removes now useless transmissions, and disconnects any
120 // other packets from other transmissions.
121 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number);
123 // Increases the largest observed. Any packets less or equal to
124 // |largest_acked_packet| are discarded if they are only for the RTT purposes.
125 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed);
127 private:
128 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info);
130 // Returns true if the packet no longer has a purpose in the map.
131 bool IsPacketUseless(UnackedPacketMap::const_iterator it) const;
133 QuicPacketSequenceNumber largest_sent_packet_;
134 QuicPacketSequenceNumber largest_observed_;
136 // Newly serialized retransmittable and fec packets are added to this map,
137 // which contains owning pointers to any contained frames. If a packet is
138 // retransmitted, this map will contain entries for both the old and the new
139 // packet. The old packet's retransmittable frames entry will be NULL, while
140 // the new packet's entry will contain the frames to retransmit.
141 // If the old packet is acked before the new packet, then the old entry will
142 // be removed from the map and the new entry's retransmittable frames will be
143 // set to NULL.
144 UnackedPacketMap unacked_packets_;
146 size_t bytes_in_flight_;
147 // Number of retransmittable crypto handshake packets.
148 size_t pending_crypto_packet_count_;
150 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap);
153 } // namespace net
155 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_