OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromium/quic_chromium_client_session.h" | 5 #include "net/quic/chromium/quic_chromium_client_session.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/log/net_log_event_type.h" | 24 #include "net/log/net_log_event_type.h" |
25 #include "net/log/net_log_source_type.h" | 25 #include "net/log/net_log_source_type.h" |
26 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 26 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
27 #include "net/quic/chromium/quic_chromium_connection_helper.h" | 27 #include "net/quic/chromium/quic_chromium_connection_helper.h" |
28 #include "net/quic/chromium/quic_chromium_packet_writer.h" | 28 #include "net/quic/chromium/quic_chromium_packet_writer.h" |
29 #include "net/quic/chromium/quic_stream_factory.h" | 29 #include "net/quic/chromium/quic_stream_factory.h" |
30 #include "net/quic/core/crypto/quic_server_info.h" | 30 #include "net/quic/core/crypto/quic_server_info.h" |
31 #include "net/quic/core/quic_client_promised_info.h" | 31 #include "net/quic/core/quic_client_promised_info.h" |
32 #include "net/quic/core/quic_crypto_client_stream_factory.h" | 32 #include "net/quic/core/quic_crypto_client_stream_factory.h" |
33 #include "net/quic/core/spdy_utils.h" | 33 #include "net/quic/core/spdy_utils.h" |
| 34 #include "net/spdy/spdy_http_utils.h" |
34 #include "net/spdy/spdy_session.h" | 35 #include "net/spdy/spdy_session.h" |
35 #include "net/ssl/channel_id_service.h" | 36 #include "net/ssl/channel_id_service.h" |
36 #include "net/ssl/ssl_connection_status_flags.h" | 37 #include "net/ssl/ssl_connection_status_flags.h" |
37 #include "net/ssl/ssl_info.h" | 38 #include "net/ssl/ssl_info.h" |
38 #include "net/ssl/token_binding.h" | 39 #include "net/ssl/token_binding.h" |
39 #include "net/udp/datagram_client_socket.h" | 40 #include "net/udp/datagram_client_socket.h" |
40 #include "third_party/boringssl/src/include/openssl/ssl.h" | 41 #include "third_party/boringssl/src/include/openssl/ssl.h" |
41 | 42 |
42 namespace net { | 43 namespace net { |
43 | 44 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 }; | 156 }; |
156 | 157 |
157 class HpackDecoderDebugVisitor : public QuicHeadersStream::HpackDebugVisitor { | 158 class HpackDecoderDebugVisitor : public QuicHeadersStream::HpackDebugVisitor { |
158 void OnUseEntry(QuicTime::Delta elapsed) override { | 159 void OnUseEntry(QuicTime::Delta elapsed) override { |
159 UMA_HISTOGRAM_TIMES( | 160 UMA_HISTOGRAM_TIMES( |
160 "Net.QuicHpackDecoder.IndexedEntryAge", | 161 "Net.QuicHpackDecoder.IndexedEntryAge", |
161 base::TimeDelta::FromMicroseconds(elapsed.ToMicroseconds())); | 162 base::TimeDelta::FromMicroseconds(elapsed.ToMicroseconds())); |
162 } | 163 } |
163 }; | 164 }; |
164 | 165 |
| 166 class QuicServerPushHelper : public ServerPushDelegate::ServerPushHelper { |
| 167 public: |
| 168 explicit QuicServerPushHelper( |
| 169 base::WeakPtr<QuicChromiumClientSession> session, |
| 170 const GURL& url) |
| 171 : session_(session), request_url_(url) {} |
| 172 |
| 173 void Cancel() override { |
| 174 if (session_) { |
| 175 session_->CancelPush(request_url_); |
| 176 } |
| 177 } |
| 178 |
| 179 const GURL& GetURL() override { return request_url_; } |
| 180 |
| 181 private: |
| 182 base::WeakPtr<QuicChromiumClientSession> session_; |
| 183 const GURL request_url_; |
| 184 }; |
| 185 |
165 } // namespace | 186 } // namespace |
166 | 187 |
167 QuicChromiumClientSession::StreamRequest::StreamRequest() : stream_(nullptr) {} | 188 QuicChromiumClientSession::StreamRequest::StreamRequest() : stream_(nullptr) {} |
168 | 189 |
169 QuicChromiumClientSession::StreamRequest::~StreamRequest() { | 190 QuicChromiumClientSession::StreamRequest::~StreamRequest() { |
170 CancelRequest(); | 191 CancelRequest(); |
171 } | 192 } |
172 | 193 |
173 int QuicChromiumClientSession::StreamRequest::StartRequest( | 194 int QuicChromiumClientSession::StreamRequest::StartRequest( |
174 const base::WeakPtr<QuicChromiumClientSession>& session, | 195 const base::WeakPtr<QuicChromiumClientSession>& session, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 num_total_streams_(0), | 256 num_total_streams_(0), |
236 task_runner_(task_runner), | 257 task_runner_(task_runner), |
237 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::QUIC_SESSION)), | 258 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::QUIC_SESSION)), |
238 logger_(new QuicConnectionLogger(this, | 259 logger_(new QuicConnectionLogger(this, |
239 connection_description, | 260 connection_description, |
240 std::move(socket_performance_watcher), | 261 std::move(socket_performance_watcher), |
241 net_log_)), | 262 net_log_)), |
242 going_away_(false), | 263 going_away_(false), |
243 port_migration_detected_(false), | 264 port_migration_detected_(false), |
244 token_binding_signatures_(kTokenBindingSignatureMapSize), | 265 token_binding_signatures_(kTokenBindingSignatureMapSize), |
| 266 push_delegate_(nullptr), |
245 streams_pushed_count_(0), | 267 streams_pushed_count_(0), |
246 streams_pushed_and_claimed_count_(0), | 268 streams_pushed_and_claimed_count_(0), |
247 bytes_pushed_count_(0), | 269 bytes_pushed_count_(0), |
248 bytes_pushed_and_unclaimed_count_(0), | 270 bytes_pushed_and_unclaimed_count_(0), |
249 migration_pending_(false), | 271 migration_pending_(false), |
250 weak_factory_(this) { | 272 weak_factory_(this) { |
251 sockets_.push_back(std::move(socket)); | 273 sockets_.push_back(std::move(socket)); |
252 packet_readers_.push_back(base::MakeUnique<QuicChromiumPacketReader>( | 274 packet_readers_.push_back(base::MakeUnique<QuicChromiumPacketReader>( |
253 sockets_.back().get(), clock, this, yield_after_packets, | 275 sockets_.back().get(), clock, this, yield_after_packets, |
254 yield_after_duration, net_log_)); | 276 yield_after_duration, net_log_)); |
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1411 bool QuicChromiumClientSession::HasNonMigratableStreams() const { | 1433 bool QuicChromiumClientSession::HasNonMigratableStreams() const { |
1412 for (const auto& stream : dynamic_streams()) { | 1434 for (const auto& stream : dynamic_streams()) { |
1413 if (!static_cast<QuicChromiumClientStream*>(stream.second.get()) | 1435 if (!static_cast<QuicChromiumClientStream*>(stream.second.get()) |
1414 ->can_migrate()) { | 1436 ->can_migrate()) { |
1415 return true; | 1437 return true; |
1416 } | 1438 } |
1417 } | 1439 } |
1418 return false; | 1440 return false; |
1419 } | 1441 } |
1420 | 1442 |
1421 void QuicChromiumClientSession::HandlePromised(QuicStreamId id, | 1443 bool QuicChromiumClientSession::HandlePromised(QuicStreamId id, |
1422 QuicStreamId promised_id, | 1444 QuicStreamId promised_id, |
1423 const SpdyHeaderBlock& headers) { | 1445 const SpdyHeaderBlock& headers) { |
1424 QuicClientSessionBase::HandlePromised(id, promised_id, headers); | 1446 bool result = QuicClientSessionBase::HandlePromised(id, promised_id, headers); |
| 1447 if (result) { |
| 1448 // The push promise is accepted, notify the push_delegate that a push |
| 1449 // promise has been received. |
| 1450 GURL pushed_url = GetUrlFromHeaderBlock(headers); |
| 1451 if (push_delegate_) { |
| 1452 push_delegate_->OnPush(base::MakeUnique<QuicServerPushHelper>( |
| 1453 weak_factory_.GetWeakPtr(), pushed_url)); |
| 1454 } |
| 1455 } |
1425 net_log_.AddEvent(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, | 1456 net_log_.AddEvent(NetLogEventType::QUIC_SESSION_PUSH_PROMISE_RECEIVED, |
1426 base::Bind(&NetLogQuicPushPromiseReceivedCallback, &headers, | 1457 base::Bind(&NetLogQuicPushPromiseReceivedCallback, &headers, |
1427 id, promised_id)); | 1458 id, promised_id)); |
| 1459 return result; |
1428 } | 1460 } |
1429 | 1461 |
1430 void QuicChromiumClientSession::DeletePromised( | 1462 void QuicChromiumClientSession::DeletePromised( |
1431 QuicClientPromisedInfo* promised) { | 1463 QuicClientPromisedInfo* promised) { |
1432 if (IsOpenStream(promised->id())) | 1464 if (IsOpenStream(promised->id())) |
1433 streams_pushed_and_claimed_count_++; | 1465 streams_pushed_and_claimed_count_++; |
1434 QuicClientSessionBase::DeletePromised(promised); | 1466 QuicClientSessionBase::DeletePromised(promised); |
1435 } | 1467 } |
1436 | 1468 |
1437 void QuicChromiumClientSession::OnPushStreamTimedOut(QuicStreamId stream_id) { | 1469 void QuicChromiumClientSession::OnPushStreamTimedOut(QuicStreamId stream_id) { |
1438 QuicSpdyStream* stream = GetPromisedStream(stream_id); | 1470 QuicSpdyStream* stream = GetPromisedStream(stream_id); |
1439 if (stream != nullptr) | 1471 if (stream != nullptr) |
1440 bytes_pushed_and_unclaimed_count_ += stream->stream_bytes_read(); | 1472 bytes_pushed_and_unclaimed_count_ += stream->stream_bytes_read(); |
1441 } | 1473 } |
1442 | 1474 |
1443 void QuicChromiumClientSession::CancelPush(const GURL& url) { | 1475 void QuicChromiumClientSession::CancelPush(const GURL& url) { |
1444 QuicClientPromisedInfo* promised_info = | 1476 QuicClientPromisedInfo* promised_info = |
1445 QuicClientSessionBase::GetPromisedByUrl(url.spec()); | 1477 QuicClientSessionBase::GetPromisedByUrl(url.spec()); |
1446 if (!promised_info) { | 1478 if (!promised_info || promised_info->is_validating()) { |
1447 // Push stream has already been claimed. | 1479 // Push stream has already been claimed or is pending matched to a request. |
1448 return; | 1480 return; |
1449 } | 1481 } |
1450 | 1482 |
1451 QuicStreamId stream_id = promised_info->id(); | 1483 QuicStreamId stream_id = promised_info->id(); |
1452 | 1484 |
1453 // Collect data on the cancelled push stream. | 1485 // Collect data on the cancelled push stream. |
1454 QuicSpdyStream* stream = GetPromisedStream(stream_id); | 1486 QuicSpdyStream* stream = GetPromisedStream(stream_id); |
1455 if (stream != nullptr) | 1487 if (stream != nullptr) |
1456 bytes_pushed_and_unclaimed_count_ += stream->stream_bytes_read(); | 1488 bytes_pushed_and_unclaimed_count_ += stream->stream_bytes_read(); |
1457 | 1489 |
1458 // Send the reset and remove the promised info from the promise index. | 1490 // Send the reset and remove the promised info from the promise index. |
1459 QuicClientSessionBase::ResetPromised(stream_id, QUIC_STREAM_CANCELLED); | 1491 QuicClientSessionBase::ResetPromised(stream_id, QUIC_STREAM_CANCELLED); |
1460 DeletePromised(promised_info); | 1492 DeletePromised(promised_info); |
1461 } | 1493 } |
1462 | 1494 |
1463 const LoadTimingInfo::ConnectTiming& | 1495 const LoadTimingInfo::ConnectTiming& |
1464 QuicChromiumClientSession::GetConnectTiming() { | 1496 QuicChromiumClientSession::GetConnectTiming() { |
1465 connect_timing_.ssl_start = connect_timing_.connect_start; | 1497 connect_timing_.ssl_start = connect_timing_.connect_start; |
1466 connect_timing_.ssl_end = connect_timing_.connect_end; | 1498 connect_timing_.ssl_end = connect_timing_.connect_end; |
1467 return connect_timing_; | 1499 return connect_timing_; |
1468 } | 1500 } |
1469 | 1501 |
1470 QuicVersion QuicChromiumClientSession::GetQuicVersion() const { | 1502 QuicVersion QuicChromiumClientSession::GetQuicVersion() const { |
1471 return connection()->version(); | 1503 return connection()->version(); |
1472 } | 1504 } |
1473 | 1505 |
1474 } // namespace net | 1506 } // namespace net |
OLD | NEW |