Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Side by Side Diff: net/quic/quic_ack_notifier_manager.cc

Issue 872403007: Remove an unneeded hash_set from QuicAckNotifierManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Minor_cleanup_84624803
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_ack_notifier_manager.h ('k') | net/quic/quic_ack_notifier_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 STLDeleteElements(&ack_notifiers_); 23 for (const auto& pair : ack_notifier_map_) {
24 for (QuicAckNotifier* notifier : pair.second) {
25 if (notifier->OnPacketAbandoned()) {
26 delete notifier;
27 }
28 }
29 }
24 } 30 }
25 31
26 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number, 32 void AckNotifierManager::OnPacketAcked(QuicPacketSequenceNumber sequence_number,
27 QuicTime::Delta delta_largest_observed) { 33 QuicTime::Delta delta_largest_observed) {
28 // Inform all the registered AckNotifiers of the new ACK. 34 // Inform all the registered AckNotifiers of the new ACK.
29 auto map_it = ack_notifier_map_.find(sequence_number); 35 auto map_it = ack_notifier_map_.find(sequence_number);
30 if (map_it == ack_notifier_map_.end()) { 36 if (map_it == ack_notifier_map_.end()) {
31 // No AckNotifier is interested in this sequence number. 37 // No AckNotifier is interested in this sequence number.
32 return; 38 return;
33 } 39 }
34 40
35 // One or more AckNotifiers are registered as interested in this sequence 41 // One or more AckNotifiers are registered as interested in this sequence
36 // number. Iterate through them and call OnAck on each. 42 // number. Iterate through them and call OnAck on each.
37 AckNotifierList& ack_notifier_list = map_it->second; 43 AckNotifierList& ack_notifier_list = map_it->second;
38 for (QuicAckNotifier* ack_notifier : ack_notifier_list) { 44 for (QuicAckNotifier* ack_notifier : ack_notifier_list) {
39 ack_notifier->OnAck(sequence_number, delta_largest_observed); 45 ack_notifier->OnAck(sequence_number, delta_largest_observed);
40 46
41 // If this has resulted in an empty AckNotifer, erase it. 47 // If this has resulted in an empty AckNotifer, erase it.
42 if (ack_notifier->IsEmpty()) { 48 if (!ack_notifier->HasUnackedPackets()) {
43 delete ack_notifier; 49 delete ack_notifier;
44 ack_notifiers_.erase(ack_notifier);
45 } 50 }
46 } 51 }
47 52
48 // Remove the sequence number from the map as we have notified all the 53 // Remove the sequence number from the map as we have notified all the
49 // registered AckNotifiers, and we won't see it again. 54 // registered AckNotifiers, and we won't see it again.
50 ack_notifier_map_.erase(map_it); 55 ack_notifier_map_.erase(map_it);
51 } 56 }
52 57
53 void AckNotifierManager::OnPacketRetransmitted( 58 void AckNotifierManager::OnPacketRetransmitted(
54 QuicPacketSequenceNumber old_sequence_number, 59 QuicPacketSequenceNumber old_sequence_number,
(...skipping 24 matching lines...) Expand all
79 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { 84 for (QuicAckNotifier* notifier : serialized_packet.notifiers) {
80 if (notifier == nullptr) { 85 if (notifier == nullptr) {
81 LOG(DFATAL) << "AckNotifier should not be nullptr."; 86 LOG(DFATAL) << "AckNotifier should not be nullptr.";
82 continue; 87 continue;
83 } 88 }
84 notifier->OnSerializedPacket(); 89 notifier->OnSerializedPacket();
85 90
86 // Update the mapping in the other direction, from sequence number to 91 // Update the mapping in the other direction, from sequence number to
87 // AckNotifier. 92 // AckNotifier.
88 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); 93 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier);
89
90 // Take ownership of the AckNotifier.
91 ack_notifiers_.insert(notifier);
92 } 94 }
93 } else { 95 } else {
94 // AckNotifiers can only be attached to retransmittable frames. 96 // AckNotifiers can only be attached to retransmittable frames.
95 RetransmittableFrames* frames = serialized_packet.retransmittable_frames; 97 RetransmittableFrames* frames = serialized_packet.retransmittable_frames;
96 if (frames == nullptr) { 98 if (frames == nullptr) {
97 return; 99 return;
98 } 100 }
99 101
100 // For each frame in |serialized_packet|, inform any attached AckNotifiers 102 // For each frame in |serialized_packet|, inform any attached AckNotifiers
101 // of the packet's sequence number. 103 // of the packet's sequence number.
102 for (const QuicFrame& quic_frame : frames->frames()) { 104 for (const QuicFrame& quic_frame : frames->frames()) {
103 if (quic_frame.type != STREAM_FRAME || 105 if (quic_frame.type != STREAM_FRAME ||
104 quic_frame.stream_frame->notifier == nullptr) { 106 quic_frame.stream_frame->notifier == nullptr) {
105 continue; 107 continue;
106 } 108 }
107 109
108 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier; 110 QuicAckNotifier* notifier = quic_frame.stream_frame->notifier;
109 notifier->OnSerializedPacket(); 111 notifier->OnSerializedPacket();
110 112
111 // Update the mapping in the other direction, from sequence number to 113 // Update the mapping in the other direction, from sequence number to
112 // AckNotifier. 114 // AckNotifier.
113 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); 115 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier);
114
115 // Take ownership of the AckNotifier.
116 ack_notifiers_.insert(notifier);
117 } 116 }
118 } 117 }
119 } 118 }
120 119
121 } // namespace net 120 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_ack_notifier_manager.h ('k') | net/quic/quic_ack_notifier_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698