Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: net/http/http_stream_parser.cc

Issue 2298823002: Resetting the HttpRequestInfo pointers in HttpNetworkTransaction and streams (Closed)
Patch Set: Rebased, removed upload progress plumbing, feedback. (Rebased till refs/heads/master@{#417381}) Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // Added to investigate crbug.com/499663. 373 // Added to investigate crbug.com/499663.
374 CHECK(buf); 374 CHECK(buf);
375 375
376 if (io_state_ == STATE_DONE) 376 if (io_state_ == STATE_DONE)
377 return OK; 377 return OK;
378 378
379 user_read_buf_ = buf; 379 user_read_buf_ = buf;
380 user_read_buf_len_ = buf_len; 380 user_read_buf_len_ = buf_len;
381 io_state_ = STATE_READ_BODY; 381 io_state_ = STATE_READ_BODY;
382 382
383 // Invalidate HttpRequestInfo pointer. This is to allow the stream to be
384 // shared across multiple consumers which might require this
385 // stream to outlive the consumer that initially created it.
Randy Smith (Not in Mondays) 2016/09/09 17:28:24 nit, suggestion: Similarly to before, emphasize th
shivanisha 2016/09/13 19:58:34 done.
386 if (request_)
387 ResetRequestInfo();
388
383 int result = DoLoop(OK); 389 int result = DoLoop(OK);
384 if (result == ERR_IO_PENDING) 390 if (result == ERR_IO_PENDING)
385 callback_ = callback; 391 callback_ = callback;
386 392
387 return result; 393 return result;
388 } 394 }
389 395
390 void HttpStreamParser::OnIOComplete(int result) { 396 void HttpStreamParser::OnIOComplete(int result) {
391 result = DoLoop(result); 397 result = DoLoop(result);
392 398
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 if (response_->headers->IsChunkEncoded()) { 1100 if (response_->headers->IsChunkEncoded()) {
1095 chunked_decoder_.reset(new HttpChunkedDecoder()); 1101 chunked_decoder_.reset(new HttpChunkedDecoder());
1096 } else { 1102 } else {
1097 response_body_length_ = response_->headers->GetContentLength(); 1103 response_body_length_ = response_->headers->GetContentLength();
1098 // If response_body_length_ is still -1, then we have to wait 1104 // If response_body_length_ is still -1, then we have to wait
1099 // for the server to close the connection. 1105 // for the server to close the connection.
1100 } 1106 }
1101 } 1107 }
1102 } 1108 }
1103 1109
1104 UploadProgress HttpStreamParser::GetUploadProgress() const {
1105 if (!request_->upload_data_stream)
1106 return UploadProgress();
1107
1108 return UploadProgress(request_->upload_data_stream->position(),
1109 request_->upload_data_stream->size());
1110 }
1111
1112 bool HttpStreamParser::IsResponseBodyComplete() const { 1110 bool HttpStreamParser::IsResponseBodyComplete() const {
1113 if (chunked_decoder_.get()) 1111 if (chunked_decoder_.get())
1114 return chunked_decoder_->reached_eof(); 1112 return chunked_decoder_->reached_eof();
1115 if (response_body_length_ != -1) 1113 if (response_body_length_ != -1)
1116 return response_body_read_ >= response_body_length_; 1114 return response_body_read_ >= response_body_length_;
1117 1115
1118 return false; // Must read to EOF. 1116 return false; // Must read to EOF.
1119 } 1117 }
1120 1118
1121 bool HttpStreamParser::CanFindEndOfResponse() const { 1119 bool HttpStreamParser::CanFindEndOfResponse() const {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 HttpStatusLineValidator::ValidateStatusLine(status_line); 1226 HttpStatusLineValidator::ValidateStatusLine(status_line);
1229 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, 1227 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status,
1230 HttpStatusLineValidator::STATUS_LINE_MAX); 1228 HttpStatusLineValidator::STATUS_LINE_MAX);
1231 } 1229 }
1232 1230
1233 bool HttpStreamParser::SendRequestBuffersEmpty() { 1231 bool HttpStreamParser::SendRequestBuffersEmpty() {
1234 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && 1232 return request_headers_ == nullptr && request_body_send_buf_ == nullptr &&
1235 request_body_send_buf_ == nullptr; 1233 request_body_send_buf_ == nullptr;
1236 } 1234 }
1237 1235
1236 void HttpStreamParser::ResetRequestInfo() {
1237 // Only allowed when Read state machine starts. It is safe to reset it at this
1238 // point since request_->upload_data_stream is also not needed anymore.
1239 DCHECK_EQ(STATE_READ_BODY, io_state_);
Randy Smith (Not in Mondays) 2016/09/09 17:28:24 nit, suggestion: Same as before, I'm not sure if t
shivanisha 2016/09/13 19:58:34 done.
1240
1241 request_ = nullptr;
1242 }
1243
1238 } // namespace net 1244 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698