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/feature_list.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
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" |
(...skipping 14 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/platform/api/spdy_estimate_memory_usage.h" | 51 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
50 #include "net/spdy/spdy_buffer_producer.h" | 52 #include "net/spdy/spdy_buffer_producer.h" |
51 #include "net/spdy/spdy_frame_builder.h" | 53 #include "net/spdy/spdy_frame_builder.h" |
52 #include "net/spdy/spdy_http_utils.h" | 54 #include "net/spdy/spdy_http_utils.h" |
53 #include "net/spdy/spdy_protocol.h" | 55 #include "net/spdy/spdy_protocol.h" |
54 #include "net/spdy/spdy_session_pool.h" | 56 #include "net/spdy/spdy_session_pool.h" |
55 #include "net/spdy/spdy_stream.h" | 57 #include "net/spdy/spdy_stream.h" |
56 #include "net/ssl/channel_id_service.h" | 58 #include "net/ssl/channel_id_service.h" |
57 #include "net/ssl/ssl_cipher_suite_names.h" | 59 #include "net/ssl/ssl_cipher_suite_names.h" |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 } | 1798 } |
1797 | 1799 |
1798 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { | 1800 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { |
1799 CHECK(!in_io_loop_); | 1801 CHECK(!in_io_loop_); |
1800 if (availability_state_ == STATE_DRAINING) { | 1802 if (availability_state_ == STATE_DRAINING) { |
1801 return; | 1803 return; |
1802 } | 1804 } |
1803 ignore_result(DoReadLoop(expected_read_state, result)); | 1805 ignore_result(DoReadLoop(expected_read_state, result)); |
1804 } | 1806 } |
1805 | 1807 |
| 1808 int SpdySession::DoRead() { |
| 1809 CHECK(in_io_loop_); |
| 1810 |
| 1811 CHECK(connection_); |
| 1812 CHECK(connection_->socket()); |
| 1813 read_state_ = READ_STATE_DO_READ_COMPLETE; |
| 1814 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; |
| 1815 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { |
| 1816 rv = connection_->socket()->ReadIfReady( |
| 1817 read_buffer_.get(), kReadBufferSize, |
| 1818 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), |
| 1819 READ_STATE_DO_READ)); |
| 1820 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. crbug.com/524258. |
| 1821 } |
| 1822 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { |
| 1823 // Fallback to regular Read(). |
| 1824 return connection_->socket()->Read( |
| 1825 read_buffer_.get(), kReadBufferSize, |
| 1826 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), |
| 1827 READ_STATE_DO_READ_COMPLETE)); |
| 1828 } |
| 1829 if (rv == ERR_IO_PENDING) |
| 1830 read_state_ = READ_STATE_DO_READ; |
| 1831 return rv; |
| 1832 } |
| 1833 |
1806 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { | 1834 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { |
1807 CHECK(!in_io_loop_); | 1835 CHECK(!in_io_loop_); |
1808 CHECK_EQ(read_state_, expected_read_state); | 1836 CHECK_EQ(read_state_, expected_read_state); |
1809 | 1837 |
1810 in_io_loop_ = true; | 1838 in_io_loop_ = true; |
1811 | 1839 |
1812 int bytes_read_without_yielding = 0; | 1840 int bytes_read_without_yielding = 0; |
1813 const base::TimeTicks yield_after_time = | 1841 const base::TimeTicks yield_after_time = |
1814 time_func_() + | 1842 time_func_() + |
1815 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); | 1843 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 break; | 1877 break; |
1850 } | 1878 } |
1851 } | 1879 } |
1852 | 1880 |
1853 CHECK(in_io_loop_); | 1881 CHECK(in_io_loop_); |
1854 in_io_loop_ = false; | 1882 in_io_loop_ = false; |
1855 | 1883 |
1856 return result; | 1884 return result; |
1857 } | 1885 } |
1858 | 1886 |
1859 int SpdySession::DoRead() { | |
1860 CHECK(in_io_loop_); | |
1861 | |
1862 CHECK(connection_); | |
1863 CHECK(connection_->socket()); | |
1864 read_state_ = READ_STATE_DO_READ_COMPLETE; | |
1865 return connection_->socket()->Read( | |
1866 read_buffer_.get(), kReadBufferSize, | |
1867 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
1868 READ_STATE_DO_READ_COMPLETE)); | |
1869 } | |
1870 | |
1871 int SpdySession::DoReadComplete(int result) { | 1887 int SpdySession::DoReadComplete(int result) { |
1872 CHECK(in_io_loop_); | 1888 CHECK(in_io_loop_); |
1873 | 1889 |
1874 // Parse a frame. For now this code requires that the frame fit into our | 1890 // Parse a frame. For now this code requires that the frame fit into our |
1875 // buffer (kReadBufferSize). | 1891 // buffer (kReadBufferSize). |
1876 // TODO(mbelshe): support arbitrarily large frames! | 1892 // TODO(mbelshe): support arbitrarily large frames! |
1877 | 1893 |
1878 if (result == 0) { | 1894 if (result == 0) { |
1879 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); | 1895 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); |
1880 return ERR_CONNECTION_CLOSED; | 1896 return ERR_CONNECTION_CLOSED; |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3157 if (!queue->empty()) { | 3173 if (!queue->empty()) { |
3158 SpdyStreamId stream_id = queue->front(); | 3174 SpdyStreamId stream_id = queue->front(); |
3159 queue->pop_front(); | 3175 queue->pop_front(); |
3160 return stream_id; | 3176 return stream_id; |
3161 } | 3177 } |
3162 } | 3178 } |
3163 return 0; | 3179 return 0; |
3164 } | 3180 } |
3165 | 3181 |
3166 } // namespace net | 3182 } // namespace net |
OLD | NEW |