| 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/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
| 9 #include "base/trace_event.h" | 9 #include "base/trace_event.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 io_state_ = STATE_READ_HEADERS_COMPLETE; | 84 io_state_ = STATE_READ_HEADERS_COMPLETE; |
| 85 | 85 |
| 86 result = DoLoop(result); | 86 result = DoLoop(result); |
| 87 if (result == ERR_IO_PENDING) | 87 if (result == ERR_IO_PENDING) |
| 88 user_callback_ = callback; | 88 user_callback_ = callback; |
| 89 | 89 |
| 90 return result > 0 ? OK : result; | 90 return result > 0 ? OK : result; |
| 91 } | 91 } |
| 92 | 92 |
| 93 int HttpStreamParser::ReadResponseBody(IOBuffer* buf, int buf_len, | 93 int HttpStreamParser::ReadResponseBody(IOBuffer* buf, int buf_len, |
| 94 CompletionCallback* callback) { | 94 CompletionCallback* callback) { |
| 95 DCHECK(io_state_ == STATE_BODY_PENDING || io_state_ == STATE_DONE); | 95 DCHECK(io_state_ == STATE_BODY_PENDING || io_state_ == STATE_DONE); |
| 96 DCHECK(!user_callback_); | 96 DCHECK(!user_callback_); |
| 97 DCHECK(callback); | 97 DCHECK(callback); |
| 98 DCHECK_LE(buf_len, kMaxBufSize); | 98 DCHECK_LE(buf_len, kMaxBufSize); |
| 99 | 99 |
| 100 if (io_state_ == STATE_DONE) | 100 if (io_state_ == STATE_DONE) |
| 101 return OK; | 101 return OK; |
| 102 | 102 |
| 103 user_read_buf_ = buf; | 103 user_read_buf_ = buf; |
| 104 user_read_buf_len_ = buf_len; | 104 user_read_buf_len_ = buf_len; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // and otherwise we'll use an enum to tell why it won't help. | 197 // and otherwise we'll use an enum to tell why it won't help. |
| 198 enum COALESCE_POTENTIAL { | 198 enum COALESCE_POTENTIAL { |
| 199 NO_ADVANTAGE = 0, // Coalescing won't reduce packet count. | 199 NO_ADVANTAGE = 0, // Coalescing won't reduce packet count. |
| 200 HEADER_ONLY = 1, // There is only a header packet (can't coalesce). | 200 HEADER_ONLY = 1, // There is only a header packet (can't coalesce). |
| 201 COALESCE_POTENTIAL_MAX = 30 // Various cases of coalasced savings. | 201 COALESCE_POTENTIAL_MAX = 30 // Various cases of coalasced savings. |
| 202 }; | 202 }; |
| 203 size_t coalesce = HEADER_ONLY; | 203 size_t coalesce = HEADER_ONLY; |
| 204 if (request_body_ != NULL) { | 204 if (request_body_ != NULL) { |
| 205 const size_t kBytesPerPacket = 1430; | 205 const size_t kBytesPerPacket = 1430; |
| 206 uint64 body_packets = (request_body_->size() + kBytesPerPacket - 1) / | 206 uint64 body_packets = (request_body_->size() + kBytesPerPacket - 1) / |
| 207 kBytesPerPacket; | 207 kBytesPerPacket; |
| 208 uint64 header_packets = (bytes_remaining + kBytesPerPacket - 1) / | 208 uint64 header_packets = (bytes_remaining + kBytesPerPacket - 1) / |
| 209 kBytesPerPacket; | 209 kBytesPerPacket; |
| 210 uint64 coalesced_packets = (request_body_->size() + bytes_remaining + | 210 uint64 coalesced_packets = (request_body_->size() + bytes_remaining + |
| 211 kBytesPerPacket - 1) / kBytesPerPacket; | 211 kBytesPerPacket - 1) / kBytesPerPacket; |
| 212 if (coalesced_packets < header_packets + body_packets) { | 212 if (coalesced_packets < header_packets + body_packets) { |
| 213 if (coalesced_packets > COALESCE_POTENTIAL_MAX) | 213 if (coalesced_packets > COALESCE_POTENTIAL_MAX) |
| 214 coalesce = COALESCE_POTENTIAL_MAX; | 214 coalesce = COALESCE_POTENTIAL_MAX; |
| 215 else | 215 else |
| 216 coalesce = static_cast<size_t>(header_packets + body_packets); | 216 coalesce = static_cast<size_t>(header_packets + body_packets); |
| 217 } else { | 217 } else { |
| 218 coalesce = NO_ADVANTAGE; | 218 coalesce = NO_ADVANTAGE; |
| 219 } | 219 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 557 |
| 558 bool HttpStreamParser::CanFindEndOfResponse() const { | 558 bool HttpStreamParser::CanFindEndOfResponse() const { |
| 559 return chunked_decoder_.get() || response_body_length_ >= 0; | 559 return chunked_decoder_.get() || response_body_length_ >= 0; |
| 560 } | 560 } |
| 561 | 561 |
| 562 bool HttpStreamParser::IsMoreDataBuffered() const { | 562 bool HttpStreamParser::IsMoreDataBuffered() const { |
| 563 return read_buf_->offset() > read_buf_unused_offset_; | 563 return read_buf_->offset() > read_buf_unused_offset_; |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace net | 566 } // namespace net |
| OLD | NEW |