| 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_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
| 24 #include "net/log/net_log_capture_mode.h" | 24 #include "net/log/net_log_capture_mode.h" |
| 25 #include "net/log/net_log_event_type.h" | 25 #include "net/log/net_log_event_type.h" |
| 26 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 26 #include "net/spdy/spdy_buffer_producer.h" | 27 #include "net/spdy/spdy_buffer_producer.h" |
| 27 #include "net/spdy/spdy_http_utils.h" | 28 #include "net/spdy/spdy_http_utils.h" |
| 28 #include "net/spdy/spdy_session.h" | 29 #include "net/spdy/spdy_session.h" |
| 29 | 30 |
| 30 namespace net { | 31 namespace net { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 enum StatusHeader { | 35 enum StatusHeader { |
| 35 STATUS_HEADER_NOT_INCLUDED = 0, | 36 STATUS_HEADER_NOT_INCLUDED = 0, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 106 |
| 106 std::unique_ptr<SpdyBuffer> ProduceBuffer() override { | 107 std::unique_ptr<SpdyBuffer> ProduceBuffer() override { |
| 107 if (!stream_.get()) { | 108 if (!stream_.get()) { |
| 108 NOTREACHED(); | 109 NOTREACHED(); |
| 109 return std::unique_ptr<SpdyBuffer>(); | 110 return std::unique_ptr<SpdyBuffer>(); |
| 110 } | 111 } |
| 111 DCHECK_GT(stream_->stream_id(), 0u); | 112 DCHECK_GT(stream_->stream_id(), 0u); |
| 112 return std::unique_ptr<SpdyBuffer>( | 113 return std::unique_ptr<SpdyBuffer>( |
| 113 new SpdyBuffer(stream_->ProduceHeadersFrame())); | 114 new SpdyBuffer(stream_->ProduceHeadersFrame())); |
| 114 } | 115 } |
| 116 size_t EstimateMemoryUsage() const override { return 0; } |
| 115 | 117 |
| 116 private: | 118 private: |
| 117 const base::WeakPtr<SpdyStream> stream_; | 119 const base::WeakPtr<SpdyStream> stream_; |
| 118 }; | 120 }; |
| 119 | 121 |
| 120 SpdyStream::SpdyStream(SpdyStreamType type, | 122 SpdyStream::SpdyStream(SpdyStreamType type, |
| 121 const base::WeakPtr<SpdySession>& session, | 123 const base::WeakPtr<SpdySession>& session, |
| 122 const GURL& url, | 124 const GURL& url, |
| 123 RequestPriority priority, | 125 RequestPriority priority, |
| 124 int32_t initial_send_window_size, | 126 int32_t initial_send_window_size, |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 if (type_ == SPDY_PUSH_STREAM) { | 815 if (type_ == SPDY_PUSH_STREAM) { |
| 814 load_timing_info->push_start = recv_first_byte_time_; | 816 load_timing_info->push_start = recv_first_byte_time_; |
| 815 bool done_receiving = IsClosed() || (!pending_recv_data_.empty() && | 817 bool done_receiving = IsClosed() || (!pending_recv_data_.empty() && |
| 816 !pending_recv_data_.back()); | 818 !pending_recv_data_.back()); |
| 817 if (done_receiving) | 819 if (done_receiving) |
| 818 load_timing_info->push_end = recv_last_byte_time_; | 820 load_timing_info->push_end = recv_last_byte_time_; |
| 819 } | 821 } |
| 820 return result; | 822 return result; |
| 821 } | 823 } |
| 822 | 824 |
| 825 size_t SpdyStream::EstimateMemoryUsage() const { |
| 826 // TODO(xunjieli): https://crbug.com/669108. Estimate |pending_send_data_| |
| 827 // once scoped_refptr support is in. |
| 828 return SpdyEstimateMemoryUsage(url_) + |
| 829 SpdyEstimateMemoryUsage(request_headers_) + |
| 830 SpdyEstimateMemoryUsage(url_from_header_block_) + |
| 831 SpdyEstimateMemoryUsage(pending_recv_data_) + |
| 832 SpdyEstimateMemoryUsage(response_headers_); |
| 833 } |
| 834 |
| 823 void SpdyStream::UpdateHistograms() { | 835 void SpdyStream::UpdateHistograms() { |
| 824 // We need at least the receive timers to be filled in, as otherwise | 836 // We need at least the receive timers to be filled in, as otherwise |
| 825 // metrics can be bogus. | 837 // metrics can be bogus. |
| 826 if (recv_first_byte_time_.is_null() || recv_last_byte_time_.is_null()) | 838 if (recv_first_byte_time_.is_null() || recv_last_byte_time_.is_null()) |
| 827 return; | 839 return; |
| 828 | 840 |
| 829 base::TimeTicks effective_send_time; | 841 base::TimeTicks effective_send_time; |
| 830 if (type_ == SPDY_PUSH_STREAM) { | 842 if (type_ == SPDY_PUSH_STREAM) { |
| 831 // Push streams shouldn't have |send_time_| filled in. | 843 // Push streams shouldn't have |send_time_| filled in. |
| 832 DCHECK(send_time_.is_null()); | 844 DCHECK(send_time_.is_null()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 953 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
| 942 state); | 954 state); |
| 943 break; | 955 break; |
| 944 } | 956 } |
| 945 return description; | 957 return description; |
| 946 } | 958 } |
| 947 | 959 |
| 948 #undef STATE_CASE | 960 #undef STATE_CASE |
| 949 | 961 |
| 950 } // namespace net | 962 } // namespace net |
| OLD | NEW |