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

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

Issue 2298823002: Resetting the HttpRequestInfo pointers in HttpNetworkTransaction and streams (Closed)
Patch Set: Initial patch 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 HttpCache::Transactions which might require this
385 // stream to outlive the request_'s owner URLRequestHttpJob.
Randy Smith (Not in Mondays) 2016/09/01 20:18:31 As noted elsewhere, I'm really uncomfortable with
shivanisha 2016/09/08 20:43:54 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 chunked_decoder_.reset(new HttpChunkedDecoder()); 1089 chunked_decoder_.reset(new HttpChunkedDecoder());
1084 } else { 1090 } else {
1085 response_body_length_ = response_->headers->GetContentLength(); 1091 response_body_length_ = response_->headers->GetContentLength();
1086 // If response_body_length_ is still -1, then we have to wait 1092 // If response_body_length_ is still -1, then we have to wait
1087 // for the server to close the connection. 1093 // for the server to close the connection.
1088 } 1094 }
1089 } 1095 }
1090 } 1096 }
1091 1097
1092 UploadProgress HttpStreamParser::GetUploadProgress() const { 1098 UploadProgress HttpStreamParser::GetUploadProgress() const {
1099 if (!request_)
1100 return upload_progress_;
1101
1093 if (!request_->upload_data_stream) 1102 if (!request_->upload_data_stream)
1094 return UploadProgress(); 1103 return UploadProgress();
1095 1104
1096 return UploadProgress(request_->upload_data_stream->position(), 1105 return UploadProgress(request_->upload_data_stream->position(),
1097 request_->upload_data_stream->size()); 1106 request_->upload_data_stream->size());
1098 } 1107 }
1099 1108
1100 bool HttpStreamParser::IsResponseBodyComplete() const { 1109 bool HttpStreamParser::IsResponseBodyComplete() const {
1101 if (chunked_decoder_.get()) 1110 if (chunked_decoder_.get())
1102 return chunked_decoder_->reached_eof(); 1111 return chunked_decoder_->reached_eof();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 HttpStatusLineValidator::ValidateStatusLine(status_line); 1225 HttpStatusLineValidator::ValidateStatusLine(status_line);
1217 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, 1226 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status,
1218 HttpStatusLineValidator::STATUS_LINE_MAX); 1227 HttpStatusLineValidator::STATUS_LINE_MAX);
1219 } 1228 }
1220 1229
1221 bool HttpStreamParser::SendRequestBuffersEmpty() { 1230 bool HttpStreamParser::SendRequestBuffersEmpty() {
1222 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && 1231 return request_headers_ == nullptr && request_body_send_buf_ == nullptr &&
1223 request_body_send_buf_ == nullptr; 1232 request_body_send_buf_ == nullptr;
1224 } 1233 }
1225 1234
1235 void HttpStreamParser::ResetRequestInfo() {
1236 // Only allowed when Read state machine starts. It is safe to reset it at this
1237 // point since request_->upload_data_stream is also not needed anymore.
1238 DCHECK_EQ(STATE_READ_BODY, io_state_);
1239
1240 // save upload progress if any.
1241 upload_progress_ = GetUploadProgress();
1242 request_ = nullptr;
1243 }
1244
1226 } // namespace net 1245 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698