Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / quic_ack_notifier_manager.cc
blobdf4a87c2208eb2fe2008176c8ad5b2393887705a
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 #include "net/quic/quic_ack_notifier_manager.h"
7 #include <stddef.h>
8 #include <list>
9 #include <map>
10 #include <utility>
11 #include <vector>
13 #include "base/stl_util.h"
14 #include "net/quic/quic_ack_notifier.h"
15 #include "net/quic/quic_flags.h"
16 #include "net/quic/quic_protocol.h"
18 namespace net {
20 AckNotifierManager::AckNotifierManager() {}
22 AckNotifierManager::~AckNotifierManager() {
23 for (const auto& pair : ack_notifier_map_) {
24 for (QuicAckNotifier* notifier : pair.second) {
25 if (notifier->OnPacketAbandoned()) {
26 delete notifier;
32 void AckNotifierManager::OnPacketAcked(QuicPacketNumber packet_number,
33 QuicTime::Delta delta_largest_observed) {
34 // Inform all the registered AckNotifiers of the new ACK.
35 auto map_it = ack_notifier_map_.find(packet_number);
36 if (map_it == ack_notifier_map_.end()) {
37 // No AckNotifier is interested in this packet number.
38 return;
41 // One or more AckNotifiers are registered as interested in this sequence
42 // number. Iterate through them and call OnAck on each.
43 for (QuicAckNotifier* ack_notifier : map_it->second) {
44 if (ack_notifier->OnAck(delta_largest_observed)) {
45 // If this has resulted in an empty AckNotifer, erase it.
46 delete ack_notifier;
50 // Remove the packet number from the map as we have notified all the
51 // registered AckNotifiers, and we won't see it again.
52 ack_notifier_map_.erase(map_it);
55 void AckNotifierManager::OnPacketRetransmitted(
56 QuicPacketNumber old_packet_number,
57 QuicPacketNumber new_packet_number,
58 int packet_payload_size) {
59 auto map_it = ack_notifier_map_.find(old_packet_number);
60 if (map_it == ack_notifier_map_.end()) {
61 // No AckNotifiers are interested in the old packet number.
62 return;
65 // Update the existing QuicAckNotifiers to the new packet number.
66 AckNotifierList& ack_notifier_list = map_it->second;
67 for (QuicAckNotifier* ack_notifier : ack_notifier_list) {
68 ack_notifier->OnPacketRetransmitted(packet_payload_size);
71 // The old packet number is no longer of interest, copy the updated
72 // AckNotifiers to the new packet number before deleting the old.
73 // TODO(rtenneti): use std::move when chromium supports it.
74 // ack_notifier_map_[new_packet_number] = std::move(ack_notifier_list);
75 ack_notifier_map_[new_packet_number] = ack_notifier_list;
76 ack_notifier_map_.erase(map_it);
79 void AckNotifierManager::OnSerializedPacket(
80 const SerializedPacket& serialized_packet) {
81 if (serialized_packet.notifiers.empty()) {
82 return;
84 // Inform each attached AckNotifier of the packet's serialization.
85 AckNotifierList& notifier_list =
86 ack_notifier_map_[serialized_packet.packet_number];
87 for (QuicAckNotifier* notifier : serialized_packet.notifiers) {
88 if (notifier == nullptr) {
89 LOG(DFATAL) << "AckNotifier should not be nullptr.";
90 continue;
92 notifier->OnSerializedPacket();
93 notifier_list.push_back(notifier);
97 void AckNotifierManager::OnPacketRemoved(QuicPacketNumber packet_number) {
98 // Determine if there are any notifiers interested in this packet.
99 auto map_it = ack_notifier_map_.find(packet_number);
100 if (map_it == ack_notifier_map_.end()) {
101 return;
104 // Notify all of the interested notifiers that the packet is abandoned.
105 for (QuicAckNotifier* ack_notifier : map_it->second) {
106 DCHECK(ack_notifier);
107 if (ack_notifier->OnPacketAbandoned()) {
108 // If this has resulted in an empty AckNotifer, erase it.
109 delete ack_notifier;
113 // Remove the packet with given packet number from the map.
114 ack_notifier_map_.erase(map_it);
117 } // namespace net