| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/metrics/stats_counters.h" | 12 #include "base/metrics/stats_counters.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "net/base/connection_type_histograms.h" | 20 #include "net/base/connection_type_histograms.h" |
| 21 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
| 22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 23 #include "net/http/http_network_session.h" | 23 #include "net/http/http_network_session.h" |
| 24 #include "net/http/http_server_properties.h" |
| 24 #include "net/socket/ssl_client_socket.h" | 25 #include "net/socket/ssl_client_socket.h" |
| 25 #include "net/spdy/spdy_frame_builder.h" | 26 #include "net/spdy/spdy_frame_builder.h" |
| 26 #include "net/spdy/spdy_http_utils.h" | 27 #include "net/spdy/spdy_http_utils.h" |
| 27 #include "net/spdy/spdy_protocol.h" | 28 #include "net/spdy/spdy_protocol.h" |
| 28 #include "net/spdy/spdy_session_pool.h" | 29 #include "net/spdy/spdy_session_pool.h" |
| 29 #include "net/spdy/spdy_settings_storage.h" | 30 #include "net/spdy/spdy_settings_storage.h" |
| 30 #include "net/spdy/spdy_stream.h" | 31 #include "net/spdy/spdy_stream.h" |
| 31 | 32 |
| 32 namespace net { | 33 namespace net { |
| 33 | 34 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 int SpdySession::connection_at_risk_of_loss_ms_ = 0; | 238 int SpdySession::connection_at_risk_of_loss_ms_ = 0; |
| 238 | 239 |
| 239 // static | 240 // static |
| 240 int SpdySession::trailing_ping_delay_time_ms_ = 1000; | 241 int SpdySession::trailing_ping_delay_time_ms_ = 1000; |
| 241 | 242 |
| 242 // static | 243 // static |
| 243 int SpdySession::hung_interval_ms_ = 10000; | 244 int SpdySession::hung_interval_ms_ = 10000; |
| 244 | 245 |
| 245 SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 246 SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
| 246 SpdySessionPool* spdy_session_pool, | 247 SpdySessionPool* spdy_session_pool, |
| 247 SpdySettingsStorage* spdy_settings, | 248 HttpServerProperties* http_server_properties, |
| 248 bool verify_domain_authentication, | 249 bool verify_domain_authentication, |
| 249 NetLog* net_log) | 250 NetLog* net_log) |
| 250 : ALLOW_THIS_IN_INITIALIZER_LIST( | 251 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 251 read_callback_(this, &SpdySession::OnReadComplete)), | 252 read_callback_(this, &SpdySession::OnReadComplete)), |
| 252 ALLOW_THIS_IN_INITIALIZER_LIST( | 253 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 253 write_callback_(this, &SpdySession::OnWriteComplete)), | 254 write_callback_(this, &SpdySession::OnWriteComplete)), |
| 254 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 255 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 255 host_port_proxy_pair_(host_port_proxy_pair), | 256 host_port_proxy_pair_(host_port_proxy_pair), |
| 256 spdy_session_pool_(spdy_session_pool), | 257 spdy_session_pool_(spdy_session_pool), |
| 257 spdy_settings_(spdy_settings), | 258 http_server_properties_(http_server_properties), |
| 258 connection_(new ClientSocketHandle), | 259 connection_(new ClientSocketHandle), |
| 259 read_buffer_(new IOBuffer(kReadBufferSize)), | 260 read_buffer_(new IOBuffer(kReadBufferSize)), |
| 260 read_pending_(false), | 261 read_pending_(false), |
| 261 stream_hi_water_mark_(1), // Always start at 1 for the first stream id. | 262 stream_hi_water_mark_(1), // Always start at 1 for the first stream id. |
| 262 write_pending_(false), | 263 write_pending_(false), |
| 263 delayed_write_pending_(false), | 264 delayed_write_pending_(false), |
| 264 is_secure_(false), | 265 is_secure_(false), |
| 265 certificate_error_code_(OK), | 266 certificate_error_code_(OK), |
| 266 error_(OK), | 267 error_(OK), |
| 267 state_(IDLE), | 268 state_(IDLE), |
| (...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 if (!need_to_send_ping_) | 1394 if (!need_to_send_ping_) |
| 1394 return; | 1395 return; |
| 1395 | 1396 |
| 1396 PlanToSendTrailingPing(); | 1397 PlanToSendTrailingPing(); |
| 1397 } | 1398 } |
| 1398 | 1399 |
| 1399 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) { | 1400 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) { |
| 1400 spdy::SpdySettings settings; | 1401 spdy::SpdySettings settings; |
| 1401 if (spdy_framer_.ParseSettings(&frame, &settings)) { | 1402 if (spdy_framer_.ParseSettings(&frame, &settings)) { |
| 1402 HandleSettings(settings); | 1403 HandleSettings(settings); |
| 1403 spdy_settings_->Set(host_port_pair(), settings); | 1404 http_server_properties_->SetSpdySettings(host_port_pair(), settings); |
| 1404 } | 1405 } |
| 1405 | 1406 |
| 1406 received_settings_ = true; | 1407 received_settings_ = true; |
| 1407 | 1408 |
| 1408 net_log_.AddEvent( | 1409 net_log_.AddEvent( |
| 1409 NetLog::TYPE_SPDY_SESSION_RECV_SETTINGS, | 1410 NetLog::TYPE_SPDY_SESSION_RECV_SETTINGS, |
| 1410 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1411 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); |
| 1411 } | 1412 } |
| 1412 | 1413 |
| 1413 void SpdySession::OnWindowUpdate( | 1414 void SpdySession::OnWindowUpdate( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 else if (trial->group_name() == "cwndDynamic") | 1475 else if (trial->group_name() == "cwndDynamic") |
| 1475 return cwnd; | 1476 return cwnd; |
| 1476 NOTREACHED(); | 1477 NOTREACHED(); |
| 1477 return cwnd; | 1478 return cwnd; |
| 1478 } | 1479 } |
| 1479 | 1480 |
| 1480 void SpdySession::SendSettings() { | 1481 void SpdySession::SendSettings() { |
| 1481 // Note: we're copying the settings here, so that we can potentially modify | 1482 // Note: we're copying the settings here, so that we can potentially modify |
| 1482 // the settings for the field trial. When removing the field trial, make | 1483 // the settings for the field trial. When removing the field trial, make |
| 1483 // this a reference to the const SpdySettings again. | 1484 // this a reference to the const SpdySettings again. |
| 1484 spdy::SpdySettings settings = spdy_settings_->Get(host_port_pair()); | 1485 spdy::SpdySettings settings = |
| 1486 http_server_properties_->GetSpdySettings(host_port_pair()); |
| 1485 if (settings.empty()) | 1487 if (settings.empty()) |
| 1486 return; | 1488 return; |
| 1487 | 1489 |
| 1488 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. | 1490 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. |
| 1489 for (spdy::SpdySettings::iterator i = settings.begin(), | 1491 for (spdy::SpdySettings::iterator i = settings.begin(), |
| 1490 end = settings.end(); i != end; ++i) { | 1492 end = settings.end(); i != end; ++i) { |
| 1491 const uint32 id = i->first.id(); | 1493 const uint32 id = i->first.id(); |
| 1492 const uint32 val = i->second; | 1494 const uint32 val = i->second; |
| 1493 switch (id) { | 1495 switch (id) { |
| 1494 case spdy::SETTINGS_CURRENT_CWND: | 1496 case spdy::SETTINGS_CURRENT_CWND: |
| 1495 uint32 cwnd = 0; | 1497 uint32 cwnd = 0; |
| 1496 cwnd = ApplyCwndFieldTrialPolicy(val); | 1498 cwnd = ApplyCwndFieldTrialPolicy(val); |
| 1497 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", | 1499 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", |
| 1498 cwnd, | 1500 cwnd, |
| 1499 1, 200, 100); | 1501 1, 200, 100); |
| 1500 if (cwnd != val) { | 1502 if (cwnd != val) { |
| 1501 i->second = cwnd; | 1503 i->second = cwnd; |
| 1502 i->first.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 1504 i->first.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
| 1503 spdy_settings_->Set(host_port_pair(), settings); | 1505 http_server_properties_->SetSpdySettings(host_port_pair(), settings); |
| 1504 } | 1506 } |
| 1505 break; | 1507 break; |
| 1506 } | 1508 } |
| 1507 } | 1509 } |
| 1508 | 1510 |
| 1509 HandleSettings(settings); | 1511 HandleSettings(settings); |
| 1510 | 1512 |
| 1511 net_log_.AddEvent( | 1513 net_log_.AddEvent( |
| 1512 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | 1514 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, |
| 1513 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1515 make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", | 1659 UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", |
| 1658 received_settings_ ? 1 : 0, 2); | 1660 received_settings_ ? 1 : 0, 2); |
| 1659 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", | 1661 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", |
| 1660 stalled_streams_, | 1662 stalled_streams_, |
| 1661 0, 300, 50); | 1663 0, 300, 50); |
| 1662 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", | 1664 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", |
| 1663 stalled_streams_ > 0 ? 1 : 0, 2); | 1665 stalled_streams_ > 0 ? 1 : 0, 2); |
| 1664 | 1666 |
| 1665 if (received_settings_) { | 1667 if (received_settings_) { |
| 1666 // Enumerate the saved settings, and set histograms for it. | 1668 // Enumerate the saved settings, and set histograms for it. |
| 1667 const spdy::SpdySettings& settings = spdy_settings_->Get(host_port_pair()); | 1669 const spdy::SpdySettings& settings = |
| 1670 http_server_properties_->GetSpdySettings(host_port_pair()); |
| 1668 | 1671 |
| 1669 spdy::SpdySettings::const_iterator it; | 1672 spdy::SpdySettings::const_iterator it; |
| 1670 for (it = settings.begin(); it != settings.end(); ++it) { | 1673 for (it = settings.begin(); it != settings.end(); ++it) { |
| 1671 const spdy::SpdySetting setting = *it; | 1674 const spdy::SpdySetting setting = *it; |
| 1672 switch (setting.first.id()) { | 1675 switch (setting.first.id()) { |
| 1673 case spdy::SETTINGS_CURRENT_CWND: | 1676 case spdy::SETTINGS_CURRENT_CWND: |
| 1674 // Record several different histograms to see if cwnd converges | 1677 // Record several different histograms to see if cwnd converges |
| 1675 // for larger volumes of data being sent. | 1678 // for larger volumes of data being sent. |
| 1676 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", | 1679 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", |
| 1677 setting.second, | 1680 setting.second, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 if (it == pending_callback_map_.end()) | 1723 if (it == pending_callback_map_.end()) |
| 1721 return; | 1724 return; |
| 1722 | 1725 |
| 1723 OldCompletionCallback* callback = it->second.callback; | 1726 OldCompletionCallback* callback = it->second.callback; |
| 1724 int result = it->second.result; | 1727 int result = it->second.result; |
| 1725 pending_callback_map_.erase(it); | 1728 pending_callback_map_.erase(it); |
| 1726 callback->Run(result); | 1729 callback->Run(result); |
| 1727 } | 1730 } |
| 1728 | 1731 |
| 1729 } // namespace net | 1732 } // namespace net |
| OLD | NEW |