| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 DictionaryValue* dict = new DictionaryValue(); | 116 DictionaryValue* dict = new DictionaryValue(); |
| 117 dict->Set("host", new StringValue(host_pair_.first.ToString())); | 117 dict->Set("host", new StringValue(host_pair_.first.ToString())); |
| 118 dict->Set("proxy", new StringValue(host_pair_.second.ToPacString())); | 118 dict->Set("proxy", new StringValue(host_pair_.second.ToPacString())); |
| 119 return dict; | 119 return dict; |
| 120 } | 120 } |
| 121 private: | 121 private: |
| 122 const HostPortProxyPair host_pair_; | 122 const HostPortProxyPair host_pair_; |
| 123 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionParameter); | 123 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySessionParameter); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 class NetLogSpdySettingParameter : public NetLog::EventParameters { |
| 127 public: |
| 128 explicit NetLogSpdySettingParameter(SpdySettingsIds id, |
| 129 SpdySettingsFlags flags, |
| 130 uint32 value) |
| 131 : id_(id), |
| 132 flags_(flags), |
| 133 value_(value) { |
| 134 } |
| 135 |
| 136 virtual Value* ToValue() const { |
| 137 DictionaryValue* dict = new DictionaryValue(); |
| 138 dict->SetInteger("id", id_); |
| 139 dict->SetInteger("flags", flags_); |
| 140 dict->SetInteger("value", value_); |
| 141 return dict; |
| 142 } |
| 143 |
| 144 private: |
| 145 ~NetLogSpdySettingParameter() {} |
| 146 const SpdySettingsIds id_; |
| 147 const SpdySettingsFlags flags_; |
| 148 const uint32 value_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(NetLogSpdySettingParameter); |
| 151 }; |
| 152 |
| 126 class NetLogSpdySettingsParameter : public NetLog::EventParameters { | 153 class NetLogSpdySettingsParameter : public NetLog::EventParameters { |
| 127 public: | 154 public: |
| 128 explicit NetLogSpdySettingsParameter(const SpdySettings& settings) | 155 explicit NetLogSpdySettingsParameter(const SpdySettings& settings) |
| 129 : settings_(settings) {} | 156 : settings_(settings) {} |
| 130 | 157 |
| 131 virtual Value* ToValue() const { | 158 virtual Value* ToValue() const { |
| 132 DictionaryValue* dict = new DictionaryValue(); | 159 DictionaryValue* dict = new DictionaryValue(); |
| 133 ListValue* settings = new ListValue(); | 160 ListValue* settings = new ListValue(); |
| 134 for (SpdySettings::const_iterator it = settings_.begin(); | 161 for (SpdySettings::const_iterator it = settings_.begin(); |
| 135 it != settings_.end(); ++it) { | 162 it != settings_.end(); ++it) { |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 } | 1352 } |
| 1326 | 1353 |
| 1327 scoped_refptr<SpdyStream> stream = active_streams_[stream_id]; | 1354 scoped_refptr<SpdyStream> stream = active_streams_[stream_id]; |
| 1328 stream->OnDataReceived(data, len); | 1355 stream->OnDataReceived(data, len); |
| 1329 } | 1356 } |
| 1330 | 1357 |
| 1331 void SpdySession::OnSetting(SpdySettingsIds id, | 1358 void SpdySession::OnSetting(SpdySettingsIds id, |
| 1332 uint8 flags, | 1359 uint8 flags, |
| 1333 uint32 value) { | 1360 uint32 value) { |
| 1334 HandleSetting(id, value); | 1361 HandleSetting(id, value); |
| 1335 SettingsFlagsAndId flags_and_id(flags, id); | 1362 http_server_properties_->SetSpdySetting( |
| 1336 // TODO(rtenneti): persist SpdySetting. | 1363 host_port_pair(), |
| 1337 // http_server_properties_->SetSpdySetting( | 1364 id, |
| 1338 // host_port_pair(), std::make_pair(flags_and_id, value)); | 1365 static_cast<SpdySettingsFlags>(flags), |
| 1339 | 1366 value); |
| 1340 received_settings_ = true; | 1367 received_settings_ = true; |
| 1341 | 1368 |
| 1342 // Log the settings. | 1369 // Log the setting. |
| 1343 SpdySettings settings; | |
| 1344 settings.insert(settings.end(), std::make_pair(flags_and_id, value)); | |
| 1345 net_log_.AddEvent( | 1370 net_log_.AddEvent( |
| 1346 NetLog::TYPE_SPDY_SESSION_RECV_SETTINGS, | 1371 NetLog::TYPE_SPDY_SESSION_RECV_SETTING, |
| 1347 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1372 make_scoped_refptr(new NetLogSpdySettingParameter( |
| 1373 id, static_cast<SpdySettingsFlags>(flags), value))); |
| 1348 } | 1374 } |
| 1349 | 1375 |
| 1350 bool SpdySession::Respond(const SpdyHeaderBlock& headers, | 1376 bool SpdySession::Respond(const SpdyHeaderBlock& headers, |
| 1351 const scoped_refptr<SpdyStream> stream) { | 1377 const scoped_refptr<SpdyStream> stream) { |
| 1352 int rv = OK; | 1378 int rv = OK; |
| 1353 rv = stream->OnResponseReceived(headers); | 1379 rv = stream->OnResponseReceived(headers); |
| 1354 if (rv < 0) { | 1380 if (rv < 0) { |
| 1355 DCHECK_NE(rv, ERR_IO_PENDING); | 1381 DCHECK_NE(rv, ERR_IO_PENDING); |
| 1356 const SpdyStreamId stream_id = stream->stream_id(); | 1382 const SpdyStreamId stream_id = stream->stream_id(); |
| 1357 DeleteStream(stream_id, rv); | 1383 DeleteStream(stream_id, rv); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 return std::max(cwnd, 16); | 1697 return std::max(cwnd, 16); |
| 1672 else if (trial->group_name() == "cwndMin10") | 1698 else if (trial->group_name() == "cwndMin10") |
| 1673 return std::max(cwnd, 10); | 1699 return std::max(cwnd, 10); |
| 1674 else if (trial->group_name() == "cwndDynamic") | 1700 else if (trial->group_name() == "cwndDynamic") |
| 1675 return cwnd; | 1701 return cwnd; |
| 1676 NOTREACHED(); | 1702 NOTREACHED(); |
| 1677 return cwnd; | 1703 return cwnd; |
| 1678 } | 1704 } |
| 1679 | 1705 |
| 1680 void SpdySession::SendSettings() { | 1706 void SpdySession::SendSettings() { |
| 1681 // Note: we're copying the settings here, so that we can potentially modify | 1707 const SettingsMap& settings_map = |
| 1682 // the settings for the field trial. When removing the field trial, make | |
| 1683 // this a reference to the const SpdySettings again. | |
| 1684 SpdySettings settings = | |
| 1685 http_server_properties_->GetSpdySettings(host_port_pair()); | 1708 http_server_properties_->GetSpdySettings(host_port_pair()); |
| 1686 if (settings.empty()) | 1709 if (settings_map.empty()) |
| 1687 return; | 1710 return; |
| 1688 | 1711 |
| 1689 typedef std::map<uint32, SpdySetting> SpdySettingsMap; | |
| 1690 SpdySettingsMap unique_settings; | |
| 1691 | |
| 1692 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. | 1712 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. |
| 1693 for (SpdySettings::iterator i = settings.begin(), | 1713 const SpdySettingsIds id = SETTINGS_CURRENT_CWND; |
| 1694 end = settings.end(); i != end; ++i) { | 1714 SettingsMap::const_iterator it = settings_map.find(id); |
| 1695 const uint32 id = i->first.id(); | 1715 uint32 value = 0; |
| 1696 const uint32 val = i->second; | 1716 if (it != settings_map.end()) |
| 1697 switch (id) { | 1717 value = it->second.second; |
| 1698 case SETTINGS_CURRENT_CWND: | 1718 uint32 cwnd = ApplyCwndFieldTrialPolicy(value); |
| 1699 uint32 cwnd = 0; | 1719 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", cwnd, 1, 200, 100); |
| 1700 cwnd = ApplyCwndFieldTrialPolicy(val); | 1720 if (cwnd != value) { |
| 1701 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", | 1721 http_server_properties_->SetSpdySetting( |
| 1702 cwnd, | 1722 host_port_pair(), id, SETTINGS_FLAG_PLEASE_PERSIST, cwnd); |
| 1703 1, 200, 100); | |
| 1704 if (cwnd != val) { | |
| 1705 SettingsFlagsAndId new_id(SETTINGS_FLAG_PLEASE_PERSIST, | |
| 1706 id); | |
| 1707 i->second = cwnd; | |
| 1708 i->first = new_id; | |
| 1709 SpdySetting setting(new_id, val); | |
| 1710 // TODO(rtenneti): Persist SpdySetting. | |
| 1711 // http_server_properties_->SetSpdySetting(host_port_pair(), setting); | |
| 1712 unique_settings[id] = setting; | |
| 1713 continue; | |
| 1714 } | |
| 1715 } | |
| 1716 unique_settings[id] = *i; | |
| 1717 } | 1723 } |
| 1718 | 1724 |
| 1719 HandleSettings(settings); | 1725 const SettingsMap& settings_map_new = |
| 1726 http_server_properties_->GetSpdySettings(host_port_pair()); |
| 1727 |
| 1728 SpdySettings settings; |
| 1729 for (SettingsMap::const_iterator i = settings_map_new.begin(), |
| 1730 end = settings_map_new.end(); i != end; ++i) { |
| 1731 const SpdySettingsIds new_id = i->first; |
| 1732 const SpdySettingsFlags new_flags = i->second.first; |
| 1733 const uint32 new_val = i->second.second; |
| 1734 HandleSetting(new_id, new_val); |
| 1735 SettingsFlagsAndId flags_and_id(new_flags, new_id); |
| 1736 settings.push_back(SpdySetting(flags_and_id, new_val)); |
| 1737 } |
| 1720 | 1738 |
| 1721 net_log_.AddEvent( | 1739 net_log_.AddEvent( |
| 1722 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | 1740 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, |
| 1723 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1741 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); |
| 1724 | 1742 |
| 1725 SpdySettings sorted_settings; | |
| 1726 for (SpdySettingsMap::iterator it = unique_settings.begin(); | |
| 1727 unique_settings.end() != it; | |
| 1728 ++it) { | |
| 1729 sorted_settings.push_back(it->second); | |
| 1730 } | |
| 1731 | |
| 1732 // Create the SETTINGS frame and send it. | 1743 // Create the SETTINGS frame and send it. |
| 1733 DCHECK(buffered_spdy_framer_.get()); | 1744 DCHECK(buffered_spdy_framer_.get()); |
| 1734 scoped_ptr<SpdySettingsControlFrame> settings_frame( | 1745 scoped_ptr<SpdySettingsControlFrame> settings_frame( |
| 1735 buffered_spdy_framer_->CreateSettings(sorted_settings)); | 1746 buffered_spdy_framer_->CreateSettings(settings)); |
| 1736 sent_settings_ = true; | 1747 sent_settings_ = true; |
| 1737 QueueFrame(settings_frame.get(), 0, NULL); | 1748 QueueFrame(settings_frame.get(), 0, NULL); |
| 1738 } | 1749 } |
| 1739 | 1750 |
| 1740 void SpdySession::HandleSettings(const SpdySettings& settings) { | |
| 1741 for (SpdySettings::const_iterator i = settings.begin(), | |
| 1742 end = settings.end(); i != end; ++i) { | |
| 1743 HandleSetting(i->first.id(), i->second); | |
| 1744 } | |
| 1745 } | |
| 1746 | |
| 1747 void SpdySession::HandleSetting(uint32 id, uint32 value) { | 1751 void SpdySession::HandleSetting(uint32 id, uint32 value) { |
| 1748 switch (id) { | 1752 switch (id) { |
| 1749 case SETTINGS_MAX_CONCURRENT_STREAMS: | 1753 case SETTINGS_MAX_CONCURRENT_STREAMS: |
| 1750 max_concurrent_streams_ = std::min(static_cast<size_t>(value), | 1754 max_concurrent_streams_ = std::min(static_cast<size_t>(value), |
| 1751 g_max_concurrent_stream_limit); | 1755 g_max_concurrent_stream_limit); |
| 1752 ProcessPendingCreateStreams(); | 1756 ProcessPendingCreateStreams(); |
| 1753 break; | 1757 break; |
| 1754 case SETTINGS_INITIAL_WINDOW_SIZE: | 1758 case SETTINGS_INITIAL_WINDOW_SIZE: |
| 1755 // INITIAL_WINDOW_SIZE updates initial_send_window_size_ only. | 1759 // INITIAL_WINDOW_SIZE updates initial_send_window_size_ only. |
| 1756 // TODO(rtenneti): discuss with the server team about | 1760 // TODO(rtenneti): discuss with the server team about |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", | 1894 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", |
| 1891 received_settings_ ? 1 : 0, 2); | 1895 received_settings_ ? 1 : 0, 2); |
| 1892 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", | 1896 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", |
| 1893 stalled_streams_, | 1897 stalled_streams_, |
| 1894 0, 300, 50); | 1898 0, 300, 50); |
| 1895 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", | 1899 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", |
| 1896 stalled_streams_ > 0 ? 1 : 0, 2); | 1900 stalled_streams_ > 0 ? 1 : 0, 2); |
| 1897 | 1901 |
| 1898 if (received_settings_) { | 1902 if (received_settings_) { |
| 1899 // Enumerate the saved settings, and set histograms for it. | 1903 // Enumerate the saved settings, and set histograms for it. |
| 1900 const SpdySettings& settings = | 1904 const SettingsMap& settings_map = |
| 1901 http_server_properties_->GetSpdySettings(host_port_pair()); | 1905 http_server_properties_->GetSpdySettings(host_port_pair()); |
| 1902 | 1906 |
| 1903 SpdySettings::const_iterator it; | 1907 SettingsMap::const_iterator it; |
| 1904 for (it = settings.begin(); it != settings.end(); ++it) { | 1908 for (it = settings_map.begin(); it != settings_map.end(); ++it) { |
| 1905 const SpdySetting setting = *it; | 1909 const SpdySettingsIds id = it->first; |
| 1906 switch (setting.first.id()) { | 1910 const uint32 val = it->second.second; |
| 1911 switch (id) { |
| 1907 case SETTINGS_CURRENT_CWND: | 1912 case SETTINGS_CURRENT_CWND: |
| 1908 // Record several different histograms to see if cwnd converges | 1913 // Record several different histograms to see if cwnd converges |
| 1909 // for larger volumes of data being sent. | 1914 // for larger volumes of data being sent. |
| 1910 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", | 1915 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", |
| 1911 setting.second, | 1916 val, 1, 200, 100); |
| 1912 1, 200, 100); | |
| 1913 if (bytes_received_ > 10 * 1024) { | 1917 if (bytes_received_ > 10 * 1024) { |
| 1914 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd10K", | 1918 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd10K", |
| 1915 setting.second, | 1919 val, 1, 200, 100); |
| 1916 1, 200, 100); | |
| 1917 if (bytes_received_ > 25 * 1024) { | 1920 if (bytes_received_ > 25 * 1024) { |
| 1918 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd25K", | 1921 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd25K", |
| 1919 setting.second, | 1922 val, 1, 200, 100); |
| 1920 1, 200, 100); | |
| 1921 if (bytes_received_ > 50 * 1024) { | 1923 if (bytes_received_ > 50 * 1024) { |
| 1922 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd50K", | 1924 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd50K", |
| 1923 setting.second, | 1925 val, 1, 200, 100); |
| 1924 1, 200, 100); | |
| 1925 if (bytes_received_ > 100 * 1024) { | 1926 if (bytes_received_ > 100 * 1024) { |
| 1926 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd100K", | 1927 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd100K", |
| 1927 setting.second, | 1928 val, 1, 200, 100); |
| 1928 1, 200, 100); | |
| 1929 } | 1929 } |
| 1930 } | 1930 } |
| 1931 } | 1931 } |
| 1932 } | 1932 } |
| 1933 break; | 1933 break; |
| 1934 case SETTINGS_ROUND_TRIP_TIME: | 1934 case SETTINGS_ROUND_TRIP_TIME: |
| 1935 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRTT", | 1935 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRTT", |
| 1936 setting.second, | 1936 val, 1, 1200, 100); |
| 1937 1, 1200, 100); | |
| 1938 break; | 1937 break; |
| 1939 case SETTINGS_DOWNLOAD_RETRANS_RATE: | 1938 case SETTINGS_DOWNLOAD_RETRANS_RATE: |
| 1940 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate", | 1939 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate", |
| 1941 setting.second, | 1940 val, 1, 100, 50); |
| 1942 1, 100, 50); | 1941 break; |
| 1942 default: |
| 1943 break; | 1943 break; |
| 1944 } | 1944 } |
| 1945 } | 1945 } |
| 1946 } | 1946 } |
| 1947 } | 1947 } |
| 1948 | 1948 |
| 1949 void SpdySession::InvokeUserStreamCreationCallback( | 1949 void SpdySession::InvokeUserStreamCreationCallback( |
| 1950 scoped_refptr<SpdyStream>* stream) { | 1950 scoped_refptr<SpdyStream>* stream) { |
| 1951 PendingCallbackMap::iterator it = pending_callback_map_.find(stream); | 1951 PendingCallbackMap::iterator it = pending_callback_map_.find(stream); |
| 1952 | 1952 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1963 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1963 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
| 1964 if (!is_secure_) | 1964 if (!is_secure_) |
| 1965 return NULL; | 1965 return NULL; |
| 1966 SSLClientSocket* ssl_socket = | 1966 SSLClientSocket* ssl_socket = |
| 1967 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1967 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
| 1968 DCHECK(ssl_socket); | 1968 DCHECK(ssl_socket); |
| 1969 return ssl_socket; | 1969 return ssl_socket; |
| 1970 } | 1970 } |
| 1971 | 1971 |
| 1972 } // namespace net | 1972 } // namespace net |
| OLD | NEW |