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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
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 for (QuicAckNotifier* ack_notifier : map_it->second) {
38 for (QuicAckNotifier* ack_notifier : ack_notifier_list) { 44 if (ack_notifier->OnAck(delta_largest_observed)) {
39 ack_notifier->OnAck(sequence_number, delta_largest_observed); 45 // If this has resulted in an empty AckNotifer, erase it.
40
41 // If this has resulted in an empty AckNotifer, erase it.
42 if (ack_notifier->IsEmpty()) {
43 delete ack_notifier; 46 delete ack_notifier;
44 ack_notifiers_.erase(ack_notifier);
45 } 47 }
46 } 48 }
47 49
48 // 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
49 // registered AckNotifiers, and we won't see it again. 51 // registered AckNotifiers, and we won't see it again.
50 ack_notifier_map_.erase(map_it); 52 ack_notifier_map_.erase(map_it);
51 } 53 }
52 54
53 void AckNotifierManager::OnPacketRetransmitted( 55 void AckNotifierManager::OnPacketRetransmitted(
54 QuicPacketSequenceNumber old_sequence_number, 56 QuicPacketSequenceNumber old_sequence_number,
(...skipping 13 matching lines...) Expand all
68 70
69 // The old sequence number is no longer of interest, copy the updated 71 // The old sequence number is no longer of interest, copy the updated
70 // AckNotifiers to the new sequence number before deleting the old. 72 // AckNotifiers to the new sequence number before deleting the old.
71 ack_notifier_map_[new_sequence_number] = ack_notifier_list; 73 ack_notifier_map_[new_sequence_number] = ack_notifier_list;
72 ack_notifier_map_.erase(map_it); 74 ack_notifier_map_.erase(map_it);
73 } 75 }
74 76
75 void AckNotifierManager::OnSerializedPacket( 77 void AckNotifierManager::OnSerializedPacket(
76 const SerializedPacket& serialized_packet) { 78 const SerializedPacket& serialized_packet) {
77 if (FLAGS_quic_attach_ack_notifiers_to_packets) { 79 if (FLAGS_quic_attach_ack_notifiers_to_packets) {
78 // Inform each attached AckNotifier of the packet's sequence number. 80 // Inform each attached AckNotifier of the packet's serialization.
81 AckNotifierList& notifier_list =
82 ack_notifier_map_[serialized_packet.sequence_number];
79 for (QuicAckNotifier* notifier : serialized_packet.notifiers) { 83 for (QuicAckNotifier* notifier : serialized_packet.notifiers) {
80 if (notifier == nullptr) { 84 if (notifier == nullptr) {
81 LOG(DFATAL) << "AckNotifier should not be nullptr."; 85 LOG(DFATAL) << "AckNotifier should not be nullptr.";
82 continue; 86 continue;
83 } 87 }
84 notifier->AddSequenceNumber(serialized_packet.sequence_number, 88 notifier->OnSerializedPacket();
85 serialized_packet.packet->length());
86 89
87 // Update the mapping in the other direction, from sequence number to 90 // Update the mapping in the other direction, from sequence number to
88 // AckNotifier. 91 // AckNotifier.
89 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); 92 notifier_list.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->AddSequenceNumber(serialized_packet.sequence_number, 110 notifier->OnSerializedPacket();
111 serialized_packet.packet->length());
112 111
113 // Update the mapping in the other direction, from sequence number to 112 // Update the mapping in the other direction, from sequence number to
114 // AckNotifier. 113 // AckNotifier.
115 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier); 114 ack_notifier_map_[serialized_packet.sequence_number].push_back(notifier);
116
117 // Take ownership of the AckNotifier.
118 ack_notifiers_.insert(notifier);
119 } 115 }
120 } 116 }
121 } 117 }
122 118
123 } // namespace net 119 } // 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