| OLD | NEW |
| 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/quic_buffered_packet_store.h" | 5 #include "net/quic/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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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().Add(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 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 = | 134 QuicTime expiration_time = clock_->ApproximateNow() - connection_life_span_; |
| 135 clock_->ApproximateNow().Subtract(connection_life_span_); | |
| 136 while (!undecryptable_packets_.empty()) { | 135 while (!undecryptable_packets_.empty()) { |
| 137 auto& entry = undecryptable_packets_.front(); | 136 auto& entry = undecryptable_packets_.front(); |
| 138 if (entry.second.creation_time > expiration_time) { | 137 if (entry.second.creation_time > expiration_time) { |
| 139 break; | 138 break; |
| 140 } | 139 } |
| 141 visitor_->OnExpiredPackets(entry.first, std::move(entry.second)); | 140 visitor_->OnExpiredPackets(entry.first, std::move(entry.second)); |
| 142 undecryptable_packets_.erase(undecryptable_packets_.begin()); | 141 undecryptable_packets_.erase(undecryptable_packets_.begin()); |
| 143 } | 142 } |
| 144 if (!undecryptable_packets_.empty()) { | 143 if (!undecryptable_packets_.empty()) { |
| 145 expiration_alarm_->Set(clock_->ApproximateNow().Add(connection_life_span_)); | 144 expiration_alarm_->Set(clock_->ApproximateNow() + connection_life_span_); |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 | 147 |
| 149 } // namespace net | 148 } // namespace net |
| OLD | NEW |