| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 int size, | 219 int size, |
| 220 bool fin, | 220 bool fin, |
| 221 NetLogCaptureMode /* capture_mode */) { | 221 NetLogCaptureMode /* capture_mode */) { |
| 222 auto dict = base::MakeUnique<base::DictionaryValue>(); | 222 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 223 dict->SetInteger("stream_id", static_cast<int>(stream_id)); | 223 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
| 224 dict->SetInteger("size", size); | 224 dict->SetInteger("size", size); |
| 225 dict->SetBoolean("fin", fin); | 225 dict->SetBoolean("fin", fin); |
| 226 return std::move(dict); | 226 return std::move(dict); |
| 227 } | 227 } |
| 228 | 228 |
| 229 std::unique_ptr<base::Value> NetLogSpdyRstCallback( | 229 std::unique_ptr<base::Value> NetLogSpdyRecvRstStreamCallback( |
| 230 SpdyStreamId stream_id, |
| 231 int error_code, |
| 232 NetLogCaptureMode /* capture_mode */) { |
| 233 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 234 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
| 235 dict->SetInteger("status", error_code); |
| 236 return std::move(dict); |
| 237 } |
| 238 |
| 239 std::unique_ptr<base::Value> NetLogSpdySendRstStreamCallback( |
| 230 SpdyStreamId stream_id, | 240 SpdyStreamId stream_id, |
| 231 int error_code, | 241 int error_code, |
| 232 const std::string* description, | 242 const std::string* description, |
| 233 NetLogCaptureMode /* capture_mode */) { | 243 NetLogCaptureMode /* capture_mode */) { |
| 234 auto dict = base::MakeUnique<base::DictionaryValue>(); | 244 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 235 dict->SetInteger("stream_id", static_cast<int>(stream_id)); | 245 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
| 236 dict->SetInteger("error_code", error_code); | 246 dict->SetInteger("error_code", error_code); |
| 237 dict->SetString("description", *description); | 247 dict->SetString("description", *description); |
| 238 return std::move(dict); | 248 return std::move(dict); |
| 239 } | 249 } |
| 240 | 250 |
| 241 std::unique_ptr<base::Value> NetLogSpdyPingCallback( | 251 std::unique_ptr<base::Value> NetLogSpdyPingCallback( |
| 242 SpdyPingId unique_id, | 252 SpdyPingId unique_id, |
| 243 bool is_ack, | 253 bool is_ack, |
| 244 const char* type, | 254 const char* type, |
| 245 NetLogCaptureMode /* capture_mode */) { | 255 NetLogCaptureMode /* capture_mode */) { |
| 246 auto dict = base::MakeUnique<base::DictionaryValue>(); | 256 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 247 dict->SetInteger("unique_id", static_cast<int>(unique_id)); | 257 dict->SetInteger("unique_id", static_cast<int>(unique_id)); |
| 248 dict->SetString("type", type); | 258 dict->SetString("type", type); |
| 249 dict->SetBoolean("is_ack", is_ack); | 259 dict->SetBoolean("is_ack", is_ack); |
| 250 return std::move(dict); | 260 return std::move(dict); |
| 251 } | 261 } |
| 252 | 262 |
| 253 std::unique_ptr<base::Value> NetLogSpdyGoAwayCallback( | 263 std::unique_ptr<base::Value> NetLogSpdyRecvGoAwayCallback( |
| 254 SpdyStreamId last_stream_id, | 264 SpdyStreamId last_stream_id, |
| 255 int active_streams, | 265 int active_streams, |
| 256 int unclaimed_streams, | 266 int unclaimed_streams, |
| 257 SpdyErrorCode error_code, | 267 SpdyErrorCode error_code, |
| 258 base::StringPiece debug_data, | 268 base::StringPiece debug_data, |
| 259 NetLogCaptureMode capture_mode) { | 269 NetLogCaptureMode capture_mode) { |
| 260 auto dict = base::MakeUnique<base::DictionaryValue>(); | 270 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 261 dict->SetInteger("last_accepted_stream_id", | 271 dict->SetInteger("last_accepted_stream_id", |
| 262 static_cast<int>(last_stream_id)); | 272 static_cast<int>(last_stream_id)); |
| 263 dict->SetInteger("active_streams", active_streams); | 273 dict->SetInteger("active_streams", active_streams); |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 // in-flight one. | 1343 // in-flight one. |
| 1334 CloseActiveStreamIterator(it, ERR_SPDY_PROTOCOL_ERROR); | 1344 CloseActiveStreamIterator(it, ERR_SPDY_PROTOCOL_ERROR); |
| 1335 } | 1345 } |
| 1336 | 1346 |
| 1337 void SpdySession::EnqueueResetStreamFrame(SpdyStreamId stream_id, | 1347 void SpdySession::EnqueueResetStreamFrame(SpdyStreamId stream_id, |
| 1338 RequestPriority priority, | 1348 RequestPriority priority, |
| 1339 SpdyErrorCode error_code, | 1349 SpdyErrorCode error_code, |
| 1340 const std::string& description) { | 1350 const std::string& description) { |
| 1341 DCHECK_NE(stream_id, 0u); | 1351 DCHECK_NE(stream_id, 0u); |
| 1342 | 1352 |
| 1343 net_log().AddEvent( | 1353 net_log().AddEvent(NetLogEventType::HTTP2_SESSION_SEND_RST_STREAM, |
| 1344 NetLogEventType::HTTP2_SESSION_SEND_RST_STREAM, | 1354 base::Bind(&NetLogSpdySendRstStreamCallback, stream_id, |
| 1345 base::Bind(&NetLogSpdyRstCallback, stream_id, error_code, &description)); | 1355 error_code, &description)); |
| 1346 | 1356 |
| 1347 DCHECK(buffered_spdy_framer_.get()); | 1357 DCHECK(buffered_spdy_framer_.get()); |
| 1348 std::unique_ptr<SpdySerializedFrame> rst_frame( | 1358 std::unique_ptr<SpdySerializedFrame> rst_frame( |
| 1349 buffered_spdy_framer_->CreateRstStream(stream_id, error_code)); | 1359 buffered_spdy_framer_->CreateRstStream(stream_id, error_code)); |
| 1350 | 1360 |
| 1351 EnqueueSessionWrite(priority, RST_STREAM, std::move(rst_frame)); | 1361 EnqueueSessionWrite(priority, RST_STREAM, std::move(rst_frame)); |
| 1352 RecordProtocolErrorHistogram(MapRstStreamStatusToProtocolError(error_code)); | 1362 RecordProtocolErrorHistogram(MapRstStreamStatusToProtocolError(error_code)); |
| 1353 } | 1363 } |
| 1354 | 1364 |
| 1355 void SpdySession::EnqueuePriorityFrame(SpdyStreamId stream_id, | 1365 void SpdySession::EnqueuePriorityFrame(SpdyStreamId stream_id, |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2364 if (stream_id % 2 == 0 && stream_id > last_accepted_push_stream_id_) | 2374 if (stream_id % 2 == 0 && stream_id > last_accepted_push_stream_id_) |
| 2365 return false; | 2375 return false; |
| 2366 | 2376 |
| 2367 return true; | 2377 return true; |
| 2368 } | 2378 } |
| 2369 | 2379 |
| 2370 void SpdySession::OnRstStream(SpdyStreamId stream_id, | 2380 void SpdySession::OnRstStream(SpdyStreamId stream_id, |
| 2371 SpdyErrorCode error_code) { | 2381 SpdyErrorCode error_code) { |
| 2372 CHECK(in_io_loop_); | 2382 CHECK(in_io_loop_); |
| 2373 | 2383 |
| 2374 std::string description; | |
| 2375 net_log().AddEvent( | 2384 net_log().AddEvent( |
| 2376 NetLogEventType::HTTP2_SESSION_RST_STREAM, | 2385 NetLogEventType::HTTP2_SESSION_RECV_RST_STREAM, |
| 2377 base::Bind(&NetLogSpdyRstCallback, stream_id, error_code, &description)); | 2386 base::Bind(&NetLogSpdyRecvRstStreamCallback, stream_id, error_code)); |
| 2378 | 2387 |
| 2379 ActiveStreamMap::iterator it = active_streams_.find(stream_id); | 2388 ActiveStreamMap::iterator it = active_streams_.find(stream_id); |
| 2380 if (it == active_streams_.end()) { | 2389 if (it == active_streams_.end()) { |
| 2381 // NOTE: it may just be that the stream was cancelled. | 2390 // NOTE: it may just be that the stream was cancelled. |
| 2382 LOG(WARNING) << "Received RST for invalid stream" << stream_id; | 2391 LOG(WARNING) << "Received RST for invalid stream" << stream_id; |
| 2383 return; | 2392 return; |
| 2384 } | 2393 } |
| 2385 | 2394 |
| 2386 CHECK_EQ(it->second->stream_id(), stream_id); | 2395 CHECK_EQ(it->second->stream_id(), stream_id); |
| 2387 | 2396 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2411 } | 2420 } |
| 2412 | 2421 |
| 2413 void SpdySession::OnGoAway(SpdyStreamId last_accepted_stream_id, | 2422 void SpdySession::OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 2414 SpdyErrorCode error_code, | 2423 SpdyErrorCode error_code, |
| 2415 base::StringPiece debug_data) { | 2424 base::StringPiece debug_data) { |
| 2416 CHECK(in_io_loop_); | 2425 CHECK(in_io_loop_); |
| 2417 | 2426 |
| 2418 // TODO(jgraettinger): UMA histogram on |error_code|. | 2427 // TODO(jgraettinger): UMA histogram on |error_code|. |
| 2419 | 2428 |
| 2420 net_log_.AddEvent( | 2429 net_log_.AddEvent( |
| 2421 NetLogEventType::HTTP2_SESSION_GOAWAY, | 2430 NetLogEventType::HTTP2_SESSION_RECV_GOAWAY, |
| 2422 base::Bind(&NetLogSpdyGoAwayCallback, last_accepted_stream_id, | 2431 base::Bind(&NetLogSpdyRecvGoAwayCallback, last_accepted_stream_id, |
| 2423 active_streams_.size(), unclaimed_pushed_streams_.size(), | 2432 active_streams_.size(), unclaimed_pushed_streams_.size(), |
| 2424 error_code, debug_data)); | 2433 error_code, debug_data)); |
| 2425 MakeUnavailable(); | 2434 MakeUnavailable(); |
| 2426 if (error_code == ERROR_CODE_HTTP_1_1_REQUIRED) { | 2435 if (error_code == ERROR_CODE_HTTP_1_1_REQUIRED) { |
| 2427 // TODO(bnc): Record histogram with number of open streams capped at 50. | 2436 // TODO(bnc): Record histogram with number of open streams capped at 50. |
| 2428 DoDrainSession(ERR_HTTP_1_1_REQUIRED, "HTTP_1_1_REQUIRED for stream."); | 2437 DoDrainSession(ERR_HTTP_1_1_REQUIRED, "HTTP_1_1_REQUIRED for stream."); |
| 2429 } else { | 2438 } else { |
| 2430 StartGoingAway(last_accepted_stream_id, ERR_ABORTED); | 2439 StartGoingAway(last_accepted_stream_id, ERR_ABORTED); |
| 2431 } | 2440 } |
| 2432 // This is to handle the case when we already don't have any active | 2441 // This is to handle the case when we already don't have any active |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2462 | 2471 |
| 2463 // We will record RTT in histogram when there are no more client sent | 2472 // We will record RTT in histogram when there are no more client sent |
| 2464 // pings_in_flight_. | 2473 // pings_in_flight_. |
| 2465 RecordPingRTTHistogram(time_func_() - last_ping_sent_time_); | 2474 RecordPingRTTHistogram(time_func_() - last_ping_sent_time_); |
| 2466 } | 2475 } |
| 2467 | 2476 |
| 2468 void SpdySession::OnWindowUpdate(SpdyStreamId stream_id, | 2477 void SpdySession::OnWindowUpdate(SpdyStreamId stream_id, |
| 2469 int delta_window_size) { | 2478 int delta_window_size) { |
| 2470 CHECK(in_io_loop_); | 2479 CHECK(in_io_loop_); |
| 2471 | 2480 |
| 2472 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECEIVED_WINDOW_UPDATE_FRAME, | 2481 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECV_WINDOW_UPDATE, |
| 2473 base::Bind(&NetLogSpdyWindowUpdateFrameCallback, stream_id, | 2482 base::Bind(&NetLogSpdyWindowUpdateFrameCallback, stream_id, |
| 2474 delta_window_size)); | 2483 delta_window_size)); |
| 2475 | 2484 |
| 2476 if (stream_id == kSessionFlowControlStreamId) { | 2485 if (stream_id == kSessionFlowControlStreamId) { |
| 2477 // WINDOW_UPDATE for the session. | 2486 // WINDOW_UPDATE for the session. |
| 2478 if (delta_window_size < 1) { | 2487 if (delta_window_size < 1) { |
| 2479 RecordProtocolErrorHistogram(PROTOCOL_ERROR_INVALID_WINDOW_UPDATE_SIZE); | 2488 RecordProtocolErrorHistogram(PROTOCOL_ERROR_INVALID_WINDOW_UPDATE_SIZE); |
| 2480 DoDrainSession( | 2489 DoDrainSession( |
| 2481 ERR_SPDY_PROTOCOL_ERROR, | 2490 ERR_SPDY_PROTOCOL_ERROR, |
| 2482 "Received WINDOW_UPDATE with an invalid delta_window_size " + | 2491 "Received WINDOW_UPDATE with an invalid delta_window_size " + |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2825 void SpdySession::SendWindowUpdateFrame(SpdyStreamId stream_id, | 2834 void SpdySession::SendWindowUpdateFrame(SpdyStreamId stream_id, |
| 2826 uint32_t delta_window_size, | 2835 uint32_t delta_window_size, |
| 2827 RequestPriority priority) { | 2836 RequestPriority priority) { |
| 2828 ActiveStreamMap::const_iterator it = active_streams_.find(stream_id); | 2837 ActiveStreamMap::const_iterator it = active_streams_.find(stream_id); |
| 2829 if (it != active_streams_.end()) { | 2838 if (it != active_streams_.end()) { |
| 2830 CHECK_EQ(it->second->stream_id(), stream_id); | 2839 CHECK_EQ(it->second->stream_id(), stream_id); |
| 2831 } else { | 2840 } else { |
| 2832 CHECK_EQ(stream_id, kSessionFlowControlStreamId); | 2841 CHECK_EQ(stream_id, kSessionFlowControlStreamId); |
| 2833 } | 2842 } |
| 2834 | 2843 |
| 2835 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_SENT_WINDOW_UPDATE_FRAME, | 2844 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_SEND_WINDOW_UPDATE, |
| 2836 base::Bind(&NetLogSpdyWindowUpdateFrameCallback, stream_id, | 2845 base::Bind(&NetLogSpdyWindowUpdateFrameCallback, stream_id, |
| 2837 delta_window_size)); | 2846 delta_window_size)); |
| 2838 | 2847 |
| 2839 DCHECK(buffered_spdy_framer_.get()); | 2848 DCHECK(buffered_spdy_framer_.get()); |
| 2840 std::unique_ptr<SpdySerializedFrame> window_update_frame( | 2849 std::unique_ptr<SpdySerializedFrame> window_update_frame( |
| 2841 buffered_spdy_framer_->CreateWindowUpdate(stream_id, delta_window_size)); | 2850 buffered_spdy_framer_->CreateWindowUpdate(stream_id, delta_window_size)); |
| 2842 EnqueueSessionWrite(priority, WINDOW_UPDATE, std::move(window_update_frame)); | 2851 EnqueueSessionWrite(priority, WINDOW_UPDATE, std::move(window_update_frame)); |
| 2843 } | 2852 } |
| 2844 | 2853 |
| 2845 void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { | 2854 void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 if (!queue->empty()) { | 3126 if (!queue->empty()) { |
| 3118 SpdyStreamId stream_id = queue->front(); | 3127 SpdyStreamId stream_id = queue->front(); |
| 3119 queue->pop_front(); | 3128 queue->pop_front(); |
| 3120 return stream_id; | 3129 return stream_id; |
| 3121 } | 3130 } |
| 3122 } | 3131 } |
| 3123 return 0; | 3132 return 0; |
| 3124 } | 3133 } |
| 3125 | 3134 |
| 3126 } // namespace net | 3135 } // namespace net |
| OLD | NEW |