Chromium Code Reviews| 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/field_trial.h" | |
|
davidben
2017/02/10 23:33:49
No longer used.
xunjieli
2017/02/13 20:28:19
Done.
| |
| 17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/metrics/sparse_histogram.h" | 19 #include "base/metrics/sparse_histogram.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 20 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 38 #include "net/http/http_server_properties.h" | 39 #include "net/http/http_server_properties.h" |
| 39 #include "net/http/http_util.h" | 40 #include "net/http/http_util.h" |
| 40 #include "net/http/transport_security_state.h" | 41 #include "net/http/transport_security_state.h" |
| 41 #include "net/log/net_log.h" | 42 #include "net/log/net_log.h" |
| 42 #include "net/log/net_log_capture_mode.h" | 43 #include "net/log/net_log_capture_mode.h" |
| 43 #include "net/log/net_log_event_type.h" | 44 #include "net/log/net_log_event_type.h" |
| 44 #include "net/log/net_log_source.h" | 45 #include "net/log/net_log_source.h" |
| 45 #include "net/log/net_log_source_type.h" | 46 #include "net/log/net_log_source_type.h" |
| 46 #include "net/log/net_log_with_source.h" | 47 #include "net/log/net_log_with_source.h" |
| 47 #include "net/proxy/proxy_server.h" | 48 #include "net/proxy/proxy_server.h" |
| 49 #include "net/socket/socket.h" | |
| 48 #include "net/socket/ssl_client_socket.h" | 50 #include "net/socket/ssl_client_socket.h" |
| 49 #include "net/spdy/spdy_buffer_producer.h" | 51 #include "net/spdy/spdy_buffer_producer.h" |
| 50 #include "net/spdy/spdy_frame_builder.h" | 52 #include "net/spdy/spdy_frame_builder.h" |
| 51 #include "net/spdy/spdy_http_utils.h" | 53 #include "net/spdy/spdy_http_utils.h" |
| 52 #include "net/spdy/spdy_protocol.h" | 54 #include "net/spdy/spdy_protocol.h" |
| 53 #include "net/spdy/spdy_session_pool.h" | 55 #include "net/spdy/spdy_session_pool.h" |
| 54 #include "net/spdy/spdy_stream.h" | 56 #include "net/spdy/spdy_stream.h" |
| 55 #include "net/ssl/channel_id_service.h" | 57 #include "net/ssl/channel_id_service.h" |
| 56 #include "net/ssl/ssl_cipher_suite_names.h" | 58 #include "net/ssl/ssl_cipher_suite_names.h" |
| 57 #include "net/ssl/ssl_connection_status_flags.h" | 59 #include "net/ssl/ssl_connection_status_flags.h" |
| (...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1769 } | 1771 } |
| 1770 | 1772 |
| 1771 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { | 1773 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { |
| 1772 CHECK(!in_io_loop_); | 1774 CHECK(!in_io_loop_); |
| 1773 if (availability_state_ == STATE_DRAINING) { | 1775 if (availability_state_ == STATE_DRAINING) { |
| 1774 return; | 1776 return; |
| 1775 } | 1777 } |
| 1776 ignore_result(DoReadLoop(expected_read_state, result)); | 1778 ignore_result(DoReadLoop(expected_read_state, result)); |
| 1777 } | 1779 } |
| 1778 | 1780 |
| 1781 int SpdySession::DoRead() { | |
| 1782 CHECK(in_io_loop_); | |
| 1783 | |
| 1784 CHECK(connection_); | |
| 1785 CHECK(connection_->socket()); | |
| 1786 read_state_ = READ_STATE_DO_READ_COMPLETE; | |
| 1787 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; | |
| 1788 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { | |
|
davidben
2017/02/10 23:33:49
#include "base/feature_list.h"
xunjieli
2017/02/13 20:28:19
Done.
| |
| 1789 rv = connection_->socket()->ReadIfReady( | |
| 1790 read_buffer_.get(), kReadBufferSize, | |
| 1791 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
| 1792 READ_STATE_DO_READ)); | |
| 1793 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. crbug.com/524258. | |
| 1794 } | |
| 1795 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { | |
| 1796 // Fallback to regular Read(). | |
| 1797 return connection_->socket()->Read( | |
| 1798 read_buffer_.get(), kReadBufferSize, | |
| 1799 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
| 1800 READ_STATE_DO_READ_COMPLETE)); | |
| 1801 } | |
| 1802 if (rv == ERR_IO_PENDING) | |
| 1803 read_state_ = READ_STATE_DO_READ; | |
| 1804 return rv; | |
| 1805 } | |
| 1806 | |
| 1779 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { | 1807 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { |
| 1780 CHECK(!in_io_loop_); | 1808 CHECK(!in_io_loop_); |
| 1781 CHECK_EQ(read_state_, expected_read_state); | 1809 CHECK_EQ(read_state_, expected_read_state); |
| 1782 | 1810 |
| 1783 in_io_loop_ = true; | 1811 in_io_loop_ = true; |
| 1784 | 1812 |
| 1785 int bytes_read_without_yielding = 0; | 1813 int bytes_read_without_yielding = 0; |
| 1786 const base::TimeTicks yield_after_time = | 1814 const base::TimeTicks yield_after_time = |
| 1787 time_func_() + | 1815 time_func_() + |
| 1788 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); | 1816 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 break; | 1850 break; |
| 1823 } | 1851 } |
| 1824 } | 1852 } |
| 1825 | 1853 |
| 1826 CHECK(in_io_loop_); | 1854 CHECK(in_io_loop_); |
| 1827 in_io_loop_ = false; | 1855 in_io_loop_ = false; |
| 1828 | 1856 |
| 1829 return result; | 1857 return result; |
| 1830 } | 1858 } |
| 1831 | 1859 |
| 1832 int SpdySession::DoRead() { | |
| 1833 CHECK(in_io_loop_); | |
| 1834 | |
| 1835 CHECK(connection_); | |
| 1836 CHECK(connection_->socket()); | |
| 1837 read_state_ = READ_STATE_DO_READ_COMPLETE; | |
| 1838 return connection_->socket()->Read( | |
| 1839 read_buffer_.get(), kReadBufferSize, | |
| 1840 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
| 1841 READ_STATE_DO_READ_COMPLETE)); | |
| 1842 } | |
| 1843 | |
| 1844 int SpdySession::DoReadComplete(int result) { | 1860 int SpdySession::DoReadComplete(int result) { |
| 1845 CHECK(in_io_loop_); | 1861 CHECK(in_io_loop_); |
| 1846 | 1862 |
| 1847 // Parse a frame. For now this code requires that the frame fit into our | 1863 // Parse a frame. For now this code requires that the frame fit into our |
| 1848 // buffer (kReadBufferSize). | 1864 // buffer (kReadBufferSize). |
| 1849 // TODO(mbelshe): support arbitrarily large frames! | 1865 // TODO(mbelshe): support arbitrarily large frames! |
| 1850 | 1866 |
| 1851 if (result == 0) { | 1867 if (result == 0) { |
| 1852 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); | 1868 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); |
| 1853 return ERR_CONNECTION_CLOSED; | 1869 return ERR_CONNECTION_CLOSED; |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3130 if (!queue->empty()) { | 3146 if (!queue->empty()) { |
| 3131 SpdyStreamId stream_id = queue->front(); | 3147 SpdyStreamId stream_id = queue->front(); |
| 3132 queue->pop_front(); | 3148 queue->pop_front(); |
| 3133 return stream_id; | 3149 return stream_id; |
| 3134 } | 3150 } |
| 3135 } | 3151 } |
| 3136 return 0; | 3152 return 0; |
| 3137 } | 3153 } |
| 3138 | 3154 |
| 3139 } // namespace net | 3155 } // namespace net |
| OLD | NEW |