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

Side by Side Diff: net/quic/core/quic_buffered_packet_store.cc

Issue 2229393003: net: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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/core/interval_test.cc ('k') | net/quic/core/quic_connection.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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/core/quic_buffered_packet_store.h" 5 #include "net/quic/core/quic_buffered_packet_store.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 expiration_alarm_( 72 expiration_alarm_(
73 alarm_factory->CreateAlarm(new ConnectionExpireAlarm(this))) {} 73 alarm_factory->CreateAlarm(new ConnectionExpireAlarm(this))) {}
74 74
75 QuicBufferedPacketStore::~QuicBufferedPacketStore() {} 75 QuicBufferedPacketStore::~QuicBufferedPacketStore() {}
76 76
77 EnqueuePacketResult QuicBufferedPacketStore::EnqueuePacket( 77 EnqueuePacketResult QuicBufferedPacketStore::EnqueuePacket(
78 QuicConnectionId connection_id, 78 QuicConnectionId connection_id,
79 const QuicReceivedPacket& packet, 79 const QuicReceivedPacket& packet,
80 IPEndPoint server_address, 80 IPEndPoint server_address,
81 IPEndPoint client_address) { 81 IPEndPoint client_address) {
82 if (!ContainsKey(undecryptable_packets_, connection_id) && 82 if (!base::ContainsKey(undecryptable_packets_, connection_id) &&
83 undecryptable_packets_.size() >= kDefaultMaxConnectionsInStore) { 83 undecryptable_packets_.size() >= kDefaultMaxConnectionsInStore) {
84 // Drop the packet if store can't keep track of more connections. 84 // Drop the packet if store can't keep track of more connections.
85 return TOO_MANY_CONNECTIONS; 85 return TOO_MANY_CONNECTIONS;
86 } else if (!ContainsKey(undecryptable_packets_, connection_id)) { 86 } else if (!base::ContainsKey(undecryptable_packets_, connection_id)) {
87 undecryptable_packets_.emplace( 87 undecryptable_packets_.emplace(
88 std::make_pair(connection_id, BufferedPacketList())); 88 std::make_pair(connection_id, BufferedPacketList()));
89 } 89 }
90 CHECK(ContainsKey(undecryptable_packets_, connection_id)); 90 CHECK(base::ContainsKey(undecryptable_packets_, connection_id));
91 BufferedPacketList& queue = 91 BufferedPacketList& queue =
92 undecryptable_packets_.find(connection_id)->second; 92 undecryptable_packets_.find(connection_id)->second;
93 93
94 if (queue.buffered_packets.size() >= kDefaultMaxUndecryptablePackets) { 94 if (queue.buffered_packets.size() >= kDefaultMaxUndecryptablePackets) {
95 // If there are kMaxBufferedPacketsPerConnection packets buffered up for 95 // If there are kMaxBufferedPacketsPerConnection packets buffered up for
96 // this connection, drop the current packet. 96 // this connection, drop the current packet.
97 return TOO_MANY_PACKETS; 97 return TOO_MANY_PACKETS;
98 } 98 }
99 99
100 if (queue.buffered_packets.empty()) { 100 if (queue.buffered_packets.empty()) {
101 // If this is the first packet arrived on a new connection, initialize the 101 // If this is the first packet arrived on a new connection, initialize the
102 // creation time. 102 // creation time.
103 queue.creation_time = clock_->ApproximateNow(); 103 queue.creation_time = clock_->ApproximateNow();
104 } 104 }
105 105
106 BufferedPacket new_entry(std::unique_ptr<QuicReceivedPacket>(packet.Clone()), 106 BufferedPacket new_entry(std::unique_ptr<QuicReceivedPacket>(packet.Clone()),
107 server_address, client_address); 107 server_address, client_address);
108 108
109 queue.buffered_packets.push_back(std::move(new_entry)); 109 queue.buffered_packets.push_back(std::move(new_entry));
110 110
111 if (!expiration_alarm_->IsSet()) { 111 if (!expiration_alarm_->IsSet()) {
112 expiration_alarm_->Set(clock_->ApproximateNow() + connection_life_span_); 112 expiration_alarm_->Set(clock_->ApproximateNow() + connection_life_span_);
113 } 113 }
114 return SUCCESS; 114 return SUCCESS;
115 } 115 }
116 116
117 bool QuicBufferedPacketStore::HasBufferedPackets( 117 bool QuicBufferedPacketStore::HasBufferedPackets(
118 QuicConnectionId connection_id) const { 118 QuicConnectionId connection_id) const {
119 return ContainsKey(undecryptable_packets_, connection_id); 119 return base::ContainsKey(undecryptable_packets_, connection_id);
120 } 120 }
121 121
122 list<BufferedPacket> QuicBufferedPacketStore::DeliverPackets( 122 list<BufferedPacket> QuicBufferedPacketStore::DeliverPackets(
123 QuicConnectionId connection_id) { 123 QuicConnectionId connection_id) {
124 list<BufferedPacket> packets_to_deliver; 124 list<BufferedPacket> packets_to_deliver;
125 auto it = undecryptable_packets_.find(connection_id); 125 auto it = undecryptable_packets_.find(connection_id);
126 if (it != undecryptable_packets_.end()) { 126 if (it != undecryptable_packets_.end()) {
127 packets_to_deliver = std::move(it->second.buffered_packets); 127 packets_to_deliver = std::move(it->second.buffered_packets);
128 undecryptable_packets_.erase(connection_id); 128 undecryptable_packets_.erase(connection_id);
129 } 129 }
130 return packets_to_deliver; 130 return packets_to_deliver;
131 } 131 }
132 132
133 void QuicBufferedPacketStore::OnExpirationTimeout() { 133 void QuicBufferedPacketStore::OnExpirationTimeout() {
134 QuicTime expiration_time = clock_->ApproximateNow() - connection_life_span_; 134 QuicTime expiration_time = clock_->ApproximateNow() - connection_life_span_;
135 while (!undecryptable_packets_.empty()) { 135 while (!undecryptable_packets_.empty()) {
136 auto& entry = undecryptable_packets_.front(); 136 auto& entry = undecryptable_packets_.front();
137 if (entry.second.creation_time > expiration_time) { 137 if (entry.second.creation_time > expiration_time) {
138 break; 138 break;
139 } 139 }
140 visitor_->OnExpiredPackets(entry.first, std::move(entry.second)); 140 visitor_->OnExpiredPackets(entry.first, std::move(entry.second));
141 undecryptable_packets_.erase(undecryptable_packets_.begin()); 141 undecryptable_packets_.erase(undecryptable_packets_.begin());
142 } 142 }
143 if (!undecryptable_packets_.empty()) { 143 if (!undecryptable_packets_.empty()) {
144 expiration_alarm_->Set(clock_->ApproximateNow() + connection_life_span_); 144 expiration_alarm_->Set(clock_->ApproximateNow() + connection_life_span_);
145 } 145 }
146 } 146 }
147 147
148 } // namespace net 148 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/interval_test.cc ('k') | net/quic/core/quic_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698