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

Side by Side Diff: net/quic/quic_http_stream.cc

Issue 23597045: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged QuicPriority to RequestPriority changes Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_http_stream.h ('k') | net/quic/quic_http_stream_test.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/quic/quic_http_stream.h" 5 #include "net/quic/quic_http_stream.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.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_response_headers.h" 11 #include "net/http/http_response_headers.h"
12 #include "net/http/http_util.h" 12 #include "net/http/http_util.h"
13 #include "net/quic/quic_client_session.h" 13 #include "net/quic/quic_client_session.h"
14 #include "net/quic/quic_http_utils.h"
14 #include "net/quic/quic_reliable_client_stream.h" 15 #include "net/quic/quic_reliable_client_stream.h"
15 #include "net/quic/quic_utils.h" 16 #include "net/quic/quic_utils.h"
16 #include "net/socket/next_proto.h" 17 #include "net/socket/next_proto.h"
17 #include "net/spdy/spdy_frame_builder.h" 18 #include "net/spdy/spdy_frame_builder.h"
18 #include "net/spdy/spdy_framer.h" 19 #include "net/spdy/spdy_framer.h"
19 #include "net/spdy/spdy_http_utils.h" 20 #include "net/spdy/spdy_http_utils.h"
20 #include "net/ssl/ssl_info.h" 21 #include "net/ssl/ssl_info.h"
21 22
22 namespace net { 23 namespace net {
23 24
24 static const size_t kHeaderBufInitialSize = 4096; 25 static const size_t kHeaderBufInitialSize = 4096;
25 26
26 QuicHttpStream::QuicHttpStream(const base::WeakPtr<QuicClientSession> session) 27 QuicHttpStream::QuicHttpStream(const base::WeakPtr<QuicClientSession> session)
27 : next_state_(STATE_NONE), 28 : next_state_(STATE_NONE),
28 session_(session), 29 session_(session),
29 stream_(NULL), 30 stream_(NULL),
30 request_info_(NULL), 31 request_info_(NULL),
31 request_body_stream_(NULL), 32 request_body_stream_(NULL),
33 priority_(MINIMUM_PRIORITY),
32 response_info_(NULL), 34 response_info_(NULL),
33 response_status_(OK), 35 response_status_(OK),
34 response_headers_received_(false), 36 response_headers_received_(false),
35 read_buf_(new GrowableIOBuffer()), 37 read_buf_(new GrowableIOBuffer()),
36 user_buffer_len_(0), 38 user_buffer_len_(0),
37 weak_factory_(this) { 39 weak_factory_(this) {
38 DCHECK(session_); 40 DCHECK(session_);
39 } 41 }
40 42
41 QuicHttpStream::~QuicHttpStream() { 43 QuicHttpStream::~QuicHttpStream() {
42 Close(false); 44 Close(false);
43 } 45 }
44 46
45 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info, 47 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info,
46 RequestPriority priority, 48 RequestPriority priority,
47 const BoundNetLog& stream_net_log, 49 const BoundNetLog& stream_net_log,
48 const CompletionCallback& callback) { 50 const CompletionCallback& callback) {
49 DCHECK(!stream_); 51 DCHECK(!stream_);
50 if (!session_) 52 if (!session_)
51 return ERR_CONNECTION_CLOSED; 53 return ERR_CONNECTION_CLOSED;
52 54
53 stream_net_log_ = stream_net_log; 55 stream_net_log_ = stream_net_log;
54 request_info_ = request_info; 56 request_info_ = request_info;
57 priority_ = priority;
55 58
56 int rv = stream_request_.StartRequest( 59 int rv = stream_request_.StartRequest(
57 session_, &stream_, base::Bind(&QuicHttpStream::OnStreamReady, 60 session_, &stream_, base::Bind(&QuicHttpStream::OnStreamReady,
58 weak_factory_.GetWeakPtr())); 61 weak_factory_.GetWeakPtr()));
59 if (rv == ERR_IO_PENDING) 62 if (rv == ERR_IO_PENDING)
60 callback_ = callback; 63 callback_ = callback;
61 64
62 if (rv == OK) 65 if (rv == OK)
63 stream_->SetDelegate(this); 66 stream_->SetDelegate(this);
64 67
(...skipping 10 matching lines...) Expand all
75 78
76 int QuicHttpStream::SendRequest(const HttpRequestHeaders& request_headers, 79 int QuicHttpStream::SendRequest(const HttpRequestHeaders& request_headers,
77 HttpResponseInfo* response, 80 HttpResponseInfo* response,
78 const CompletionCallback& callback) { 81 const CompletionCallback& callback) {
79 CHECK(stream_); 82 CHECK(stream_);
80 CHECK(!request_body_stream_); 83 CHECK(!request_body_stream_);
81 CHECK(!response_info_); 84 CHECK(!response_info_);
82 CHECK(!callback.is_null()); 85 CHECK(!callback.is_null());
83 CHECK(response); 86 CHECK(response);
84 87
88 QuicPriority priority = ConvertRequestPriorityToQuicPriority(priority_);
89 stream_->set_priority(priority);
85 // Store the serialized request headers. 90 // Store the serialized request headers.
86 SpdyHeaderBlock headers; 91 SpdyHeaderBlock headers;
87 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, 92 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers,
88 &headers, 3, /*direct=*/true); 93 &headers, 3, /*direct=*/true);
89 if (session_->connection()->version() < QUIC_VERSION_9) { 94 if (session_->connection()->version() < QUIC_VERSION_9) {
90 request_ = stream_->compressor()->CompressHeaders(headers); 95 request_ = stream_->compressor()->CompressHeaders(headers);
91 } else { 96 } else {
92 request_ = stream_->compressor()->CompressHeadersWithPriority(0, headers); 97 request_ = stream_->compressor()->CompressHeadersWithPriority(priority,
98 headers);
93 } 99 }
94 // Log the actual request with the URL Request's net log. 100 // Log the actual request with the URL Request's net log.
95 stream_net_log_.AddEvent( 101 stream_net_log_.AddEvent(
96 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS, 102 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS,
97 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); 103 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers));
98 // Also log to the QuicSession's net log. 104 // Also log to the QuicSession's net log.
99 stream_->net_log().AddEvent( 105 stream_->net_log().AddEvent(
100 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, 106 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS,
101 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); 107 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers));
102 108
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 user_buffer_len_ = buf_len; 206 user_buffer_len_ = buf_len;
201 return ERR_IO_PENDING; 207 return ERR_IO_PENDING;
202 } 208 }
203 209
204 void QuicHttpStream::Close(bool not_reusable) { 210 void QuicHttpStream::Close(bool not_reusable) {
205 // Note: the not_reusable flag has no meaning for SPDY streams. 211 // Note: the not_reusable flag has no meaning for SPDY streams.
206 if (stream_) { 212 if (stream_) {
207 stream_->SetDelegate(NULL); 213 stream_->SetDelegate(NULL);
208 // TODO(rch): use new CANCELLED error code here once quic 11 214 // TODO(rch): use new CANCELLED error code here once quic 11
209 // is everywhere. 215 // is everywhere.
210 stream_->Close(QUIC_SERVER_ERROR_PROCESSING_STREAM); 216 stream_->Close(QUIC_ERROR_PROCESSING_STREAM);
211 stream_ = NULL; 217 stream_ = NULL;
212 } 218 }
213 } 219 }
214 220
215 HttpStream* QuicHttpStream::RenewStreamForAuth() { 221 HttpStream* QuicHttpStream::RenewStreamForAuth() {
216 return NULL; 222 return NULL;
217 } 223 }
218 224
219 bool QuicHttpStream::IsResponseBodyComplete() const { 225 bool QuicHttpStream::IsResponseBodyComplete() const {
220 return next_state_ == STATE_OPEN && !stream_; 226 return next_state_ == STATE_OPEN && !stream_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 bool QuicHttpStream::IsSpdyHttpStream() const { 263 bool QuicHttpStream::IsSpdyHttpStream() const {
258 return false; 264 return false;
259 } 265 }
260 266
261 void QuicHttpStream::Drain(HttpNetworkSession* session) { 267 void QuicHttpStream::Drain(HttpNetworkSession* session) {
262 Close(false); 268 Close(false);
263 delete this; 269 delete this;
264 } 270 }
265 271
266 void QuicHttpStream::SetPriority(RequestPriority priority) { 272 void QuicHttpStream::SetPriority(RequestPriority priority) {
267 // Nothing to do here (yet). 273 priority_ = priority;
268 } 274 }
269 275
270 int QuicHttpStream::OnSendData() { 276 int QuicHttpStream::OnSendData() {
271 // TODO(rch): Change QUIC IO to provide notifications to the streams. 277 // TODO(rch): Change QUIC IO to provide notifications to the streams.
272 NOTREACHED(); 278 NOTREACHED();
273 return OK; 279 return OK;
274 } 280 }
275 281
276 int QuicHttpStream::OnSendDataComplete(int status, bool* eof) { 282 int QuicHttpStream::OnSendDataComplete(int status, bool* eof) {
277 // TODO(rch): Change QUIC IO to provide notifications to the streams. 283 // TODO(rch): Change QUIC IO to provide notifications to the streams.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 DoCallback(response_status_); 335 DoCallback(response_status_);
330 } 336 }
331 337
332 void QuicHttpStream::OnError(int error) { 338 void QuicHttpStream::OnError(int error) {
333 stream_ = NULL; 339 stream_ = NULL;
334 response_status_ = error; 340 response_status_ = error;
335 if (!callback_.is_null()) 341 if (!callback_.is_null())
336 DoCallback(response_status_); 342 DoCallback(response_status_);
337 } 343 }
338 344
345 bool QuicHttpStream::HasSendHeadersComplete() {
346 return next_state_ > STATE_SEND_HEADERS_COMPLETE;
347 }
348
339 void QuicHttpStream::OnIOComplete(int rv) { 349 void QuicHttpStream::OnIOComplete(int rv) {
340 rv = DoLoop(rv); 350 rv = DoLoop(rv);
341 351
342 if (rv != ERR_IO_PENDING && !callback_.is_null()) { 352 if (rv != ERR_IO_PENDING && !callback_.is_null()) {
343 DoCallback(rv); 353 DoCallback(rv);
344 } 354 }
345 } 355 }
346 356
347 void QuicHttpStream::DoCallback(int rv) { 357 void QuicHttpStream::DoCallback(int rv) {
348 CHECK_NE(rv, ERR_IO_PENDING); 358 CHECK_NE(rv, ERR_IO_PENDING);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 526
517 void QuicHttpStream::BufferResponseBody(const char* data, int length) { 527 void QuicHttpStream::BufferResponseBody(const char* data, int length) {
518 if (length == 0) 528 if (length == 0)
519 return; 529 return;
520 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); 530 IOBufferWithSize* io_buffer = new IOBufferWithSize(length);
521 memcpy(io_buffer->data(), data, length); 531 memcpy(io_buffer->data(), data, length);
522 response_body_.push_back(make_scoped_refptr(io_buffer)); 532 response_body_.push_back(make_scoped_refptr(io_buffer));
523 } 533 }
524 534
525 } // namespace net 535 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_http_stream.h ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698