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

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

Issue 275953002: Remove HTTP pipelining support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix line endings Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_response_body_drainer.h ('k') | net/http/http_response_body_drainer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_response_body_drainer.h" 5 #include "net/http/http_response_body_drainer.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/http/http_network_session.h" 11 #include "net/http/http_network_session.h"
12 #include "net/http/http_stream_base.h" 12 #include "net/http/http_stream_base.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStreamBase* stream) 16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStreamBase* stream)
17 : read_size_(0), 17 : stream_(stream),
18 stream_(stream),
19 next_state_(STATE_NONE), 18 next_state_(STATE_NONE),
20 total_read_(0), 19 total_read_(0),
21 session_(NULL) {} 20 session_(NULL) {}
22 21
23 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} 22 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {}
24 23
25 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { 24 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) {
26 StartWithSize(session, kDrainBodyBufferSize); 25 read_buf_ = new IOBuffer(kDrainBodyBufferSize);
27 }
28
29 void HttpResponseBodyDrainer::StartWithSize(HttpNetworkSession* session,
30 int num_bytes_to_drain) {
31 DCHECK_LE(0, num_bytes_to_drain);
32 // TODO(simonjam): Consider raising this limit if we're pipelining. If we have
33 // a bunch of responses in the pipeline, we should be less willing to give up
34 // while draining.
35 if (num_bytes_to_drain > kDrainBodyBufferSize) {
36 Finish(ERR_RESPONSE_BODY_TOO_BIG_TO_DRAIN);
37 return;
38 } else if (num_bytes_to_drain == 0) {
39 Finish(OK);
40 return;
41 }
42
43 read_size_ = num_bytes_to_drain;
44 read_buf_ = new IOBuffer(read_size_);
45 next_state_ = STATE_DRAIN_RESPONSE_BODY; 26 next_state_ = STATE_DRAIN_RESPONSE_BODY;
46 int rv = DoLoop(OK); 27 int rv = DoLoop(OK);
47 28
48 if (rv == ERR_IO_PENDING) { 29 if (rv == ERR_IO_PENDING) {
49 timer_.Start(FROM_HERE, 30 timer_.Start(FROM_HERE,
50 base::TimeDelta::FromSeconds(kTimeoutInSeconds), 31 base::TimeDelta::FromSeconds(kTimeoutInSeconds),
51 this, 32 this,
52 &HttpResponseBodyDrainer::OnTimerFired); 33 &HttpResponseBodyDrainer::OnTimerFired);
53 session_ = session; 34 session_ = session;
54 session->AddResponseDrainer(this); 35 session->AddResponseDrainer(this);
(...skipping 26 matching lines...) Expand all
81 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 62 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
82 63
83 return rv; 64 return rv;
84 } 65 }
85 66
86 int HttpResponseBodyDrainer::DoDrainResponseBody() { 67 int HttpResponseBodyDrainer::DoDrainResponseBody() {
87 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; 68 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE;
88 69
89 return stream_->ReadResponseBody( 70 return stream_->ReadResponseBody(
90 read_buf_.get(), 71 read_buf_.get(),
91 read_size_ - total_read_, 72 kDrainBodyBufferSize - total_read_,
92 base::Bind(&HttpResponseBodyDrainer::OnIOComplete, 73 base::Bind(&HttpResponseBodyDrainer::OnIOComplete,
93 base::Unretained(this))); 74 base::Unretained(this)));
94 } 75 }
95 76
96 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { 77 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) {
97 DCHECK_NE(ERR_IO_PENDING, result); 78 DCHECK_NE(ERR_IO_PENDING, result);
98 79
99 if (result < 0) 80 if (result < 0)
100 return result; 81 return result;
101 82
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 stream_->Close(true /* no keep-alive */); 117 stream_->Close(true /* no keep-alive */);
137 } else { 118 } else {
138 DCHECK_EQ(OK, result); 119 DCHECK_EQ(OK, result);
139 stream_->Close(false /* keep-alive */); 120 stream_->Close(false /* keep-alive */);
140 } 121 }
141 122
142 delete this; 123 delete this;
143 } 124 }
144 125
145 } // namespace net 126 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_response_body_drainer.h ('k') | net/http/http_response_body_drainer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698