| 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_seconds_ = 10; | 238 int SpdySession::connection_at_risk_of_loss_seconds_ = 10; | 
| 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 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1405   if (!need_to_send_ping_) | 1406   if (!need_to_send_ping_) | 
| 1406     return; | 1407     return; | 
| 1407 | 1408 | 
| 1408   PlanToSendTrailingPing(); | 1409   PlanToSendTrailingPing(); | 
| 1409 } | 1410 } | 
| 1410 | 1411 | 
| 1411 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) { | 1412 void SpdySession::OnSettings(const spdy::SpdySettingsControlFrame& frame) { | 
| 1412   spdy::SpdySettings settings; | 1413   spdy::SpdySettings settings; | 
| 1413   if (spdy_framer_.ParseSettings(&frame, &settings)) { | 1414   if (spdy_framer_.ParseSettings(&frame, &settings)) { | 
| 1414     HandleSettings(settings); | 1415     HandleSettings(settings); | 
| 1415     spdy_settings_->Set(host_port_pair(), settings); | 1416     http_server_properties_->SetSpdySettings(host_port_pair(), settings); | 
| 1416   } | 1417   } | 
| 1417 | 1418 | 
| 1418   received_settings_ = true; | 1419   received_settings_ = true; | 
| 1419 | 1420 | 
| 1420   net_log_.AddEvent( | 1421   net_log_.AddEvent( | 
| 1421       NetLog::TYPE_SPDY_SESSION_RECV_SETTINGS, | 1422       NetLog::TYPE_SPDY_SESSION_RECV_SETTINGS, | 
| 1422       make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1423       make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 
| 1423 } | 1424 } | 
| 1424 | 1425 | 
| 1425 void SpdySession::OnWindowUpdate( | 1426 void SpdySession::OnWindowUpdate( | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1486   else if (trial->group_name() == "cwndDynamic") | 1487   else if (trial->group_name() == "cwndDynamic") | 
| 1487     return cwnd; | 1488     return cwnd; | 
| 1488   NOTREACHED(); | 1489   NOTREACHED(); | 
| 1489   return cwnd; | 1490   return cwnd; | 
| 1490 } | 1491 } | 
| 1491 | 1492 | 
| 1492 void SpdySession::SendSettings() { | 1493 void SpdySession::SendSettings() { | 
| 1493   // Note:  we're copying the settings here, so that we can potentially modify | 1494   // Note:  we're copying the settings here, so that we can potentially modify | 
| 1494   // the settings for the field trial.  When removing the field trial, make | 1495   // the settings for the field trial.  When removing the field trial, make | 
| 1495   // this a reference to the const SpdySettings again. | 1496   // this a reference to the const SpdySettings again. | 
| 1496   spdy::SpdySettings settings = spdy_settings_->Get(host_port_pair()); | 1497   spdy::SpdySettings settings = | 
|  | 1498       http_server_properties_->GetSpdySettings(host_port_pair()); | 
| 1497   if (settings.empty()) | 1499   if (settings.empty()) | 
| 1498     return; | 1500     return; | 
| 1499 | 1501 | 
| 1500   // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. | 1502   // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. | 
| 1501   for (spdy::SpdySettings::iterator i = settings.begin(), | 1503   for (spdy::SpdySettings::iterator i = settings.begin(), | 
| 1502            end = settings.end(); i != end; ++i) { | 1504            end = settings.end(); i != end; ++i) { | 
| 1503     const uint32 id = i->first.id(); | 1505     const uint32 id = i->first.id(); | 
| 1504     const uint32 val = i->second; | 1506     const uint32 val = i->second; | 
| 1505     switch (id) { | 1507     switch (id) { | 
| 1506       case spdy::SETTINGS_CURRENT_CWND: | 1508       case spdy::SETTINGS_CURRENT_CWND: | 
| 1507         uint32 cwnd = 0; | 1509         uint32 cwnd = 0; | 
| 1508         cwnd = ApplyCwndFieldTrialPolicy(val); | 1510         cwnd = ApplyCwndFieldTrialPolicy(val); | 
| 1509         UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", | 1511         UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", | 
| 1510                                     cwnd, | 1512                                     cwnd, | 
| 1511                                     1, 200, 100); | 1513                                     1, 200, 100); | 
| 1512         if (cwnd != val) { | 1514         if (cwnd != val) { | 
| 1513           i->second = cwnd; | 1515           i->second = cwnd; | 
| 1514           i->first.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 1516           i->first.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 
| 1515           spdy_settings_->Set(host_port_pair(), settings); | 1517           http_server_properties_->SetSpdySettings(host_port_pair(), settings); | 
| 1516         } | 1518         } | 
| 1517         break; | 1519         break; | 
| 1518     } | 1520     } | 
| 1519   } | 1521   } | 
| 1520 | 1522 | 
| 1521   HandleSettings(settings); | 1523   HandleSettings(settings); | 
| 1522 | 1524 | 
| 1523   net_log_.AddEvent( | 1525   net_log_.AddEvent( | 
| 1524       NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | 1526       NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | 
| 1525       make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 1527       make_scoped_refptr(new NetLogSpdySettingsParameter(settings))); | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1667   UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", | 1669   UMA_HISTOGRAM_ENUMERATION("Net.SpdySettingsReceived", | 
| 1668                             received_settings_ ? 1 : 0, 2); | 1670                             received_settings_ ? 1 : 0, 2); | 
| 1669   UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", | 1671   UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdyStreamStallsPerSession", | 
| 1670                               stalled_streams_, | 1672                               stalled_streams_, | 
| 1671                               0, 300, 50); | 1673                               0, 300, 50); | 
| 1672   UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", | 1674   UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionsWithStalls", | 
| 1673                             stalled_streams_ > 0 ? 1 : 0, 2); | 1675                             stalled_streams_ > 0 ? 1 : 0, 2); | 
| 1674 | 1676 | 
| 1675   if (received_settings_) { | 1677   if (received_settings_) { | 
| 1676     // Enumerate the saved settings, and set histograms for it. | 1678     // Enumerate the saved settings, and set histograms for it. | 
| 1677     const spdy::SpdySettings& settings = spdy_settings_->Get(host_port_pair()); | 1679     const spdy::SpdySettings& settings = | 
|  | 1680         http_server_properties_->GetSpdySettings(host_port_pair()); | 
| 1678 | 1681 | 
| 1679     spdy::SpdySettings::const_iterator it; | 1682     spdy::SpdySettings::const_iterator it; | 
| 1680     for (it = settings.begin(); it != settings.end(); ++it) { | 1683     for (it = settings.begin(); it != settings.end(); ++it) { | 
| 1681       const spdy::SpdySetting setting = *it; | 1684       const spdy::SpdySetting setting = *it; | 
| 1682       switch (setting.first.id()) { | 1685       switch (setting.first.id()) { | 
| 1683         case spdy::SETTINGS_CURRENT_CWND: | 1686         case spdy::SETTINGS_CURRENT_CWND: | 
| 1684           // Record several different histograms to see if cwnd converges | 1687           // Record several different histograms to see if cwnd converges | 
| 1685           // for larger volumes of data being sent. | 1688           // for larger volumes of data being sent. | 
| 1686           UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", | 1689           UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwnd", | 
| 1687                                       setting.second, | 1690                                       setting.second, | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1730   if (it == pending_callback_map_.end()) | 1733   if (it == pending_callback_map_.end()) | 
| 1731     return; | 1734     return; | 
| 1732 | 1735 | 
| 1733   OldCompletionCallback* callback = it->second.callback; | 1736   OldCompletionCallback* callback = it->second.callback; | 
| 1734   int result = it->second.result; | 1737   int result = it->second.result; | 
| 1735   pending_callback_map_.erase(it); | 1738   pending_callback_map_.erase(it); | 
| 1736   callback->Run(result); | 1739   callback->Run(result); | 
| 1737 } | 1740 } | 
| 1738 | 1741 | 
| 1739 }  // namespace net | 1742 }  // namespace net | 
| OLD | NEW | 
|---|