OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/http/http_request_info.h" | 9 #include "net/http/http_request_info.h" |
10 #include "net/http/http_response_info.h" | 10 #include "net/http/http_response_info.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return ERR_IO_PENDING; | 144 return ERR_IO_PENDING; |
145 } | 145 } |
146 | 146 |
147 int SpdyStream::SendRequest(UploadDataStream* upload_data, | 147 int SpdyStream::SendRequest(UploadDataStream* upload_data, |
148 HttpResponseInfo* response, | 148 HttpResponseInfo* response, |
149 CompletionCallback* callback) { | 149 CompletionCallback* callback) { |
150 CHECK(callback); | 150 CHECK(callback); |
151 CHECK(!cancelled_); | 151 CHECK(!cancelled_); |
152 CHECK(response); | 152 CHECK(response); |
153 | 153 |
154 DLOG(INFO) << " * " << __FUNCTION__ << "()"; | |
155 | |
156 if (response_) { | 154 if (response_) { |
157 *response = *response_; | 155 *response = *response_; |
158 delete response_; | 156 delete response_; |
159 } | 157 } |
160 response_ = response; | 158 response_ = response; |
161 | 159 |
162 if (upload_data) { | 160 if (upload_data) { |
163 if (upload_data->size()) | 161 if (upload_data->size()) |
164 request_body_stream_.reset(upload_data); | 162 request_body_stream_.reset(upload_data); |
165 else | 163 else |
(...skipping 21 matching lines...) Expand all Loading... |
187 } | 185 } |
188 | 186 |
189 void SpdyStream::Cancel() { | 187 void SpdyStream::Cancel() { |
190 cancelled_ = true; | 188 cancelled_ = true; |
191 user_callback_ = NULL; | 189 user_callback_ = NULL; |
192 | 190 |
193 session_->CancelStream(stream_id_); | 191 session_->CancelStream(stream_id_); |
194 } | 192 } |
195 | 193 |
196 void SpdyStream::OnResponseReceived(const HttpResponseInfo& response) { | 194 void SpdyStream::OnResponseReceived(const HttpResponseInfo& response) { |
197 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
198 metrics_.StartStream(); | 195 metrics_.StartStream(); |
199 | 196 |
200 CHECK(!response_->headers); | 197 CHECK(!response_->headers); |
201 | 198 |
202 *response_ = response; // TODO(mbelshe): avoid copy. | 199 *response_ = response; // TODO(mbelshe): avoid copy. |
203 DCHECK(response_->headers); | 200 DCHECK(response_->headers); |
204 | 201 |
205 recv_first_byte_time_ = base::TimeTicks::Now(); | 202 recv_first_byte_time_ = base::TimeTicks::Now(); |
206 | 203 |
207 if (io_state_ == STATE_NONE) { | 204 if (io_state_ == STATE_NONE) { |
(...skipping 11 matching lines...) Expand all Loading... |
219 NOTREACHED(); | 216 NOTREACHED(); |
220 } | 217 } |
221 | 218 |
222 int rv = DoLoop(OK); | 219 int rv = DoLoop(OK); |
223 | 220 |
224 if (user_callback_) | 221 if (user_callback_) |
225 DoCallback(rv); | 222 DoCallback(rv); |
226 } | 223 } |
227 | 224 |
228 bool SpdyStream::OnDataReceived(const char* data, int length) { | 225 bool SpdyStream::OnDataReceived(const char* data, int length) { |
229 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
230 DCHECK_GE(length, 0); | 226 DCHECK_GE(length, 0); |
231 LOG(INFO) << "SpdyStream: Data (" << length << " bytes) received for " | 227 LOG(INFO) << "SpdyStream: Data (" << length << " bytes) received for " |
232 << stream_id_; | 228 << stream_id_; |
233 | 229 |
234 CHECK(!response_complete_); | 230 CHECK(!response_complete_); |
235 | 231 |
236 // If we don't have a response, then the SYN_REPLY did not come through. | 232 // If we don't have a response, then the SYN_REPLY did not come through. |
237 // We cannot pass data up to the caller unless the reply headers have been | 233 // We cannot pass data up to the caller unless the reply headers have been |
238 // received. | 234 // received. |
239 if (!response_->headers) { | 235 if (!response_->headers) { |
(...skipping 30 matching lines...) Expand all Loading... |
270 if (user_buffer_) { | 266 if (user_buffer_) { |
271 // Handing small chunks of data to the caller creates measurable overhead. | 267 // Handing small chunks of data to the caller creates measurable overhead. |
272 // We buffer data in short time-spans and send a single read notification. | 268 // We buffer data in short time-spans and send a single read notification. |
273 ScheduleBufferedReadCallback(); | 269 ScheduleBufferedReadCallback(); |
274 } | 270 } |
275 | 271 |
276 return true; | 272 return true; |
277 } | 273 } |
278 | 274 |
279 void SpdyStream::OnWriteComplete(int status) { | 275 void SpdyStream::OnWriteComplete(int status) { |
280 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
281 // TODO(mbelshe): Check for cancellation here. If we're cancelled, we | 276 // TODO(mbelshe): Check for cancellation here. If we're cancelled, we |
282 // should discontinue the DoLoop. | 277 // should discontinue the DoLoop. |
283 | 278 |
284 if (status > 0) | 279 if (status > 0) |
285 send_bytes_ += status; | 280 send_bytes_ += status; |
286 | 281 |
287 DoLoop(status); | 282 DoLoop(status); |
288 } | 283 } |
289 | 284 |
290 void SpdyStream::OnClose(int status) { | 285 void SpdyStream::OnClose(int status) { |
291 DLOG(INFO) << " >> " << __FUNCTION__ << "()"; | |
292 response_complete_ = true; | 286 response_complete_ = true; |
293 response_status_ = status; | 287 response_status_ = status; |
294 stream_id_ = 0; | 288 stream_id_ = 0; |
295 | 289 |
296 if (user_callback_) | 290 if (user_callback_) |
297 DoCallback(status); | 291 DoCallback(status); |
298 | 292 |
299 UpdateHistograms(); | 293 UpdateHistograms(); |
300 } | 294 } |
301 | 295 |
302 int SpdyStream::DoLoop(int result) { | 296 int SpdyStream::DoLoop(int result) { |
303 do { | 297 do { |
304 DLOG(INFO) << " * " << __FUNCTION__ << "() state = " << io_state_ | |
305 << " result = " << result; | |
306 State state = io_state_; | 298 State state = io_state_; |
307 io_state_ = STATE_NONE; | 299 io_state_ = STATE_NONE; |
308 switch (state) { | 300 switch (state) { |
309 // State machine 1: Send headers and wait for response headers. | 301 // State machine 1: Send headers and wait for response headers. |
310 case STATE_SEND_HEADERS: | 302 case STATE_SEND_HEADERS: |
311 CHECK_EQ(OK, result); | 303 CHECK_EQ(OK, result); |
312 net_log_.BeginEvent(NetLog::TYPE_SPDY_STREAM_SEND_HEADERS); | 304 net_log_.BeginEvent(NetLog::TYPE_SPDY_STREAM_SEND_HEADERS); |
313 result = DoSendHeaders(); | 305 result = DoSendHeaders(); |
314 break; | 306 break; |
315 case STATE_SEND_HEADERS_COMPLETE: | 307 case STATE_SEND_HEADERS_COMPLETE: |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", | 514 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", |
523 recv_last_byte_time_ - recv_first_byte_time_); | 515 recv_last_byte_time_ - recv_first_byte_time_); |
524 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", | 516 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", |
525 recv_last_byte_time_ - send_time_); | 517 recv_last_byte_time_ - send_time_); |
526 | 518 |
527 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); | 519 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); |
528 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 520 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
529 } | 521 } |
530 | 522 |
531 } // namespace net | 523 } // namespace net |
OLD | NEW |