Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: net/spdy/spdy_session.cc

Issue 9802003: SPDY - persist SPDY settings. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(spdy::SpdySettingsIds id,
129 uint8 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 spdy::SpdySettingsIds id_;
147 const uint8 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 spdy::SpdySettings& settings) 155 explicit NetLogSpdySettingsParameter(const spdy::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 (spdy::SpdySettings::const_iterator it = settings_.begin(); 161 for (spdy::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
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(spdy::SpdySettingsIds id, 1358 void SpdySession::OnSetting(spdy::SpdySettingsIds id,
1332 uint8 flags, 1359 uint8 flags,
1333 uint32 value) { 1360 uint32 value) {
1334 HandleSetting(id, value); 1361 HandleSetting(id, value);
1335 spdy::SettingsFlagsAndId flags_and_id(flags, id); 1362
1336 // TODO(rtenneti): persist SpdySetting. 1363 spdy::SettingsFlagsAndValue flags_and_value(flags, value);
1337 // http_server_properties_->SetSpdySetting( 1364 http_server_properties_->SetSpdySetting(
1338 // host_port_pair(), std::make_pair(flags_and_id, value)); 1365 host_port_pair(), id, flags_and_value);
Ryan Hamilton 2012/03/21 16:24:41 This API seems a bit suboptimal. instead of takin
ramant (doing other things) 2012/03/23 04:11:25 Done.
1339 1366
1340 received_settings_ = true; 1367 received_settings_ = true;
1341 1368
1342 // Log the settings. 1369 // Log the setting.
1343 spdy::SpdySettings settings;
1344 settings.insert(settings.end(), std::make_pair(flags_and_id, value));
1345 net_log_.AddEvent( 1370 net_log_.AddEvent(
Ryan Hamilton 2012/03/21 16:24:41 Hm. This means that we'll end up with 1 log entry
ramant (doing other things) 2012/03/23 04:11:25 +1. Will create a bug for buffering.
Ryan Hamilton 2012/03/23 15:25:38 Thanks.
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(id, flags, value)));
1348 } 1373 }
1349 1374
1350 bool SpdySession::Respond(const spdy::SpdyHeaderBlock& headers, 1375 bool SpdySession::Respond(const spdy::SpdyHeaderBlock& headers,
1351 const scoped_refptr<SpdyStream> stream) { 1376 const scoped_refptr<SpdyStream> stream) {
1352 int rv = OK; 1377 int rv = OK;
1353 rv = stream->OnResponseReceived(headers); 1378 rv = stream->OnResponseReceived(headers);
1354 if (rv < 0) { 1379 if (rv < 0) {
1355 DCHECK_NE(rv, ERR_IO_PENDING); 1380 DCHECK_NE(rv, ERR_IO_PENDING);
1356 const spdy::SpdyStreamId stream_id = stream->stream_id(); 1381 const spdy::SpdyStreamId stream_id = stream->stream_id();
1357 DeleteStream(stream_id, rv); 1382 DeleteStream(stream_id, rv);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 return std::max(cwnd, 16); 1696 return std::max(cwnd, 16);
1672 else if (trial->group_name() == "cwndMin10") 1697 else if (trial->group_name() == "cwndMin10")
1673 return std::max(cwnd, 10); 1698 return std::max(cwnd, 10);
1674 else if (trial->group_name() == "cwndDynamic") 1699 else if (trial->group_name() == "cwndDynamic")
1675 return cwnd; 1700 return cwnd;
1676 NOTREACHED(); 1701 NOTREACHED();
1677 return cwnd; 1702 return cwnd;
1678 } 1703 }
1679 1704
1680 void SpdySession::SendSettings() { 1705 void SpdySession::SendSettings() {
1681 // Note: we're copying the settings here, so that we can potentially modify 1706 // Note: we can potentially modify the settings for the field trial.
Ryan Hamilton 2012/03/21 16:24:41 I think I would remove this comment. It doesn't s
ramant (doing other things) 2012/03/23 04:11:25 Done.
1682 // the settings for the field trial. When removing the field trial, make 1707 const spdy::SettingsMap& settings_map =
1683 // this a reference to the const SpdySettings again.
1684 spdy::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, spdy::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 (spdy::SpdySettings::iterator i = settings.begin(), 1713 for (spdy::SettingsMap::const_iterator i = settings_map.begin(),
Ryan Hamilton 2012/03/21 16:24:41 Since this is a map, I don't think you need to loo
ramant (doing other things) 2012/03/23 04:11:25 Thanks for the above. Done.
1694 end = settings.end(); i != end; ++i) { 1714 end = settings_map.end(); i != end; ++i) {
1695 const uint32 id = i->first.id(); 1715 const uint32 id = i->first;
Ryan Hamilton 2012/03/21 16:24:41 nit: should the type of id be spdy::SpdySettingsId
ramant (doing other things) 2012/03/23 04:11:25 Done.
1696 const uint32 val = i->second; 1716 const uint32 val = i->second.second;
1697 switch (id) { 1717 switch (id) {
1698 case spdy::SETTINGS_CURRENT_CWND: 1718 case spdy::SETTINGS_CURRENT_CWND:
1699 uint32 cwnd = 0; 1719 uint32 cwnd = 0;
1700 cwnd = ApplyCwndFieldTrialPolicy(val); 1720 cwnd = ApplyCwndFieldTrialPolicy(val);
1701 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", 1721 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent",
1702 cwnd, 1722 cwnd, 1, 200, 100);
1703 1, 200, 100);
1704 if (cwnd != val) { 1723 if (cwnd != val) {
1705 spdy::SettingsFlagsAndId new_id(spdy::SETTINGS_FLAG_PLEASE_PERSIST, 1724 spdy::SettingsFlagsAndValue flags_and_value(
1706 id); 1725 spdy::SETTINGS_FLAG_PLEASE_PERSIST, cwnd);
1707 i->second = cwnd; 1726 http_server_properties_->SetSpdySetting(
1708 i->first = new_id; 1727 host_port_pair(), id, flags_and_value);
1709 spdy::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 } 1728 }
1729 break;
1715 } 1730 }
1716 unique_settings[id] = *i;
1717 } 1731 }
1718 1732
1719 HandleSettings(settings); 1733 const spdy::SettingsMap& settings_map_new =
1734 http_server_properties_->GetSpdySettings(host_port_pair());
1735
1736 spdy::SpdySettings settings;
Ryan Hamilton 2012/03/21 16:24:41 Oh, here we're using SpdySettings as a list. How
ramant (doing other things) 2012/03/23 04:11:25 Would like to a submit a separate CL to delete all
Ryan Hamilton 2012/03/23 15:25:38 Sounds good.
1737 for (spdy::SettingsMap::const_iterator i = settings_map_new.begin(),
1738 end = settings_map_new.end(); i != end; ++i) {
1739 const uint32 id = i->first;
1740 const uint8 flags = i->second.first;
1741 const uint32 val = i->second.second;
1742 HandleSetting(id, val);
1743 spdy::SettingsFlagsAndId flags_and_id(flags, id);
1744 settings.push_back(spdy::SpdySetting(flags_and_id, val));
1745 }
1720 1746
1721 net_log_.AddEvent( 1747 net_log_.AddEvent(
1722 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, 1748 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS,
1723 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); 1749 make_scoped_refptr(new NetLogSpdySettingsParameter(settings)));
1724 1750
1725 spdy::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. 1751 // Create the SETTINGS frame and send it.
1733 DCHECK(buffered_spdy_framer_.get()); 1752 DCHECK(buffered_spdy_framer_.get());
1734 scoped_ptr<spdy::SpdySettingsControlFrame> settings_frame( 1753 scoped_ptr<spdy::SpdySettingsControlFrame> settings_frame(
1735 buffered_spdy_framer_->CreateSettings(sorted_settings)); 1754 buffered_spdy_framer_->CreateSettings(settings));
1736 sent_settings_ = true; 1755 sent_settings_ = true;
1737 QueueFrame(settings_frame.get(), 0, NULL); 1756 QueueFrame(settings_frame.get(), 0, NULL);
1738 } 1757 }
1739 1758
1740 void SpdySession::HandleSettings(const spdy::SpdySettings& settings) {
1741 for (spdy::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) { 1759 void SpdySession::HandleSetting(uint32 id, uint32 value) {
1748 switch (id) { 1760 switch (id) {
1749 case spdy::SETTINGS_MAX_CONCURRENT_STREAMS: 1761 case spdy::SETTINGS_MAX_CONCURRENT_STREAMS:
1750 max_concurrent_streams_ = std::min(static_cast<size_t>(value), 1762 max_concurrent_streams_ = std::min(static_cast<size_t>(value),
1751 g_max_concurrent_stream_limit); 1763 g_max_concurrent_stream_limit);
1752 ProcessPendingCreateStreams(); 1764 ProcessPendingCreateStreams();
1753 break; 1765 break;
1754 case spdy::SETTINGS_INITIAL_WINDOW_SIZE: 1766 case spdy::SETTINGS_INITIAL_WINDOW_SIZE:
1755 // INITIAL_WINDOW_SIZE updates initial_send_window_size_ only. 1767 // INITIAL_WINDOW_SIZE updates initial_send_window_size_ only.
1756 // TODO(rtenneti): discuss with the server team about 1768 // TODO(rtenneti): discuss with the server team about
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", 1902 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived",
1891 received_settings_ ? 1 : 0, 2); 1903 received_settings_ ? 1 : 0, 2);
1892 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", 1904 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession",
1893 stalled_streams_, 1905 stalled_streams_,
1894 0, 300, 50); 1906 0, 300, 50);
1895 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", 1907 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls",
1896 stalled_streams_ > 0 ? 1 : 0, 2); 1908 stalled_streams_ > 0 ? 1 : 0, 2);
1897 1909
1898 if (received_settings_) { 1910 if (received_settings_) {
1899 // Enumerate the saved settings, and set histograms for it. 1911 // Enumerate the saved settings, and set histograms for it.
1900 const spdy::SpdySettings& settings = 1912 const spdy::SettingsMap& settings_map =
1901 http_server_properties_->GetSpdySettings(host_port_pair()); 1913 http_server_properties_->GetSpdySettings(host_port_pair());
1902 1914
1903 spdy::SpdySettings::const_iterator it; 1915 spdy::SettingsMap::const_iterator it;
1904 for (it = settings.begin(); it != settings.end(); ++it) { 1916 for (it = settings_map.begin(); it != settings_map.end(); ++it) {
1905 const spdy::SpdySetting setting = *it; 1917 const uint32 id = it->first;
1906 switch (setting.first.id()) { 1918 const uint32 val = it->second.second;
Ryan Hamilton 2012/03/21 16:24:41 Nice cleanup. Much more readable. nit: should id
ramant (doing other things) 2012/03/23 04:11:25 Done.
1919 switch (id) {
1907 case spdy::SETTINGS_CURRENT_CWND: 1920 case spdy::SETTINGS_CURRENT_CWND:
1908 // Record several different histograms to see if cwnd converges 1921 // Record several different histograms to see if cwnd converges
1909 // for larger volumes of data being sent. 1922 // for larger volumes of data being sent.
1910 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", 1923 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd",
1911 setting.second, 1924 val, 1, 200, 100);
1912 1, 200, 100);
1913 if (bytes_received_ > 10 * 1024) { 1925 if (bytes_received_ > 10 * 1024) {
1914 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd10K", 1926 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd10K",
1915 setting.second, 1927 val, 1, 200, 100);
1916 1, 200, 100);
1917 if (bytes_received_ > 25 * 1024) { 1928 if (bytes_received_ > 25 * 1024) {
1918 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd25K", 1929 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd25K",
1919 setting.second, 1930 val, 1, 200, 100);
1920 1, 200, 100);
1921 if (bytes_received_ > 50 * 1024) { 1931 if (bytes_received_ > 50 * 1024) {
1922 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd50K", 1932 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd50K",
1923 setting.second, 1933 val, 1, 200, 100);
1924 1, 200, 100);
1925 if (bytes_received_ > 100 * 1024) { 1934 if (bytes_received_ > 100 * 1024) {
1926 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd100K", 1935 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd100K",
1927 setting.second, 1936 val, 1, 200, 100);
1928 1, 200, 100);
1929 } 1937 }
1930 } 1938 }
1931 } 1939 }
1932 } 1940 }
1933 break; 1941 break;
1934 case spdy::SETTINGS_ROUND_TRIP_TIME: 1942 case spdy::SETTINGS_ROUND_TRIP_TIME:
1935 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRTT", 1943 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRTT",
1936 setting.second, 1944 val, 1, 1200, 100);
1937 1, 1200, 100);
1938 break; 1945 break;
1939 case spdy::SETTINGS_DOWNLOAD_RETRANS_RATE: 1946 case spdy::SETTINGS_DOWNLOAD_RETRANS_RATE:
1940 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate", 1947 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsRetransRate",
1941 setting.second, 1948 val, 1, 100, 50);
1942 1, 100, 50);
1943 break; 1949 break;
1944 } 1950 }
1945 } 1951 }
1946 } 1952 }
1947 } 1953 }
1948 1954
1949 void SpdySession::InvokeUserStreamCreationCallback( 1955 void SpdySession::InvokeUserStreamCreationCallback(
1950 scoped_refptr<SpdyStream>* stream) { 1956 scoped_refptr<SpdyStream>* stream) {
1951 PendingCallbackMap::iterator it = pending_callback_map_.find(stream); 1957 PendingCallbackMap::iterator it = pending_callback_map_.find(stream);
1952 1958
(...skipping 10 matching lines...) Expand all
1963 SSLClientSocket* SpdySession::GetSSLClientSocket() const { 1969 SSLClientSocket* SpdySession::GetSSLClientSocket() const {
1964 if (!is_secure_) 1970 if (!is_secure_)
1965 return NULL; 1971 return NULL;
1966 SSLClientSocket* ssl_socket = 1972 SSLClientSocket* ssl_socket =
1967 reinterpret_cast<SSLClientSocket*>(connection_->socket()); 1973 reinterpret_cast<SSLClientSocket*>(connection_->socket());
1968 DCHECK(ssl_socket); 1974 DCHECK(ssl_socket);
1969 return ssl_socket; 1975 return ssl_socket;
1970 } 1976 }
1971 1977
1972 } // namespace net 1978 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698