| 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_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 AckNotifierManager::AckNotifierManager() {} | 19 AckNotifierManager::AckNotifierManager() { |
| 20 } |
| 20 | 21 |
| 21 AckNotifierManager::~AckNotifierManager() { | 22 AckNotifierManager::~AckNotifierManager() { |
| 22 STLDeleteElements(&ack_notifiers_); | 23 STLDeleteElements(&ack_notifiers_); |
| 23 } | 24 } |
| 24 | 25 |
| 25 void AckNotifierManager::OnPacketAcked( | 26 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number, |
| 26 QuicPacketSequenceNumber sequence_number, | 27 QuicTime::Delta delta_largest_observed) { |
| 27 QuicTime::Delta delta_largest_observed) { | |
| 28 // Inform all the registered AckNotifiers of the new ACK. | 28 // Inform all the registered AckNotifiers of the new ACK. |
| 29 AckNotifierMap::iterator map_it = ack_notifier_map_.find(sequence_number); | 29 AckNotifierMap::iterator map_it = ack_notifier_map_.find(sequence_number); |
| 30 if (map_it == ack_notifier_map_.end()) { | 30 if (map_it == ack_notifier_map_.end()) { |
| 31 // No AckNotifier is interested in this sequence number. | 31 // No AckNotifier is interested in this sequence number. |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // One or more AckNotifiers are registered as interested in this sequence | 35 // One or more AckNotifiers are registered as interested in this sequence |
| 36 // number. Iterate through them and call OnAck on each. | 36 // number. Iterate through them and call OnAck on each. |
| 37 for (AckNotifierSet::iterator set_it = map_it->second.begin(); | 37 for (AckNotifierSet::iterator set_it = map_it->second.begin(); |
| 38 set_it != map_it->second.end(); ++set_it) { | 38 set_it != map_it->second.end(); |
| 39 ++set_it) { |
| 39 QuicAckNotifier* ack_notifier = *set_it; | 40 QuicAckNotifier* ack_notifier = *set_it; |
| 40 ack_notifier->OnAck(sequence_number, delta_largest_observed); | 41 ack_notifier->OnAck(sequence_number, delta_largest_observed); |
| 41 | 42 |
| 42 // If this has resulted in an empty AckNotifer, erase it. | 43 // If this has resulted in an empty AckNotifer, erase it. |
| 43 if (ack_notifier->IsEmpty()) { | 44 if (ack_notifier->IsEmpty()) { |
| 44 delete ack_notifier; | 45 delete ack_notifier; |
| 45 ack_notifiers_.erase(ack_notifier); | 46 ack_notifiers_.erase(ack_notifier); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 // Remove the sequence number from the map as we have notified all the | 50 // Remove the sequence number from the map as we have notified all the |
| 50 // registered AckNotifiers, and we won't see it again. | 51 // registered AckNotifiers, and we won't see it again. |
| 51 ack_notifier_map_.erase(map_it); | 52 ack_notifier_map_.erase(map_it); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void AckNotifierManager::UpdateSequenceNumber( | 55 void AckNotifierManager::UpdateSequenceNumber( |
| 55 QuicPacketSequenceNumber old_sequence_number, | 56 QuicPacketSequenceNumber old_sequence_number, |
| 56 QuicPacketSequenceNumber new_sequence_number) { | 57 QuicPacketSequenceNumber new_sequence_number) { |
| 57 AckNotifierMap::iterator map_it = ack_notifier_map_.find(old_sequence_number); | 58 AckNotifierMap::iterator map_it = ack_notifier_map_.find(old_sequence_number); |
| 58 if (map_it != ack_notifier_map_.end()) { | 59 if (map_it != ack_notifier_map_.end()) { |
| 59 // We will add an entry to the map for the new sequence number, and move | 60 // We will add an entry to the map for the new sequence number, and move |
| 60 // the | 61 // the |
| 61 // list of AckNotifiers over. | 62 // list of AckNotifiers over. |
| 62 AckNotifierSet new_set; | 63 AckNotifierSet new_set; |
| 63 for (AckNotifierSet::iterator notifier_it = map_it->second.begin(); | 64 for (AckNotifierSet::iterator notifier_it = map_it->second.begin(); |
| 64 notifier_it != map_it->second.end(); ++notifier_it) { | 65 notifier_it != map_it->second.end(); |
| 66 ++notifier_it) { |
| 65 (*notifier_it) | 67 (*notifier_it) |
| 66 ->UpdateSequenceNumber(old_sequence_number, new_sequence_number); | 68 ->UpdateSequenceNumber(old_sequence_number, new_sequence_number); |
| 67 new_set.insert(*notifier_it); | 69 new_set.insert(*notifier_it); |
| 68 } | 70 } |
| 69 ack_notifier_map_[new_sequence_number] = new_set; | 71 ack_notifier_map_[new_sequence_number] = new_set; |
| 70 ack_notifier_map_.erase(map_it); | 72 ack_notifier_map_.erase(map_it); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 void AckNotifierManager::OnSerializedPacket( | 76 void AckNotifierManager::OnSerializedPacket( |
| 75 const SerializedPacket& serialized_packet) { | 77 const SerializedPacket& serialized_packet) { |
| 76 // Run through all the frames and if any of them are stream frames and have | 78 // Run through all the frames and if any of them are stream frames and have |
| 77 // an AckNotifier registered, then inform the AckNotifier that it should be | 79 // an AckNotifier registered, then inform the AckNotifier that it should be |
| 78 // interested in this packet's sequence number. | 80 // interested in this packet's sequence number. |
| 79 | 81 |
| 80 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; | 82 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; |
| 81 | 83 |
| 82 // AckNotifiers can only be attached to retransmittable frames. | 84 // AckNotifiers can only be attached to retransmittable frames. |
| 83 if (!frames) { | 85 if (!frames) { |
| 84 return; | 86 return; |
| 85 } | 87 } |
| 86 | 88 |
| 87 for (QuicFrames::const_iterator it = frames->frames().begin(); | 89 for (QuicFrames::const_iterator it = frames->frames().begin(); |
| 88 it != frames->frames().end(); ++it) { | 90 it != frames->frames().end(); |
| 91 ++it) { |
| 89 if (it->type == STREAM_FRAME && it->stream_frame->notifier != NULL) { | 92 if (it->type == STREAM_FRAME && it->stream_frame->notifier != NULL) { |
| 90 QuicAckNotifier* notifier = it->stream_frame->notifier; | 93 QuicAckNotifier* notifier = it->stream_frame->notifier; |
| 91 | 94 |
| 92 // The AckNotifier needs to know it is tracking this packet's sequence | 95 // The AckNotifier needs to know it is tracking this packet's sequence |
| 93 // number. | 96 // number. |
| 94 notifier->AddSequenceNumber(serialized_packet.sequence_number, | 97 notifier->AddSequenceNumber(serialized_packet.sequence_number, |
| 95 serialized_packet.packet->length()); | 98 serialized_packet.packet->length()); |
| 96 | 99 |
| 97 // Update the mapping in the other direction, from sequence | 100 // Update the mapping in the other direction, from sequence |
| 98 // number to AckNotifier. | 101 // number to AckNotifier. |
| 99 ack_notifier_map_[serialized_packet.sequence_number].insert(notifier); | 102 ack_notifier_map_[serialized_packet.sequence_number].insert(notifier); |
| 100 | 103 |
| 101 // Take ownership of the AckNotifier. | 104 // Take ownership of the AckNotifier. |
| 102 ack_notifiers_.insert(notifier); | 105 ack_notifiers_.insert(notifier); |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace net | 110 } // namespace net |
| OLD | NEW |