| 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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "base/trace_event/memory_usage_estimator.h" |
| 28 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
| 29 #include "base/values.h" | 30 #include "base/values.h" |
| 30 #include "crypto/ec_private_key.h" | 31 #include "crypto/ec_private_key.h" |
| 31 #include "crypto/ec_signature_creator.h" | 32 #include "crypto/ec_signature_creator.h" |
| 32 #include "net/base/proxy_delegate.h" | 33 #include "net/base/proxy_delegate.h" |
| 33 #include "net/cert/asn1_util.h" | 34 #include "net/cert/asn1_util.h" |
| 34 #include "net/cert/cert_verify_result.h" | 35 #include "net/cert/cert_verify_result.h" |
| 35 #include "net/cert/ct_policy_status.h" | 36 #include "net/cert/ct_policy_status.h" |
| 36 #include "net/http/http_log_util.h" | 37 #include "net/http/http_log_util.h" |
| 37 #include "net/http/http_network_session.h" | 38 #include "net/http/http_network_session.h" |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 566 } |
| 566 | 567 |
| 567 base::WeakPtr<SpdyStream> SpdyStreamRequest::ReleaseStream() { | 568 base::WeakPtr<SpdyStream> SpdyStreamRequest::ReleaseStream() { |
| 568 DCHECK(!session_); | 569 DCHECK(!session_); |
| 569 base::WeakPtr<SpdyStream> stream = stream_; | 570 base::WeakPtr<SpdyStream> stream = stream_; |
| 570 DCHECK(stream); | 571 DCHECK(stream); |
| 571 Reset(); | 572 Reset(); |
| 572 return stream; | 573 return stream; |
| 573 } | 574 } |
| 574 | 575 |
| 576 size_t SpdyStreamRequest::EstimateMemoryUsage() const { |
| 577 return base::trace_event::EstimateItemMemoryUsage(url_); |
| 578 } |
| 579 |
| 575 void SpdyStreamRequest::OnRequestCompleteSuccess( | 580 void SpdyStreamRequest::OnRequestCompleteSuccess( |
| 576 const base::WeakPtr<SpdyStream>& stream) { | 581 const base::WeakPtr<SpdyStream>& stream) { |
| 577 DCHECK(session_); | 582 DCHECK(session_); |
| 578 DCHECK(!stream_); | 583 DCHECK(!stream_); |
| 579 DCHECK(!callback_.is_null()); | 584 DCHECK(!callback_.is_null()); |
| 580 CompletionCallback callback = callback_; | 585 CompletionCallback callback = callback_; |
| 581 Reset(); | 586 Reset(); |
| 582 DCHECK(stream); | 587 DCHECK(stream); |
| 583 stream_ = stream; | 588 stream_ = stream; |
| 584 callback.Run(OK); | 589 callback.Run(OK); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 spdy_session_->pool_->RegisterUnclaimedPushedStream( | 648 spdy_session_->pool_->RegisterUnclaimedPushedStream( |
| 644 url, spdy_session_->GetWeakPtr()); | 649 url, spdy_session_->GetWeakPtr()); |
| 645 } | 650 } |
| 646 return streams_.insert( | 651 return streams_.insert( |
| 647 position, | 652 position, |
| 648 std::make_pair( | 653 std::make_pair( |
| 649 url, SpdySession::UnclaimedPushedStreamContainer::PushedStreamInfo( | 654 url, SpdySession::UnclaimedPushedStreamContainer::PushedStreamInfo( |
| 650 stream_id, creation_time))); | 655 stream_id, creation_time))); |
| 651 } | 656 } |
| 652 | 657 |
| 658 size_t SpdySession::UnclaimedPushedStreamContainer::EstimateMemoryUsage() |
| 659 const { |
| 660 return base::trace_event::EstimateMemoryUsage(streams_); |
| 661 } |
| 662 |
| 653 // static | 663 // static |
| 654 bool SpdySession::CanPool(TransportSecurityState* transport_security_state, | 664 bool SpdySession::CanPool(TransportSecurityState* transport_security_state, |
| 655 const SSLInfo& ssl_info, | 665 const SSLInfo& ssl_info, |
| 656 const std::string& old_hostname, | 666 const std::string& old_hostname, |
| 657 const std::string& new_hostname) { | 667 const std::string& new_hostname) { |
| 658 // Pooling is prohibited if the server cert is not valid for the new domain, | 668 // Pooling is prohibited if the server cert is not valid for the new domain, |
| 659 // and for connections on which client certs were sent. It is also prohibited | 669 // and for connections on which client certs were sent. It is also prohibited |
| 660 // when channel ID was sent if the hosts are from different eTLDs+1. | 670 // when channel ID was sent if the hosts are from different eTLDs+1. |
| 661 if (IsCertStatusError(ssl_info.cert_status)) | 671 if (IsCertStatusError(ssl_info.cert_status)) |
| 662 return false; | 672 return false; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 bool SpdySession::CloseOneIdleConnection() { | 1075 bool SpdySession::CloseOneIdleConnection() { |
| 1066 CHECK(!in_io_loop_); | 1076 CHECK(!in_io_loop_); |
| 1067 DCHECK(pool_); | 1077 DCHECK(pool_); |
| 1068 if (active_streams_.empty()) { | 1078 if (active_streams_.empty()) { |
| 1069 DoDrainSession(ERR_CONNECTION_CLOSED, "Closing idle connection."); | 1079 DoDrainSession(ERR_CONNECTION_CLOSED, "Closing idle connection."); |
| 1070 } | 1080 } |
| 1071 // Return false as the socket wasn't immediately closed. | 1081 // Return false as the socket wasn't immediately closed. |
| 1072 return false; | 1082 return false; |
| 1073 } | 1083 } |
| 1074 | 1084 |
| 1075 void SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, | 1085 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, |
| 1076 bool* is_session_active) const { | 1086 bool* is_session_active) const { |
| 1087 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is |
| 1088 // supported in memory_usage_estimator.h. |
| 1077 *is_session_active = is_active(); | 1089 *is_session_active = is_active(); |
| 1078 connection_->DumpMemoryStats(stats); | 1090 connection_->DumpMemoryStats(stats); |
| 1091 // |connection_| is estimated in stats->total_size. |read_buffer_| is |
| 1092 // estimated in kReadBufferSize. TODO(xunjieli): Make them use EMU(). |
| 1093 return stats->total_size + kReadBufferSize + |
| 1094 base::trace_event::EstimateMemoryUsage(spdy_session_key_) + |
| 1095 base::trace_event::EstimateMemoryUsage(pooled_aliases_) + |
| 1096 base::trace_event::EstimateMemoryUsage(active_streams_) + |
| 1097 base::trace_event::EstimateMemoryUsage(unclaimed_pushed_streams_) + |
| 1098 base::trace_event::EstimateMemoryUsage(created_streams_) + |
| 1099 base::trace_event::EstimateMemoryUsage(write_queue_) + |
| 1100 base::trace_event::EstimateMemoryUsage(in_flight_write_) + |
| 1101 base::trace_event::EstimateMemoryUsage(buffered_spdy_framer_) + |
| 1102 base::trace_event::EstimateMemoryUsage(initial_settings_) + |
| 1103 base::trace_event::EstimateMemoryUsage(stream_send_unstall_queue_) + |
| 1104 base::trace_event::EstimateMemoryUsage(priority_dependency_state_); |
| 1079 } | 1105 } |
| 1080 | 1106 |
| 1081 void SpdySession::EnqueueStreamWrite( | 1107 void SpdySession::EnqueueStreamWrite( |
| 1082 const base::WeakPtr<SpdyStream>& stream, | 1108 const base::WeakPtr<SpdyStream>& stream, |
| 1083 SpdyFrameType frame_type, | 1109 SpdyFrameType frame_type, |
| 1084 std::unique_ptr<SpdyBufferProducer> producer) { | 1110 std::unique_ptr<SpdyBufferProducer> producer) { |
| 1085 DCHECK(frame_type == HEADERS || frame_type == DATA); | 1111 DCHECK(frame_type == HEADERS || frame_type == DATA); |
| 1086 EnqueueWrite(stream->priority(), frame_type, std::move(producer), stream); | 1112 EnqueueWrite(stream->priority(), frame_type, std::move(producer), stream); |
| 1087 } | 1113 } |
| 1088 | 1114 |
| (...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3129 if (!queue->empty()) { | 3155 if (!queue->empty()) { |
| 3130 SpdyStreamId stream_id = queue->front(); | 3156 SpdyStreamId stream_id = queue->front(); |
| 3131 queue->pop_front(); | 3157 queue->pop_front(); |
| 3132 return stream_id; | 3158 return stream_id; |
| 3133 } | 3159 } |
| 3134 } | 3160 } |
| 3135 return 0; | 3161 return 0; |
| 3136 } | 3162 } |
| 3137 | 3163 |
| 3138 } // namespace net | 3164 } // namespace net |
| OLD | NEW |