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

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

Issue 8591037: Implement Drain() on HttpPipelinedStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Skip on unusable Created 9 years 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) 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_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.h" 12 #include "net/http/http_stream.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream) 16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream)
17 : stream_(stream), 17 : stream_(stream),
18 next_state_(STATE_NONE), 18 next_state_(STATE_NONE),
19 total_read_(0), 19 total_read_(0),
20 ALLOW_THIS_IN_INITIALIZER_LIST( 20 ALLOW_THIS_IN_INITIALIZER_LIST(
21 io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)), 21 io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)),
22 user_callback_(NULL), 22 user_callback_(NULL),
23 session_(NULL) {} 23 session_(NULL) {}
24 24
25 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} 25 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {}
26 26
27 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { 27 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) {
28 read_buf_ = new IOBuffer(kDrainBodyBufferSize); 28 StartWithSize(session, kDrainBodyBufferSize);
29 }
30
31 void HttpResponseBodyDrainer::StartWithSize(HttpNetworkSession* session,
32 int num_bytes_to_drain) {
33 DCHECK_LE(0, num_bytes_to_drain);
34 // TODO(simonjam): Consider raising this limit if we're pipelining. If we have
35 // a bunch of responses in the pipeline, we should be less willing to give up
36 // while draining.
37 if (num_bytes_to_drain > kDrainBodyBufferSize) {
38 Finish(ERR_RESPONSE_BODY_TOO_BIG_TO_DRAIN);
39 return;
40 } else if (num_bytes_to_drain == 0) {
41 Finish(OK);
42 return;
43 }
44
45 read_size_ = num_bytes_to_drain;
46 read_buf_ = new IOBuffer(read_size_);
29 next_state_ = STATE_DRAIN_RESPONSE_BODY; 47 next_state_ = STATE_DRAIN_RESPONSE_BODY;
30 int rv = DoLoop(OK); 48 int rv = DoLoop(OK);
31 49
32 if (rv == ERR_IO_PENDING) { 50 if (rv == ERR_IO_PENDING) {
33 timer_.Start(FROM_HERE, 51 timer_.Start(FROM_HERE,
34 base::TimeDelta::FromSeconds(kTimeoutInSeconds), 52 base::TimeDelta::FromSeconds(kTimeoutInSeconds),
35 this, 53 this,
36 &HttpResponseBodyDrainer::OnTimerFired); 54 &HttpResponseBodyDrainer::OnTimerFired);
37 session_ = session; 55 session_ = session;
38 session->AddResponseDrainer(this); 56 session->AddResponseDrainer(this);
(...skipping 25 matching lines...) Expand all
64 } 82 }
65 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); 83 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE);
66 84
67 return rv; 85 return rv;
68 } 86 }
69 87
70 int HttpResponseBodyDrainer::DoDrainResponseBody() { 88 int HttpResponseBodyDrainer::DoDrainResponseBody() {
71 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; 89 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE;
72 90
73 return stream_->ReadResponseBody( 91 return stream_->ReadResponseBody(
74 read_buf_, kDrainBodyBufferSize - total_read_, 92 read_buf_, read_size_ - total_read_,
75 &io_callback_); 93 &io_callback_);
76 } 94 }
77 95
78 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { 96 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) {
79 DCHECK_NE(ERR_IO_PENDING, result); 97 DCHECK_NE(ERR_IO_PENDING, result);
80 98
81 if (result < 0) 99 if (result < 0)
82 return result; 100 return result;
83 101
84 if (result == 0) 102 if (result == 0)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 stream_->Close(true /* no keep-alive */); 136 stream_->Close(true /* no keep-alive */);
119 } else { 137 } else {
120 DCHECK_EQ(OK, result); 138 DCHECK_EQ(OK, result);
121 stream_->Close(false /* keep-alive */); 139 stream_->Close(false /* keep-alive */);
122 } 140 }
123 141
124 delete this; 142 delete this;
125 } 143 }
126 144
127 } // namespace net 145 } // 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