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> |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 const SettingsMap& initial_settings, | 733 const SettingsMap& initial_settings, |
734 TimeFunc time_func, | 734 TimeFunc time_func, |
735 ServerPushDelegate* push_delegate, | 735 ServerPushDelegate* push_delegate, |
736 ProxyDelegate* proxy_delegate, | 736 ProxyDelegate* proxy_delegate, |
737 NetLog* net_log) | 737 NetLog* net_log) |
738 : in_io_loop_(false), | 738 : in_io_loop_(false), |
739 spdy_session_key_(spdy_session_key), | 739 spdy_session_key_(spdy_session_key), |
740 pool_(NULL), | 740 pool_(NULL), |
741 http_server_properties_(http_server_properties), | 741 http_server_properties_(http_server_properties), |
742 transport_security_state_(transport_security_state), | 742 transport_security_state_(transport_security_state), |
743 read_buffer_(new IOBuffer(kReadBufferSize)), | |
744 stream_hi_water_mark_(kFirstStreamId), | 743 stream_hi_water_mark_(kFirstStreamId), |
745 last_accepted_push_stream_id_(0), | 744 last_accepted_push_stream_id_(0), |
746 unclaimed_pushed_streams_(this), | 745 unclaimed_pushed_streams_(this), |
747 push_delegate_(push_delegate), | 746 push_delegate_(push_delegate), |
748 num_pushed_streams_(0u), | 747 num_pushed_streams_(0u), |
749 num_active_pushed_streams_(0u), | 748 num_active_pushed_streams_(0u), |
750 bytes_pushed_count_(0u), | 749 bytes_pushed_count_(0u), |
751 bytes_pushed_and_unclaimed_count_(0u), | 750 bytes_pushed_and_unclaimed_count_(0u), |
752 in_flight_write_frame_type_(DATA), | 751 in_flight_write_frame_type_(DATA), |
753 in_flight_write_frame_size_(0), | 752 in_flight_write_frame_size_(0), |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 } | 1370 } |
1372 | 1371 |
1373 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, | 1372 size_t SpdySession::DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, |
1374 bool* is_session_active) const { | 1373 bool* is_session_active) const { |
1375 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is | 1374 // TODO(xunjieli): Include |pending_create_stream_queues_| when WeakPtr is |
1376 // supported in memory_usage_estimator.h. | 1375 // supported in memory_usage_estimator.h. |
1377 *is_session_active = is_active(); | 1376 *is_session_active = is_active(); |
1378 connection_->DumpMemoryStats(stats); | 1377 connection_->DumpMemoryStats(stats); |
1379 | 1378 |
1380 // |connection_| is estimated in stats->total_size. |read_buffer_| is | 1379 // |connection_| is estimated in stats->total_size. |read_buffer_| is |
1381 // estimated in kReadBufferSize. TODO(xunjieli): Make them use EMU(). | 1380 // estimated in |read_buffer_size|. TODO(xunjieli): Make them use EMU(). |
1382 return stats->total_size + kReadBufferSize + | 1381 size_t read_buffer_size = read_buffer_ ? kReadBufferSize : 0; |
| 1382 return stats->total_size + read_buffer_size + |
1383 SpdyEstimateMemoryUsage(spdy_session_key_) + | 1383 SpdyEstimateMemoryUsage(spdy_session_key_) + |
1384 SpdyEstimateMemoryUsage(pooled_aliases_) + | 1384 SpdyEstimateMemoryUsage(pooled_aliases_) + |
1385 SpdyEstimateMemoryUsage(active_streams_) + | 1385 SpdyEstimateMemoryUsage(active_streams_) + |
1386 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) + | 1386 SpdyEstimateMemoryUsage(unclaimed_pushed_streams_) + |
1387 SpdyEstimateMemoryUsage(created_streams_) + | 1387 SpdyEstimateMemoryUsage(created_streams_) + |
1388 SpdyEstimateMemoryUsage(write_queue_) + | 1388 SpdyEstimateMemoryUsage(write_queue_) + |
1389 SpdyEstimateMemoryUsage(in_flight_write_) + | 1389 SpdyEstimateMemoryUsage(in_flight_write_) + |
1390 SpdyEstimateMemoryUsage(buffered_spdy_framer_) + | 1390 SpdyEstimateMemoryUsage(buffered_spdy_framer_) + |
1391 SpdyEstimateMemoryUsage(initial_settings_) + | 1391 SpdyEstimateMemoryUsage(initial_settings_) + |
1392 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) + | 1392 SpdyEstimateMemoryUsage(stream_send_unstall_queue_) + |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 } | 1862 } |
1863 } | 1863 } |
1864 | 1864 |
1865 CHECK(in_io_loop_); | 1865 CHECK(in_io_loop_); |
1866 in_io_loop_ = false; | 1866 in_io_loop_ = false; |
1867 | 1867 |
1868 return result; | 1868 return result; |
1869 } | 1869 } |
1870 | 1870 |
1871 int SpdySession::DoRead() { | 1871 int SpdySession::DoRead() { |
| 1872 DCHECK(!read_buffer_); |
1872 CHECK(in_io_loop_); | 1873 CHECK(in_io_loop_); |
1873 | 1874 |
1874 CHECK(connection_); | 1875 CHECK(connection_); |
1875 CHECK(connection_->socket()); | 1876 CHECK(connection_->socket()); |
1876 read_state_ = READ_STATE_DO_READ_COMPLETE; | 1877 read_state_ = READ_STATE_DO_READ_COMPLETE; |
1877 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; | 1878 int rv = ERR_READ_IF_READY_NOT_IMPLEMENTED; |
| 1879 read_buffer_ = new IOBuffer(kReadBufferSize); |
1878 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { | 1880 if (base::FeatureList::IsEnabled(Socket::kReadIfReadyExperiment)) { |
1879 rv = connection_->socket()->ReadIfReady( | 1881 rv = connection_->socket()->ReadIfReady( |
1880 read_buffer_.get(), kReadBufferSize, | 1882 read_buffer_.get(), kReadBufferSize, |
1881 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | 1883 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), |
1882 READ_STATE_DO_READ)); | 1884 READ_STATE_DO_READ)); |
1883 // TODO(xunjieli): Follow-up CL to release |read_buffer_|. | 1885 if (rv == ERR_IO_PENDING) { |
1884 // https://crbug.com/690915. | 1886 read_buffer_ = nullptr; |
| 1887 read_state_ = READ_STATE_DO_READ; |
| 1888 return rv; |
| 1889 } |
1885 } | 1890 } |
1886 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { | 1891 if (rv == ERR_READ_IF_READY_NOT_IMPLEMENTED) { |
1887 // Fallback to regular Read(). | 1892 // Fallback to regular Read(). |
1888 return connection_->socket()->Read( | 1893 return connection_->socket()->Read( |
1889 read_buffer_.get(), kReadBufferSize, | 1894 read_buffer_.get(), kReadBufferSize, |
1890 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), | 1895 base::Bind(&SpdySession::PumpReadLoop, weak_factory_.GetWeakPtr(), |
1891 READ_STATE_DO_READ_COMPLETE)); | 1896 READ_STATE_DO_READ_COMPLETE)); |
1892 } | 1897 } |
1893 if (rv == ERR_IO_PENDING) | |
1894 read_state_ = READ_STATE_DO_READ; | |
1895 return rv; | 1898 return rv; |
1896 } | 1899 } |
1897 | 1900 |
1898 int SpdySession::DoReadComplete(int result) { | 1901 int SpdySession::DoReadComplete(int result) { |
| 1902 DCHECK(read_buffer_); |
1899 CHECK(in_io_loop_); | 1903 CHECK(in_io_loop_); |
1900 | 1904 |
1901 // Parse a frame. For now this code requires that the frame fit into our | 1905 // Parse a frame. For now this code requires that the frame fit into our |
1902 // buffer (kReadBufferSize). | 1906 // buffer (kReadBufferSize). |
1903 // TODO(mbelshe): support arbitrarily large frames! | 1907 // TODO(mbelshe): support arbitrarily large frames! |
1904 | 1908 |
1905 if (result == 0) { | 1909 if (result == 0) { |
1906 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); | 1910 DoDrainSession(ERR_CONNECTION_CLOSED, "Connection closed"); |
1907 return ERR_CONNECTION_CLOSED; | 1911 return ERR_CONNECTION_CLOSED; |
1908 } | 1912 } |
(...skipping 17 matching lines...) Expand all Loading... |
1926 data += bytes_processed; | 1930 data += bytes_processed; |
1927 | 1931 |
1928 if (availability_state_ == STATE_DRAINING) { | 1932 if (availability_state_ == STATE_DRAINING) { |
1929 return ERR_CONNECTION_CLOSED; | 1933 return ERR_CONNECTION_CLOSED; |
1930 } | 1934 } |
1931 | 1935 |
1932 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(), | 1936 DCHECK_EQ(buffered_spdy_framer_->spdy_framer_error(), |
1933 SpdyFramer::SPDY_NO_ERROR); | 1937 SpdyFramer::SPDY_NO_ERROR); |
1934 } | 1938 } |
1935 | 1939 |
| 1940 read_buffer_ = nullptr; |
1936 read_state_ = READ_STATE_DO_READ; | 1941 read_state_ = READ_STATE_DO_READ; |
1937 return OK; | 1942 return OK; |
1938 } | 1943 } |
1939 | 1944 |
1940 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) { | 1945 void SpdySession::PumpWriteLoop(WriteState expected_write_state, int result) { |
1941 CHECK(!in_io_loop_); | 1946 CHECK(!in_io_loop_); |
1942 DCHECK_EQ(write_state_, expected_write_state); | 1947 DCHECK_EQ(write_state_, expected_write_state); |
1943 | 1948 |
1944 DoWriteLoop(expected_write_state, result); | 1949 DoWriteLoop(expected_write_state, result); |
1945 | 1950 |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3184 if (!queue->empty()) { | 3189 if (!queue->empty()) { |
3185 SpdyStreamId stream_id = queue->front(); | 3190 SpdyStreamId stream_id = queue->front(); |
3186 queue->pop_front(); | 3191 queue->pop_front(); |
3187 return stream_id; | 3192 return stream_id; |
3188 } | 3193 } |
3189 } | 3194 } |
3190 return 0; | 3195 return 0; |
3191 } | 3196 } |
3192 | 3197 |
3193 } // namespace net | 3198 } // namespace net |
OLD | NEW |