| 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/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 GrowableIOBuffer* read_buffer, | 201 GrowableIOBuffer* read_buffer, |
| 202 const BoundNetLog& net_log) | 202 const BoundNetLog& net_log) |
| 203 : io_state_(STATE_NONE), | 203 : io_state_(STATE_NONE), |
| 204 request_(request), | 204 request_(request), |
| 205 request_headers_(NULL), | 205 request_headers_(NULL), |
| 206 request_headers_length_(0), | 206 request_headers_length_(0), |
| 207 read_buf_(read_buffer), | 207 read_buf_(read_buffer), |
| 208 read_buf_unused_offset_(0), | 208 read_buf_unused_offset_(0), |
| 209 response_header_start_offset_(-1), | 209 response_header_start_offset_(-1), |
| 210 received_bytes_(0), | 210 received_bytes_(0), |
| 211 sent_bytes_(0), |
| 211 response_body_length_(-1), | 212 response_body_length_(-1), |
| 212 response_body_read_(0), | 213 response_body_read_(0), |
| 213 user_read_buf_(NULL), | 214 user_read_buf_(NULL), |
| 214 user_read_buf_len_(0), | 215 user_read_buf_len_(0), |
| 215 connection_(connection), | 216 connection_(connection), |
| 216 net_log_(net_log), | 217 net_log_(net_log), |
| 217 sent_last_chunk_(false), | 218 sent_last_chunk_(false), |
| 218 upload_error_(OK), | 219 upload_error_(OK), |
| 219 weak_ptr_factory_(this) { | 220 weak_ptr_factory_(this) { |
| 220 io_callback_ = base::Bind(&HttpStreamParser::OnIOComplete, | 221 io_callback_ = base::Bind(&HttpStreamParser::OnIOComplete, |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // an error that this should try reading after, stash the error for now and | 468 // an error that this should try reading after, stash the error for now and |
| 468 // act like the request was successfully sent. | 469 // act like the request was successfully sent. |
| 469 if (request_headers_->BytesConsumed() >= request_headers_length_ && | 470 if (request_headers_->BytesConsumed() >= request_headers_length_ && |
| 470 ShouldTryReadingOnUploadError(result)) { | 471 ShouldTryReadingOnUploadError(result)) { |
| 471 upload_error_ = result; | 472 upload_error_ = result; |
| 472 return OK; | 473 return OK; |
| 473 } | 474 } |
| 474 return result; | 475 return result; |
| 475 } | 476 } |
| 476 | 477 |
| 478 sent_bytes_ += result; |
| 477 request_headers_->DidConsume(result); | 479 request_headers_->DidConsume(result); |
| 478 if (request_headers_->BytesRemaining() > 0) { | 480 if (request_headers_->BytesRemaining() > 0) { |
| 479 io_state_ = STATE_SEND_HEADERS; | 481 io_state_ = STATE_SEND_HEADERS; |
| 480 return OK; | 482 return OK; |
| 481 } | 483 } |
| 482 | 484 |
| 483 if (request_->upload_data_stream != NULL && | 485 if (request_->upload_data_stream != NULL && |
| 484 (request_->upload_data_stream->is_chunked() || | 486 (request_->upload_data_stream->is_chunked() || |
| 485 // !IsEOF() indicates that the body wasn't merged. | 487 // !IsEOF() indicates that the body wasn't merged. |
| 486 (request_->upload_data_stream->size() > 0 && | 488 (request_->upload_data_stream->size() > 0 && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (result < 0) { | 526 if (result < 0) { |
| 525 // If |result| is an error that this should try reading after, stash the | 527 // If |result| is an error that this should try reading after, stash the |
| 526 // error for now and act like the request was successfully sent. | 528 // error for now and act like the request was successfully sent. |
| 527 if (ShouldTryReadingOnUploadError(result)) { | 529 if (ShouldTryReadingOnUploadError(result)) { |
| 528 upload_error_ = result; | 530 upload_error_ = result; |
| 529 return OK; | 531 return OK; |
| 530 } | 532 } |
| 531 return result; | 533 return result; |
| 532 } | 534 } |
| 533 | 535 |
| 536 sent_bytes_ += result; |
| 534 request_body_send_buf_->DidConsume(result); | 537 request_body_send_buf_->DidConsume(result); |
| 535 | 538 |
| 536 io_state_ = STATE_SEND_BODY; | 539 io_state_ = STATE_SEND_BODY; |
| 537 return OK; | 540 return OK; |
| 538 } | 541 } |
| 539 | 542 |
| 540 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { | 543 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { |
| 541 // |result| is the result of read from the request body from the last call to | 544 // |result| is the result of read from the request body from the last call to |
| 542 // DoSendBody(). | 545 // DoSendBody(). |
| 543 DCHECK_GE(result, 0); // There won't be errors. | 546 DCHECK_GE(result, 0); // There won't be errors. |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 } | 1133 } |
| 1131 | 1134 |
| 1132 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { | 1135 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { |
| 1133 HttpStatusLineValidator::StatusLineStatus status = | 1136 HttpStatusLineValidator::StatusLineStatus status = |
| 1134 HttpStatusLineValidator::ValidateStatusLine(status_line); | 1137 HttpStatusLineValidator::ValidateStatusLine(status_line); |
| 1135 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, | 1138 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, |
| 1136 HttpStatusLineValidator::STATUS_LINE_MAX); | 1139 HttpStatusLineValidator::STATUS_LINE_MAX); |
| 1137 } | 1140 } |
| 1138 | 1141 |
| 1139 } // namespace net | 1142 } // namespace net |
| OLD | NEW |