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 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 } | 1799 } |
1798 | 1800 |
1799 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { | 1801 void SpdySession::PumpReadLoop(ReadState expected_read_state, int result) { |
1800 CHECK(!in_io_loop_); | 1802 CHECK(!in_io_loop_); |
1801 if (availability_state_ == STATE_DRAINING) { | 1803 if (availability_state_ == STATE_DRAINING) { |
1802 return; | 1804 return; |
1803 } | 1805 } |
1804 ignore_result(DoReadLoop(expected_read_state, result)); | 1806 ignore_result(DoReadLoop(expected_read_state, result)); |
1805 } | 1807 } |
1806 | 1808 |
1809 int SpdySession::DoRead() { | |
Bence
2017/03/03 16:33:41
Oh no, I just reordered methods in https://crrev.c
xunjieli
2017/03/03 19:41:06
Done.
| |
1810 CHECK(in_io_loop_); | |
1811 | |
1812 CHECK(connection_); | |
1813 CHECK(connection_->socket()); | |
Bence
2017/03/03 16:33:42
Do you think this would flow more naturally?
if (
xunjieli
2017/03/03 19:41:06
I may be biased, but I like my verson better. Fewe
Bence
2017/03/06 23:43:14
It's okay to be biased, you are the author. :)
| |
1814 read_state_ = READ_STATE_DO_READ_COMPLETE; | |
1815 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; | |
1816 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { | |
1817 rv = connection_->socket()->ReadIfReady( | |
1818 read_buffer_.get(), kReadBufferSize, | |
1819 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
1820 READ_STATE_DO_READ)); | |
1821 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. crbug.com/524258. | |
Bence
2017/03/03 16:33:42
Optional: use https:// prefix for crbug, because s
xunjieli
2017/03/03 19:41:06
Done. I personally avoid the https:// prefix becau
Bence
2017/03/06 23:43:14
I guess then you are not using vim in gnome-termin
| |
1822 } | |
1823 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { | |
1824 // Fallback to regular Read(). | |
1825 return connection_->socket()->Read( | |
1826 read_buffer_.get(), kReadBufferSize, | |
1827 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
1828 READ_STATE_DO_READ_COMPLETE)); | |
1829 } | |
1830 if (rv == ERR_IO_PENDING) | |
1831 read_state_ = READ_STATE_DO_READ; | |
1832 return rv; | |
1833 } | |
1834 | |
1807 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { | 1835 int SpdySession::DoReadLoop(ReadState expected_read_state, int result) { |
1808 CHECK(!in_io_loop_); | 1836 CHECK(!in_io_loop_); |
1809 CHECK_EQ(read_state_, expected_read_state); | 1837 CHECK_EQ(read_state_, expected_read_state); |
1810 | 1838 |
1811 in_io_loop_ = true; | 1839 in_io_loop_ = true; |
1812 | 1840 |
1813 int bytes_read_without_yielding = 0; | 1841 int bytes_read_without_yielding = 0; |
1814 const base::TimeTicks yield_after_time = | 1842 const base::TimeTicks yield_after_time = |
1815 time_func_() + | 1843 time_func_() + |
1816 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); | 1844 base::TimeDelta::FromMilliseconds(kYieldAfterDurationMilliseconds); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1850 break; | 1878 break; |
1851 } | 1879 } |
1852 } | 1880 } |
1853 | 1881 |
1854 CHECK(in_io_loop_); | 1882 CHECK(in_io_loop_); |
1855 in_io_loop_ = false; | 1883 in_io_loop_ = false; |
1856 | 1884 |
1857 return result; | 1885 return result; |
1858 } | 1886 } |
1859 | 1887 |
1860 int SpdySession::DoRead() { | |
1861 CHECK(in_io_loop_); | |
1862 | |
1863 CHECK(connection_); | |
1864 CHECK(connection_->socket()); | |
1865 read_state_ = READ_STATE_DO_READ_COMPLETE; | |
1866 return connection_->socket()->Read( | |
1867 read_buffer_.get(), kReadBufferSize, | |
1868 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | |
1869 READ_STATE_DO_READ_COMPLETE)); | |
1870 } | |
1871 | |
1872 int SpdySession::DoReadComplete(int result) { | 1888 int SpdySession::DoReadComplete(int result) { |
1873 CHECK(in_io_loop_); | 1889 CHECK(in_io_loop_); |
1874 | 1890 |
1875 // Parse a frame. For now this code requires that the frame fit into our | 1891 // Parse a frame. For now this code requires that the frame fit into our |
1876 // buffer (kReadBufferSize). | 1892 // buffer (kReadBufferSize). |
1877 // TODO(mbelshe): support arbitrarily large frames! | 1893 // TODO(mbelshe): support arbitrarily large frames! |
1878 | 1894 |
1879 if (result == 0) { | 1895 if (result == 0) { |
1880 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); | 1896 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); |
1881 return ERR_CONNECTION_CLOSED; | 1897 return ERR_CONNECTION_CLOSED; |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3158 if (!queue->empty()) { | 3174 if (!queue->empty()) { |
3159 SpdyStreamId stream_id = queue->front(); | 3175 SpdyStreamId stream_id = queue->front(); |
3160 queue->pop_front(); | 3176 queue->pop_front(); |
3161 return stream_id; | 3177 return stream_id; |
3162 } | 3178 } |
3163 } | 3179 } |
3164 return 0; | 3180 return 0; |
3165 } | 3181 } |
3166 | 3182 |
3167 } // namespace net | 3183 } // namespace net |
OLD | NEW |