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 <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 const int kReadBufferSize = 8 * 1024; | 53 const int kReadBufferSize = 8 * 1024; |
54 const int kDefaultConnectionAtRiskOfLossSeconds = 10; | 54 const int kDefaultConnectionAtRiskOfLossSeconds = 10; |
55 const int kHungIntervalSeconds = 10; | 55 const int kHungIntervalSeconds = 10; |
56 | 56 |
57 // Minimum seconds that unclaimed pushed streams will be kept in memory. | 57 // Minimum seconds that unclaimed pushed streams will be kept in memory. |
58 const int kMinPushedStreamLifetimeSeconds = 300; | 58 const int kMinPushedStreamLifetimeSeconds = 300; |
59 | 59 |
60 scoped_ptr<base::ListValue> SpdyHeaderBlockToListValue( | 60 scoped_ptr<base::ListValue> SpdyHeaderBlockToListValue( |
61 const SpdyHeaderBlock& headers, | 61 const SpdyHeaderBlock& headers, |
62 net::NetLog::LogLevel log_level) { | 62 net::NetLogCaptureMode capture_mode) { |
63 scoped_ptr<base::ListValue> headers_list(new base::ListValue()); | 63 scoped_ptr<base::ListValue> headers_list(new base::ListValue()); |
64 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 64 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
65 it != headers.end(); ++it) { | 65 it != headers.end(); ++it) { |
66 headers_list->AppendString( | 66 headers_list->AppendString( |
67 it->first + ": " + | 67 it->first + ": " + |
68 ElideHeaderValueForNetLog(log_level, it->first, it->second)); | 68 ElideHeaderValueForNetLog(capture_mode, it->first, it->second)); |
69 } | 69 } |
70 return headers_list.Pass(); | 70 return headers_list.Pass(); |
71 } | 71 } |
72 | 72 |
73 base::Value* NetLogSpdySynStreamSentCallback(const SpdyHeaderBlock* headers, | 73 base::Value* NetLogSpdySynStreamSentCallback(const SpdyHeaderBlock* headers, |
74 bool fin, | 74 bool fin, |
75 bool unidirectional, | 75 bool unidirectional, |
76 SpdyPriority spdy_priority, | 76 SpdyPriority spdy_priority, |
77 SpdyStreamId stream_id, | 77 SpdyStreamId stream_id, |
78 NetLog::LogLevel log_level) { | 78 NetLogCaptureMode capture_mode) { |
79 base::DictionaryValue* dict = new base::DictionaryValue(); | 79 base::DictionaryValue* dict = new base::DictionaryValue(); |
80 dict->Set("headers", | 80 dict->Set("headers", |
81 SpdyHeaderBlockToListValue(*headers, log_level).release()); | 81 SpdyHeaderBlockToListValue(*headers, capture_mode).release()); |
82 dict->SetBoolean("fin", fin); | 82 dict->SetBoolean("fin", fin); |
83 dict->SetBoolean("unidirectional", unidirectional); | 83 dict->SetBoolean("unidirectional", unidirectional); |
84 dict->SetInteger("priority", static_cast<int>(spdy_priority)); | 84 dict->SetInteger("priority", static_cast<int>(spdy_priority)); |
85 dict->SetInteger("stream_id", stream_id); | 85 dict->SetInteger("stream_id", stream_id); |
86 return dict; | 86 return dict; |
87 } | 87 } |
88 | 88 |
89 base::Value* NetLogSpdySynStreamReceivedCallback( | 89 base::Value* NetLogSpdySynStreamReceivedCallback( |
90 const SpdyHeaderBlock* headers, | 90 const SpdyHeaderBlock* headers, |
91 bool fin, | 91 bool fin, |
92 bool unidirectional, | 92 bool unidirectional, |
93 SpdyPriority spdy_priority, | 93 SpdyPriority spdy_priority, |
94 SpdyStreamId stream_id, | 94 SpdyStreamId stream_id, |
95 SpdyStreamId associated_stream, | 95 SpdyStreamId associated_stream, |
96 NetLog::LogLevel log_level) { | 96 NetLogCaptureMode capture_mode) { |
97 base::DictionaryValue* dict = new base::DictionaryValue(); | 97 base::DictionaryValue* dict = new base::DictionaryValue(); |
98 dict->Set("headers", | 98 dict->Set("headers", |
99 SpdyHeaderBlockToListValue(*headers, log_level).release()); | 99 SpdyHeaderBlockToListValue(*headers, capture_mode).release()); |
100 dict->SetBoolean("fin", fin); | 100 dict->SetBoolean("fin", fin); |
101 dict->SetBoolean("unidirectional", unidirectional); | 101 dict->SetBoolean("unidirectional", unidirectional); |
102 dict->SetInteger("priority", static_cast<int>(spdy_priority)); | 102 dict->SetInteger("priority", static_cast<int>(spdy_priority)); |
103 dict->SetInteger("stream_id", stream_id); | 103 dict->SetInteger("stream_id", stream_id); |
104 dict->SetInteger("associated_stream", associated_stream); | 104 dict->SetInteger("associated_stream", associated_stream); |
105 return dict; | 105 return dict; |
106 } | 106 } |
107 | 107 |
108 base::Value* NetLogSpdySynReplyOrHeadersReceivedCallback( | 108 base::Value* NetLogSpdySynReplyOrHeadersReceivedCallback( |
109 const SpdyHeaderBlock* headers, | 109 const SpdyHeaderBlock* headers, |
110 bool fin, | 110 bool fin, |
111 SpdyStreamId stream_id, | 111 SpdyStreamId stream_id, |
112 NetLog::LogLevel log_level) { | 112 NetLogCaptureMode capture_mode) { |
113 base::DictionaryValue* dict = new base::DictionaryValue(); | 113 base::DictionaryValue* dict = new base::DictionaryValue(); |
114 dict->Set("headers", | 114 dict->Set("headers", |
115 SpdyHeaderBlockToListValue(*headers, log_level).release()); | 115 SpdyHeaderBlockToListValue(*headers, capture_mode).release()); |
116 dict->SetBoolean("fin", fin); | 116 dict->SetBoolean("fin", fin); |
117 dict->SetInteger("stream_id", stream_id); | 117 dict->SetInteger("stream_id", stream_id); |
118 return dict; | 118 return dict; |
119 } | 119 } |
120 | 120 |
121 base::Value* NetLogSpdySessionCloseCallback(int net_error, | 121 base::Value* NetLogSpdySessionCloseCallback( |
122 const std::string* description, | 122 int net_error, |
123 NetLog::LogLevel /* log_level */) { | 123 const std::string* description, |
| 124 NetLogCaptureMode /* capture_mode */) { |
124 base::DictionaryValue* dict = new base::DictionaryValue(); | 125 base::DictionaryValue* dict = new base::DictionaryValue(); |
125 dict->SetInteger("net_error", net_error); | 126 dict->SetInteger("net_error", net_error); |
126 dict->SetString("description", *description); | 127 dict->SetString("description", *description); |
127 return dict; | 128 return dict; |
128 } | 129 } |
129 | 130 |
130 base::Value* NetLogSpdySessionCallback(const HostPortProxyPair* host_pair, | 131 base::Value* NetLogSpdySessionCallback(const HostPortProxyPair* host_pair, |
131 NetLog::LogLevel /* log_level */) { | 132 NetLogCaptureMode /* capture_mode */) { |
132 base::DictionaryValue* dict = new base::DictionaryValue(); | 133 base::DictionaryValue* dict = new base::DictionaryValue(); |
133 dict->SetString("host", host_pair->first.ToString()); | 134 dict->SetString("host", host_pair->first.ToString()); |
134 dict->SetString("proxy", host_pair->second.ToPacString()); | 135 dict->SetString("proxy", host_pair->second.ToPacString()); |
135 return dict; | 136 return dict; |
136 } | 137 } |
137 | 138 |
138 base::Value* NetLogSpdyInitializedCallback(NetLog::Source source, | 139 base::Value* NetLogSpdyInitializedCallback( |
139 const NextProto protocol_version, | 140 NetLog::Source source, |
140 NetLog::LogLevel /* log_level */) { | 141 const NextProto protocol_version, |
| 142 NetLogCaptureMode /* capture_mode */) { |
141 base::DictionaryValue* dict = new base::DictionaryValue(); | 143 base::DictionaryValue* dict = new base::DictionaryValue(); |
142 if (source.IsValid()) { | 144 if (source.IsValid()) { |
143 source.AddToEventParameters(dict); | 145 source.AddToEventParameters(dict); |
144 } | 146 } |
145 dict->SetString("protocol", | 147 dict->SetString("protocol", |
146 SSLClientSocket::NextProtoToString(protocol_version)); | 148 SSLClientSocket::NextProtoToString(protocol_version)); |
147 return dict; | 149 return dict; |
148 } | 150 } |
149 | 151 |
150 base::Value* NetLogSpdySettingsCallback(const HostPortPair& host_port_pair, | 152 base::Value* NetLogSpdySettingsCallback(const HostPortPair& host_port_pair, |
151 bool clear_persisted, | 153 bool clear_persisted, |
152 NetLog::LogLevel /* log_level */) { | 154 NetLogCaptureMode /* capture_mode */) { |
153 base::DictionaryValue* dict = new base::DictionaryValue(); | 155 base::DictionaryValue* dict = new base::DictionaryValue(); |
154 dict->SetString("host", host_port_pair.ToString()); | 156 dict->SetString("host", host_port_pair.ToString()); |
155 dict->SetBoolean("clear_persisted", clear_persisted); | 157 dict->SetBoolean("clear_persisted", clear_persisted); |
156 return dict; | 158 return dict; |
157 } | 159 } |
158 | 160 |
159 base::Value* NetLogSpdySettingCallback(SpdySettingsIds id, | 161 base::Value* NetLogSpdySettingCallback(SpdySettingsIds id, |
160 const SpdyMajorVersion protocol_version, | 162 const SpdyMajorVersion protocol_version, |
161 SpdySettingsFlags flags, | 163 SpdySettingsFlags flags, |
162 uint32 value, | 164 uint32 value, |
163 NetLog::LogLevel /* log_level */) { | 165 NetLogCaptureMode /* capture_mode */) { |
164 base::DictionaryValue* dict = new base::DictionaryValue(); | 166 base::DictionaryValue* dict = new base::DictionaryValue(); |
165 dict->SetInteger("id", | 167 dict->SetInteger("id", |
166 SpdyConstants::SerializeSettingId(protocol_version, id)); | 168 SpdyConstants::SerializeSettingId(protocol_version, id)); |
167 dict->SetInteger("flags", flags); | 169 dict->SetInteger("flags", flags); |
168 dict->SetInteger("value", value); | 170 dict->SetInteger("value", value); |
169 return dict; | 171 return dict; |
170 } | 172 } |
171 | 173 |
172 base::Value* NetLogSpdySendSettingsCallback( | 174 base::Value* NetLogSpdySendSettingsCallback( |
173 const SettingsMap* settings, | 175 const SettingsMap* settings, |
174 const SpdyMajorVersion protocol_version, | 176 const SpdyMajorVersion protocol_version, |
175 NetLog::LogLevel /* log_level */) { | 177 NetLogCaptureMode /* capture_mode */) { |
176 base::DictionaryValue* dict = new base::DictionaryValue(); | 178 base::DictionaryValue* dict = new base::DictionaryValue(); |
177 base::ListValue* settings_list = new base::ListValue(); | 179 base::ListValue* settings_list = new base::ListValue(); |
178 for (SettingsMap::const_iterator it = settings->begin(); | 180 for (SettingsMap::const_iterator it = settings->begin(); |
179 it != settings->end(); ++it) { | 181 it != settings->end(); ++it) { |
180 const SpdySettingsIds id = it->first; | 182 const SpdySettingsIds id = it->first; |
181 const SpdySettingsFlags flags = it->second.first; | 183 const SpdySettingsFlags flags = it->second.first; |
182 const uint32 value = it->second.second; | 184 const uint32 value = it->second.second; |
183 settings_list->Append(new base::StringValue(base::StringPrintf( | 185 settings_list->Append(new base::StringValue(base::StringPrintf( |
184 "[id:%u flags:%u value:%u]", | 186 "[id:%u flags:%u value:%u]", |
185 SpdyConstants::SerializeSettingId(protocol_version, id), | 187 SpdyConstants::SerializeSettingId(protocol_version, id), |
186 flags, | 188 flags, |
187 value))); | 189 value))); |
188 } | 190 } |
189 dict->Set("settings", settings_list); | 191 dict->Set("settings", settings_list); |
190 return dict; | 192 return dict; |
191 } | 193 } |
192 | 194 |
193 base::Value* NetLogSpdyWindowUpdateFrameCallback( | 195 base::Value* NetLogSpdyWindowUpdateFrameCallback( |
194 SpdyStreamId stream_id, | 196 SpdyStreamId stream_id, |
195 uint32 delta, | 197 uint32 delta, |
196 NetLog::LogLevel /* log_level */) { | 198 NetLogCaptureMode /* capture_mode */) { |
197 base::DictionaryValue* dict = new base::DictionaryValue(); | 199 base::DictionaryValue* dict = new base::DictionaryValue(); |
198 dict->SetInteger("stream_id", static_cast<int>(stream_id)); | 200 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
199 dict->SetInteger("delta", delta); | 201 dict->SetInteger("delta", delta); |
200 return dict; | 202 return dict; |
201 } | 203 } |
202 | 204 |
203 base::Value* NetLogSpdySessionWindowUpdateCallback( | 205 base::Value* NetLogSpdySessionWindowUpdateCallback( |
204 int32 delta, | 206 int32 delta, |
205 int32 window_size, | 207 int32 window_size, |
206 NetLog::LogLevel /* log_level */) { | 208 NetLogCaptureMode /* capture_mode */) { |
207 base::DictionaryValue* dict = new base::DictionaryValue(); | 209 base::DictionaryValue* dict = new base::DictionaryValue(); |
208 dict->SetInteger("delta", delta); | 210 dict->SetInteger("delta", delta); |
209 dict->SetInteger("window_size", window_size); | 211 dict->SetInteger("window_size", window_size); |
210 return dict; | 212 return dict; |
211 } | 213 } |
212 | 214 |
213 base::Value* NetLogSpdyDataCallback(SpdyStreamId stream_id, | 215 base::Value* NetLogSpdyDataCallback(SpdyStreamId stream_id, |
214 int size, | 216 int size, |
215 bool fin, | 217 bool fin, |
216 NetLog::LogLevel /* log_level */) { | 218 NetLogCaptureMode /* capture_mode */) { |
217 base::DictionaryValue* dict = new base::DictionaryValue(); | 219 base::DictionaryValue* dict = new base::DictionaryValue(); |
218 dict->SetInteger("stream_id", static_cast<int>(stream_id)); | 220 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
219 dict->SetInteger("size", size); | 221 dict->SetInteger("size", size); |
220 dict->SetBoolean("fin", fin); | 222 dict->SetBoolean("fin", fin); |
221 return dict; | 223 return dict; |
222 } | 224 } |
223 | 225 |
224 base::Value* NetLogSpdyRstCallback(SpdyStreamId stream_id, | 226 base::Value* NetLogSpdyRstCallback(SpdyStreamId stream_id, |
225 int status, | 227 int status, |
226 const std::string* description, | 228 const std::string* description, |
227 NetLog::LogLevel /* log_level */) { | 229 NetLogCaptureMode /* capture_mode */) { |
228 base::DictionaryValue* dict = new base::DictionaryValue(); | 230 base::DictionaryValue* dict = new base::DictionaryValue(); |
229 dict->SetInteger("stream_id", static_cast<int>(stream_id)); | 231 dict->SetInteger("stream_id", static_cast<int>(stream_id)); |
230 dict->SetInteger("status", status); | 232 dict->SetInteger("status", status); |
231 dict->SetString("description", *description); | 233 dict->SetString("description", *description); |
232 return dict; | 234 return dict; |
233 } | 235 } |
234 | 236 |
235 base::Value* NetLogSpdyPingCallback(SpdyPingId unique_id, | 237 base::Value* NetLogSpdyPingCallback(SpdyPingId unique_id, |
236 bool is_ack, | 238 bool is_ack, |
237 const char* type, | 239 const char* type, |
238 NetLog::LogLevel /* log_level */) { | 240 NetLogCaptureMode /* capture_mode */) { |
239 base::DictionaryValue* dict = new base::DictionaryValue(); | 241 base::DictionaryValue* dict = new base::DictionaryValue(); |
240 dict->SetInteger("unique_id", static_cast<int>(unique_id)); | 242 dict->SetInteger("unique_id", static_cast<int>(unique_id)); |
241 dict->SetString("type", type); | 243 dict->SetString("type", type); |
242 dict->SetBoolean("is_ack", is_ack); | 244 dict->SetBoolean("is_ack", is_ack); |
243 return dict; | 245 return dict; |
244 } | 246 } |
245 | 247 |
246 base::Value* NetLogSpdyGoAwayCallback(SpdyStreamId last_stream_id, | 248 base::Value* NetLogSpdyGoAwayCallback(SpdyStreamId last_stream_id, |
247 int active_streams, | 249 int active_streams, |
248 int unclaimed_streams, | 250 int unclaimed_streams, |
249 SpdyGoAwayStatus status, | 251 SpdyGoAwayStatus status, |
250 NetLog::LogLevel /* log_level */) { | 252 NetLogCaptureMode /* capture_mode */) { |
251 base::DictionaryValue* dict = new base::DictionaryValue(); | 253 base::DictionaryValue* dict = new base::DictionaryValue(); |
252 dict->SetInteger("last_accepted_stream_id", | 254 dict->SetInteger("last_accepted_stream_id", |
253 static_cast<int>(last_stream_id)); | 255 static_cast<int>(last_stream_id)); |
254 dict->SetInteger("active_streams", active_streams); | 256 dict->SetInteger("active_streams", active_streams); |
255 dict->SetInteger("unclaimed_streams", unclaimed_streams); | 257 dict->SetInteger("unclaimed_streams", unclaimed_streams); |
256 dict->SetInteger("status", static_cast<int>(status)); | 258 dict->SetInteger("status", static_cast<int>(status)); |
257 return dict; | 259 return dict; |
258 } | 260 } |
259 | 261 |
260 base::Value* NetLogSpdyPushPromiseReceivedCallback( | 262 base::Value* NetLogSpdyPushPromiseReceivedCallback( |
261 const SpdyHeaderBlock* headers, | 263 const SpdyHeaderBlock* headers, |
262 SpdyStreamId stream_id, | 264 SpdyStreamId stream_id, |
263 SpdyStreamId promised_stream_id, | 265 SpdyStreamId promised_stream_id, |
264 NetLog::LogLevel log_level) { | 266 NetLogCaptureMode capture_mode) { |
265 base::DictionaryValue* dict = new base::DictionaryValue(); | 267 base::DictionaryValue* dict = new base::DictionaryValue(); |
266 dict->Set("headers", | 268 dict->Set("headers", |
267 SpdyHeaderBlockToListValue(*headers, log_level).release()); | 269 SpdyHeaderBlockToListValue(*headers, capture_mode).release()); |
268 dict->SetInteger("id", stream_id); | 270 dict->SetInteger("id", stream_id); |
269 dict->SetInteger("promised_stream_id", promised_stream_id); | 271 dict->SetInteger("promised_stream_id", promised_stream_id); |
270 return dict; | 272 return dict; |
271 } | 273 } |
272 | 274 |
273 base::Value* NetLogSpdyAdoptedPushStreamCallback( | 275 base::Value* NetLogSpdyAdoptedPushStreamCallback( |
274 SpdyStreamId stream_id, const GURL* url, NetLog::LogLevel log_level) { | 276 SpdyStreamId stream_id, |
| 277 const GURL* url, |
| 278 NetLogCaptureMode capture_mode) { |
275 base::DictionaryValue* dict = new base::DictionaryValue(); | 279 base::DictionaryValue* dict = new base::DictionaryValue(); |
276 dict->SetInteger("stream_id", stream_id); | 280 dict->SetInteger("stream_id", stream_id); |
277 dict->SetString("url", url->spec()); | 281 dict->SetString("url", url->spec()); |
278 return dict; | 282 return dict; |
279 } | 283 } |
280 | 284 |
281 // Helper function to return the total size of an array of objects | 285 // Helper function to return the total size of an array of objects |
282 // with .size() member functions. | 286 // with .size() member functions. |
283 template <typename T, size_t N> size_t GetTotalSize(const T (&arr)[N]) { | 287 template <typename T, size_t N> size_t GetTotalSize(const T (&arr)[N]) { |
284 size_t total_size = 0; | 288 size_t total_size = 0; |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 SpdyHeadersIR headers(stream_id); | 1075 SpdyHeadersIR headers(stream_id); |
1072 headers.set_priority(spdy_priority); | 1076 headers.set_priority(spdy_priority); |
1073 headers.set_has_priority(true); | 1077 headers.set_has_priority(true); |
1074 headers.set_fin((flags & CONTROL_FLAG_FIN) != 0); | 1078 headers.set_fin((flags & CONTROL_FLAG_FIN) != 0); |
1075 headers.set_name_value_block(block); | 1079 headers.set_name_value_block(block); |
1076 syn_frame.reset(buffered_spdy_framer_->SerializeFrame(headers)); | 1080 syn_frame.reset(buffered_spdy_framer_->SerializeFrame(headers)); |
1077 } | 1081 } |
1078 | 1082 |
1079 streams_initiated_count_++; | 1083 streams_initiated_count_++; |
1080 | 1084 |
1081 if (net_log().IsLogging()) { | 1085 if (net_log().GetCaptureMode().enabled()) { |
1082 const NetLog::EventType type = | 1086 const NetLog::EventType type = |
1083 (GetProtocolVersion() <= SPDY3) | 1087 (GetProtocolVersion() <= SPDY3) |
1084 ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM | 1088 ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM |
1085 : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; | 1089 : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; |
1086 net_log().AddEvent(type, | 1090 net_log().AddEvent(type, |
1087 base::Bind(&NetLogSpdySynStreamSentCallback, &block, | 1091 base::Bind(&NetLogSpdySynStreamSentCallback, &block, |
1088 (flags & CONTROL_FLAG_FIN) != 0, | 1092 (flags & CONTROL_FLAG_FIN) != 0, |
1089 (flags & CONTROL_FLAG_UNIDIRECTIONAL) != 0, | 1093 (flags & CONTROL_FLAG_UNIDIRECTIONAL) != 0, |
1090 spdy_priority, stream_id)); | 1094 spdy_priority, stream_id)); |
1091 } | 1095 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 effective_len = std::min(effective_len, session_send_window_size_); | 1185 effective_len = std::min(effective_len, session_send_window_size_); |
1182 } | 1186 } |
1183 | 1187 |
1184 DCHECK_GE(effective_len, 0); | 1188 DCHECK_GE(effective_len, 0); |
1185 | 1189 |
1186 // Clear FIN flag if only some of the data will be in the data | 1190 // Clear FIN flag if only some of the data will be in the data |
1187 // frame. | 1191 // frame. |
1188 if (effective_len < len) | 1192 if (effective_len < len) |
1189 flags = static_cast<SpdyDataFlags>(flags & ~DATA_FLAG_FIN); | 1193 flags = static_cast<SpdyDataFlags>(flags & ~DATA_FLAG_FIN); |
1190 | 1194 |
1191 if (net_log().IsLogging()) { | 1195 if (net_log().GetCaptureMode().enabled()) { |
1192 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SEND_DATA, | 1196 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SEND_DATA, |
1193 base::Bind(&NetLogSpdyDataCallback, stream_id, | 1197 base::Bind(&NetLogSpdyDataCallback, stream_id, |
1194 effective_len, (flags & DATA_FLAG_FIN) != 0)); | 1198 effective_len, (flags & DATA_FLAG_FIN) != 0)); |
1195 } | 1199 } |
1196 | 1200 |
1197 // Send PrefacePing for DATA_FRAMEs with nonzero payload size. | 1201 // Send PrefacePing for DATA_FRAMEs with nonzero payload size. |
1198 if (effective_len > 0) | 1202 if (effective_len > 0) |
1199 SendPrefacePingIfNoneInFlight(); | 1203 SendPrefacePingIfNoneInFlight(); |
1200 | 1204 |
1201 // TODO(mbelshe): reduce memory copies here. | 1205 // TODO(mbelshe): reduce memory copies here. |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 size_t header_len = buffered_spdy_framer_->GetDataFrameMinimumSize(); | 2039 size_t header_len = buffered_spdy_framer_->GetDataFrameMinimumSize(); |
2036 stream->IncrementRawReceivedBytes(header_len); | 2040 stream->IncrementRawReceivedBytes(header_len); |
2037 } | 2041 } |
2038 | 2042 |
2039 void SpdySession::OnStreamFrameData(SpdyStreamId stream_id, | 2043 void SpdySession::OnStreamFrameData(SpdyStreamId stream_id, |
2040 const char* data, | 2044 const char* data, |
2041 size_t len, | 2045 size_t len, |
2042 bool fin) { | 2046 bool fin) { |
2043 CHECK(in_io_loop_); | 2047 CHECK(in_io_loop_); |
2044 DCHECK_LT(len, 1u << 24); | 2048 DCHECK_LT(len, 1u << 24); |
2045 if (net_log().IsLogging()) { | 2049 if (net_log().GetCaptureMode().enabled()) { |
2046 net_log().AddEvent( | 2050 net_log().AddEvent( |
2047 NetLog::TYPE_HTTP2_SESSION_RECV_DATA, | 2051 NetLog::TYPE_HTTP2_SESSION_RECV_DATA, |
2048 base::Bind(&NetLogSpdyDataCallback, stream_id, len, fin)); | 2052 base::Bind(&NetLogSpdyDataCallback, stream_id, len, fin)); |
2049 } | 2053 } |
2050 | 2054 |
2051 // Build the buffer as early as possible so that we go through the | 2055 // Build the buffer as early as possible so that we go through the |
2052 // session flow control checks and update | 2056 // session flow control checks and update |
2053 // |unacked_recv_window_bytes_| properly even when the stream is | 2057 // |unacked_recv_window_bytes_| properly even when the stream is |
2054 // inactive (since the other side has still reduced its session send | 2058 // inactive (since the other side has still reduced its session send |
2055 // window). | 2059 // window). |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 return; | 2112 return; |
2109 it->second.stream->OnPaddingConsumed(len); | 2113 it->second.stream->OnPaddingConsumed(len); |
2110 } | 2114 } |
2111 | 2115 |
2112 void SpdySession::OnSettings(bool clear_persisted) { | 2116 void SpdySession::OnSettings(bool clear_persisted) { |
2113 CHECK(in_io_loop_); | 2117 CHECK(in_io_loop_); |
2114 | 2118 |
2115 if (clear_persisted) | 2119 if (clear_persisted) |
2116 http_server_properties_->ClearSpdySettings(host_port_pair()); | 2120 http_server_properties_->ClearSpdySettings(host_port_pair()); |
2117 | 2121 |
2118 if (net_log_.IsLogging()) { | 2122 if (net_log_.GetCaptureMode().enabled()) { |
2119 net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_SETTINGS, | 2123 net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_SETTINGS, |
2120 base::Bind(&NetLogSpdySettingsCallback, host_port_pair(), | 2124 base::Bind(&NetLogSpdySettingsCallback, host_port_pair(), |
2121 clear_persisted)); | 2125 clear_persisted)); |
2122 } | 2126 } |
2123 | 2127 |
2124 if (GetProtocolVersion() >= SPDY4) { | 2128 if (GetProtocolVersion() >= SPDY4) { |
2125 // Send an acknowledgment of the setting. | 2129 // Send an acknowledgment of the setting. |
2126 SpdySettingsIR settings_ir; | 2130 SpdySettingsIR settings_ir; |
2127 settings_ir.set_is_ack(true); | 2131 settings_ir.set_is_ack(true); |
2128 EnqueueSessionWrite( | 2132 EnqueueSessionWrite( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 bool fin, | 2225 bool fin, |
2222 bool unidirectional, | 2226 bool unidirectional, |
2223 const SpdyHeaderBlock& headers) { | 2227 const SpdyHeaderBlock& headers) { |
2224 CHECK(in_io_loop_); | 2228 CHECK(in_io_loop_); |
2225 | 2229 |
2226 DCHECK_LE(GetProtocolVersion(), SPDY3); | 2230 DCHECK_LE(GetProtocolVersion(), SPDY3); |
2227 | 2231 |
2228 base::Time response_time = base::Time::Now(); | 2232 base::Time response_time = base::Time::Now(); |
2229 base::TimeTicks recv_first_byte_time = time_func_(); | 2233 base::TimeTicks recv_first_byte_time = time_func_(); |
2230 | 2234 |
2231 if (net_log_.IsLogging()) { | 2235 if (net_log_.GetCaptureMode().enabled()) { |
2232 net_log_.AddEvent( | 2236 net_log_.AddEvent( |
2233 NetLog::TYPE_HTTP2_SESSION_PUSHED_SYN_STREAM, | 2237 NetLog::TYPE_HTTP2_SESSION_PUSHED_SYN_STREAM, |
2234 base::Bind(&NetLogSpdySynStreamReceivedCallback, &headers, fin, | 2238 base::Bind(&NetLogSpdySynStreamReceivedCallback, &headers, fin, |
2235 unidirectional, priority, stream_id, associated_stream_id)); | 2239 unidirectional, priority, stream_id, associated_stream_id)); |
2236 } | 2240 } |
2237 | 2241 |
2238 // Split headers to simulate push promise and response. | 2242 // Split headers to simulate push promise and response. |
2239 SpdyHeaderBlock request_headers; | 2243 SpdyHeaderBlock request_headers; |
2240 SpdyHeaderBlock response_headers; | 2244 SpdyHeaderBlock response_headers; |
2241 SplitPushedHeadersToRequestAndResponse( | 2245 SplitPushedHeadersToRequestAndResponse( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 } | 2297 } |
2294 | 2298 |
2295 void SpdySession::OnSynReply(SpdyStreamId stream_id, | 2299 void SpdySession::OnSynReply(SpdyStreamId stream_id, |
2296 bool fin, | 2300 bool fin, |
2297 const SpdyHeaderBlock& headers) { | 2301 const SpdyHeaderBlock& headers) { |
2298 CHECK(in_io_loop_); | 2302 CHECK(in_io_loop_); |
2299 | 2303 |
2300 base::Time response_time = base::Time::Now(); | 2304 base::Time response_time = base::Time::Now(); |
2301 base::TimeTicks recv_first_byte_time = time_func_(); | 2305 base::TimeTicks recv_first_byte_time = time_func_(); |
2302 | 2306 |
2303 if (net_log().IsLogging()) { | 2307 if (net_log().GetCaptureMode().enabled()) { |
2304 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SYN_REPLY, | 2308 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SYN_REPLY, |
2305 base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, | 2309 base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, |
2306 &headers, fin, stream_id)); | 2310 &headers, fin, stream_id)); |
2307 } | 2311 } |
2308 | 2312 |
2309 ActiveStreamMap::iterator it = active_streams_.find(stream_id); | 2313 ActiveStreamMap::iterator it = active_streams_.find(stream_id); |
2310 if (it == active_streams_.end()) { | 2314 if (it == active_streams_.end()) { |
2311 // NOTE: it may just be that the stream was cancelled. | 2315 // NOTE: it may just be that the stream was cancelled. |
2312 return; | 2316 return; |
2313 } | 2317 } |
(...skipping 24 matching lines...) Expand all Loading... |
2338 headers, response_time, recv_first_byte_time, stream)); | 2342 headers, response_time, recv_first_byte_time, stream)); |
2339 } | 2343 } |
2340 | 2344 |
2341 void SpdySession::OnHeaders(SpdyStreamId stream_id, | 2345 void SpdySession::OnHeaders(SpdyStreamId stream_id, |
2342 bool has_priority, | 2346 bool has_priority, |
2343 SpdyPriority priority, | 2347 SpdyPriority priority, |
2344 bool fin, | 2348 bool fin, |
2345 const SpdyHeaderBlock& headers) { | 2349 const SpdyHeaderBlock& headers) { |
2346 CHECK(in_io_loop_); | 2350 CHECK(in_io_loop_); |
2347 | 2351 |
2348 if (net_log().IsLogging()) { | 2352 if (net_log().GetCaptureMode().enabled()) { |
2349 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_HEADERS, | 2353 net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_HEADERS, |
2350 base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, | 2354 base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, |
2351 &headers, fin, stream_id)); | 2355 &headers, fin, stream_id)); |
2352 } | 2356 } |
2353 | 2357 |
2354 ActiveStreamMap::iterator it = active_streams_.find(stream_id); | 2358 ActiveStreamMap::iterator it = active_streams_.find(stream_id); |
2355 if (it == active_streams_.end()) { | 2359 if (it == active_streams_.end()) { |
2356 // NOTE: it may just be that the stream was cancelled. | 2360 // NOTE: it may just be that the stream was cancelled. |
2357 LOG(WARNING) << "Received HEADERS for invalid stream " << stream_id; | 2361 LOG(WARNING) << "Received HEADERS for invalid stream " << stream_id; |
2358 return; | 2362 return; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2721 DCHECK(active_it->second.stream->IsReservedRemote()); | 2725 DCHECK(active_it->second.stream->IsReservedRemote()); |
2722 num_pushed_streams_++; | 2726 num_pushed_streams_++; |
2723 return true; | 2727 return true; |
2724 } | 2728 } |
2725 | 2729 |
2726 void SpdySession::OnPushPromise(SpdyStreamId stream_id, | 2730 void SpdySession::OnPushPromise(SpdyStreamId stream_id, |
2727 SpdyStreamId promised_stream_id, | 2731 SpdyStreamId promised_stream_id, |
2728 const SpdyHeaderBlock& headers) { | 2732 const SpdyHeaderBlock& headers) { |
2729 CHECK(in_io_loop_); | 2733 CHECK(in_io_loop_); |
2730 | 2734 |
2731 if (net_log_.IsLogging()) { | 2735 if (net_log_.GetCaptureMode().enabled()) { |
2732 net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_PUSH_PROMISE, | 2736 net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_PUSH_PROMISE, |
2733 base::Bind(&NetLogSpdyPushPromiseReceivedCallback, | 2737 base::Bind(&NetLogSpdyPushPromiseReceivedCallback, |
2734 &headers, stream_id, promised_stream_id)); | 2738 &headers, stream_id, promised_stream_id)); |
2735 } | 2739 } |
2736 | 2740 |
2737 // Any priority will do. | 2741 // Any priority will do. |
2738 // TODO(baranovich): pass parent stream id priority? | 2742 // TODO(baranovich): pass parent stream id priority? |
2739 if (!TryCreatePushStream(promised_stream_id, stream_id, 0, headers)) | 2743 if (!TryCreatePushStream(promised_stream_id, stream_id, 0, headers)) |
2740 return; | 2744 return; |
2741 } | 2745 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2915 buffered_spdy_framer_->CreateWindowUpdate(stream_id, delta_window_size)); | 2919 buffered_spdy_framer_->CreateWindowUpdate(stream_id, delta_window_size)); |
2916 EnqueueSessionWrite(priority, WINDOW_UPDATE, window_update_frame.Pass()); | 2920 EnqueueSessionWrite(priority, WINDOW_UPDATE, window_update_frame.Pass()); |
2917 } | 2921 } |
2918 | 2922 |
2919 void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { | 2923 void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { |
2920 DCHECK(buffered_spdy_framer_.get()); | 2924 DCHECK(buffered_spdy_framer_.get()); |
2921 scoped_ptr<SpdyFrame> ping_frame( | 2925 scoped_ptr<SpdyFrame> ping_frame( |
2922 buffered_spdy_framer_->CreatePingFrame(unique_id, is_ack)); | 2926 buffered_spdy_framer_->CreatePingFrame(unique_id, is_ack)); |
2923 EnqueueSessionWrite(HIGHEST, PING, ping_frame.Pass()); | 2927 EnqueueSessionWrite(HIGHEST, PING, ping_frame.Pass()); |
2924 | 2928 |
2925 if (net_log().IsLogging()) { | 2929 if (net_log().GetCaptureMode().enabled()) { |
2926 net_log().AddEvent( | 2930 net_log().AddEvent( |
2927 NetLog::TYPE_HTTP2_SESSION_PING, | 2931 NetLog::TYPE_HTTP2_SESSION_PING, |
2928 base::Bind(&NetLogSpdyPingCallback, unique_id, is_ack, "sent")); | 2932 base::Bind(&NetLogSpdyPingCallback, unique_id, is_ack, "sent")); |
2929 } | 2933 } |
2930 if (!is_ack) { | 2934 if (!is_ack) { |
2931 next_ping_id_ += 2; | 2935 next_ping_id_ += 2; |
2932 ++pings_in_flight_; | 2936 ++pings_in_flight_; |
2933 PlanToCheckPingStatus(); | 2937 PlanToCheckPingStatus(); |
2934 last_ping_sent_time_ = time_func_(); | 2938 last_ping_sent_time_ = time_func_(); |
2935 } | 2939 } |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3263 if (!queue->empty()) { | 3267 if (!queue->empty()) { |
3264 SpdyStreamId stream_id = queue->front(); | 3268 SpdyStreamId stream_id = queue->front(); |
3265 queue->pop_front(); | 3269 queue->pop_front(); |
3266 return stream_id; | 3270 return stream_id; |
3267 } | 3271 } |
3268 } | 3272 } |
3269 return 0; | 3273 return 0; |
3270 } | 3274 } |
3271 | 3275 |
3272 } // namespace net | 3276 } // namespace net |
OLD | NEW |