OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_ack_notifier_manager.h" | 5 #include "net/quic/quic_ack_notifier_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "net/quic/quic_ack_notifier.h" | 14 #include "net/quic/quic_ack_notifier.h" |
15 #include "net/quic/quic_flags.h" | 15 #include "net/quic/quic_flags.h" |
16 #include "net/quic/quic_protocol.h" | 16 #include "net/quic/quic_protocol.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 AckNotifierManager::AckNotifierManager() {} | 20 AckNotifierManager::AckNotifierManager() {} |
21 | 21 |
22 AckNotifierManager::~AckNotifierManager() { | 22 AckNotifierManager::~AckNotifierManager() { |
23 for (const auto& pair : ack_notifier_map_) { | 23 STLDeleteElements(&ack_notifiers_); |
24 for (QuicAckNotifier* notifier : pair.second) { | |
25 if (notifier->OnPacketAbandoned()) { | |
26 delete notifier; | |
27 } | |
28 } | |
29 } | |
30 } | 24 } |
31 | 25 |
32 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number, | 26 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number, |
33 QuicTime::Delta delta_largest_observed) { | 27 QuicTime::Delta delta_largest_observed) { |
34 // Inform all the registered AckNotifiers of the new ACK. | 28 // Inform all the registered AckNotifiers of the new ACK. |
35 auto map_it = ack_notifier_map_.find(sequence_number); | 29 auto map_it = ack_notifier_map_.find(sequence_number); |
36 if (map_it == ack_notifier_map_.end()) { | 30 if (map_it == ack_notifier_map_.end()) { |
37 // No AckNotifier is interested in this sequence number. | 31 // No AckNotifier is interested in this sequence number. |
38 return; | 32 return; |
39 } | 33 } |
40 | 34 |
41 // One or more AckNotifiers are registered as interested in this sequence | 35 // One or more AckNotifiers are registered as interested in this sequence |
42 // number. Iterate through them and call OnAck on each. | 36 // number. Iterate through them and call OnAck on each. |
43 for (QuicAckNotifier* ack_notifier : map_it->second) { | 37 AckNotifierList& ack_notifier_list = map_it->second; |
44 if (ack_notifier->OnAck(delta_largest_observed)) { | 38 for (QuicAckNotifier* ack_notifier : ack_notifier_list) { |
45 // If this has resulted in an empty AckNotifer, erase it. | 39 ack_notifier->OnAck(sequence_number, delta_largest_observed); |
| 40 |
| 41 // If this has resulted in an empty AckNotifer, erase it. |
| 42 if (ack_notifier->IsEmpty()) { |
46 delete ack_notifier; | 43 delete ack_notifier; |
| 44 ack_notifiers_.erase(ack_notifier); |
47 } | 45 } |
48 } | 46 } |
49 | 47 |
50 // Remove the sequence number from the map as we have notified all the | 48 // Remove the sequence number from the map as we have notified all the |
51 // registered AckNotifiers, and we won't see it again. | 49 // registered AckNotifiers, and we won't see it again. |
52 ack_notifier_map_.erase(map_it); | 50 ack_notifier_map_.erase(map_it); |
53 } | 51 } |
54 | 52 |
55 void AckNotifierManager::OnPacketRetransmitted( | 53 void AckNotifierManager::OnPacketRetransmitted( |
56 QuicPacketSequenceNumber old_sequence_number, | 54 QuicPacketSequenceNumber old_sequence_number, |
(...skipping 13 matching lines...) Expand all Loading... |
70 | 68 |
71 // The old sequence number is no longer of interest, copy the updated | 69 // The old sequence number is no longer of interest, copy the updated |
72 // AckNotifiers to the new sequence number before deleting the old. | 70 // AckNotifiers to the new sequence number before deleting the old. |
73 ack_notifier_map_[new_sequence_number] = ack_notifier_list; | 71 ack_notifier_map_[new_sequence_number] = ack_notifier_list; |
74 ack_notifier_map_.erase(map_it); | 72 ack_notifier_map_.erase(map_it); |
75 } | 73 } |
76 | 74 |
77 void AckNotifierManager::OnSerializedPacket( | 75 void AckNotifierManager::OnSerializedPacket( |
78 const SerializedPacket& serialized_packet) { | 76 const SerializedPacket& serialized_packet) { |
79 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 77 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
80 // Inform each attached AckNotifier of the packet's serialization. | 78 // Inform each attached AckNotifier of the packet's sequence number. |
81 AckNotifierList& notifier_list = | |
82 ack_notifier_map_[serialized_packet.sequence_number]; | |
83 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { | 79 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { |
84 if (notifier == nullptr) { | 80 if (notifier == nullptr) { |
85 LOG(DFATAL) << "AckNotifier should not be nullptr."; | 81 LOG(DFATAL) << "AckNotifier should not be nullptr."; |
86 continue; | 82 continue; |
87 } | 83 } |
88 notifier->OnSerializedPacket(); | 84 notifier->AddSequenceNumber(serialized_packet.sequence_number, |
| 85 serialized_packet.packet->length()); |
89 | 86 |
90 // Update the mapping in the other direction, from sequence number to | 87 // Update the mapping in the other direction, from sequence number to |
91 // AckNotifier. | 88 // AckNotifier. |
92 notifier_list.push_back(notifier); | 89 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); |
| 90 |
| 91 // Take ownership of the AckNotifier. |
| 92 ack_notifiers_.insert(notifier); |
93 } | 93 } |
94 } else { | 94 } else { |
95 // AckNotifiers can only be attached to retransmittable frames. | 95 // AckNotifiers can only be attached to retransmittable frames. |
96 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; | 96 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; |
97 if (frames == nullptr) { | 97 if (frames == nullptr) { |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 // For each frame in |serialized_packet|, inform any attached AckNotifiers | 101 // For each frame in |serialized_packet|, inform any attached AckNotifiers |
102 // of the packet's sequence number. | 102 // of the packet's sequence number. |
103 for (const QuicFrame& quic_frame : frames->frames()) { | 103 for (const QuicFrame& quic_frame : frames->frames()) { |
104 if (quic_frame.type != STREAM_FRAME || | 104 if (quic_frame.type != STREAM_FRAME || |
105 quic_frame.stream_frame->notifier == nullptr) { | 105 quic_frame.stream_frame->notifier == nullptr) { |
106 continue; | 106 continue; |
107 } | 107 } |
108 | 108 |
109 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; | 109 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; |
110 notifier->OnSerializedPacket(); | 110 notifier->AddSequenceNumber(serialized_packet.sequence_number, |
| 111 serialized_packet.packet->length()); |
111 | 112 |
112 // Update the mapping in the other direction, from sequence number to | 113 // Update the mapping in the other direction, from sequence number to |
113 // AckNotifier. | 114 // AckNotifier. |
114 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); | 115 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); |
| 116 |
| 117 // Take ownership of the AckNotifier. |
| 118 ack_notifiers_.insert(notifier); |
115 } | 119 } |
116 } | 120 } |
117 } | 121 } |
118 | 122 |
119 } // namespace net | 123 } // namespace net |
OLD | NEW |