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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 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/quic/quic_connection_helper.cc ('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/stringprintf.h" 8 #include "base/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"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Store the request body. 82 // Store the request body.
83 request_body_stream_ = request_info_->upload_data_stream; 83 request_body_stream_ = request_info_->upload_data_stream;
84 if (request_body_stream_ && (request_body_stream_->size() || 84 if (request_body_stream_ && (request_body_stream_->size() ||
85 request_body_stream_->is_chunked())) { 85 request_body_stream_->is_chunked())) {
86 // Use kMaxPacketSize as the buffer size, since the request 86 // Use kMaxPacketSize as the buffer size, since the request
87 // body data is written with this size at a time. 87 // body data is written with this size at a time.
88 // TODO(rch): use a smarter value since we can't write an entire 88 // TODO(rch): use a smarter value since we can't write an entire
89 // packet due to overhead. 89 // packet due to overhead.
90 raw_request_body_buf_ = new IOBufferWithSize(kMaxPacketSize); 90 raw_request_body_buf_ = new IOBufferWithSize(kMaxPacketSize);
91 // The request body buffer is empty at first. 91 // The request body buffer is empty at first.
92 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_, 0); 92 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), 0);
93 } 93 }
94 94
95 // Store the response info. 95 // Store the response info.
96 response_info_ = response; 96 response_info_ = response;
97 97
98 next_state_ = STATE_SEND_HEADERS; 98 next_state_ = STATE_SEND_HEADERS;
99 int rv = DoLoop(OK); 99 int rv = DoLoop(OK);
100 if (rv == ERR_IO_PENDING) 100 if (rv == ERR_IO_PENDING)
101 callback_ = callback; 101 callback_ = callback;
102 102
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 return bytes_read; 160 return bytes_read;
161 } 161 }
162 162
163 if (!stream_) { 163 if (!stream_) {
164 // If the stream is already closed, there is no body to read. 164 // If the stream is already closed, there is no body to read.
165 return response_status_; 165 return response_status_;
166 } 166 }
167 167
168 CHECK(callback_.is_null()); 168 CHECK(callback_.is_null());
169 CHECK(!user_buffer_); 169 CHECK(!user_buffer_.get());
170 CHECK_EQ(0, user_buffer_len_); 170 CHECK_EQ(0, user_buffer_len_);
171 171
172 callback_ = callback; 172 callback_ = callback;
173 user_buffer_ = buf; 173 user_buffer_ = buf;
174 user_buffer_len_ = buf_len; 174 user_buffer_len_ = buf_len;
175 return ERR_IO_PENDING; 175 return ERR_IO_PENDING;
176 } 176 }
177 177
178 void QuicHttpStream::Close(bool not_reusable) { 178 void QuicHttpStream::Close(bool not_reusable) {
179 // Note: the not_reusable flag has no meaning for SPDY streams. 179 // Note: the not_reusable flag has no meaning for SPDY streams.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return rv; 372 return rv;
373 373
374 next_state_ = request_body_stream_ ? 374 next_state_ = request_body_stream_ ?
375 STATE_READ_REQUEST_BODY : STATE_OPEN; 375 STATE_READ_REQUEST_BODY : STATE_OPEN;
376 376
377 return OK; 377 return OK;
378 } 378 }
379 379
380 int QuicHttpStream::DoReadRequestBody() { 380 int QuicHttpStream::DoReadRequestBody() {
381 next_state_ = STATE_READ_REQUEST_BODY_COMPLETE; 381 next_state_ = STATE_READ_REQUEST_BODY_COMPLETE;
382 return request_body_stream_->Read(raw_request_body_buf_, 382 return request_body_stream_->Read(
383 raw_request_body_buf_->size(), 383 raw_request_body_buf_.get(),
384 base::Bind(&QuicHttpStream::OnIOComplete, 384 raw_request_body_buf_->size(),
385 weak_factory_.GetWeakPtr())); 385 base::Bind(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr()));
386 } 386 }
387 387
388 int QuicHttpStream::DoReadRequestBodyComplete(int rv) { 388 int QuicHttpStream::DoReadRequestBodyComplete(int rv) {
389 // |rv| is the result of read from the request body from the last call to 389 // |rv| is the result of read from the request body from the last call to
390 // DoSendBody(). 390 // DoSendBody().
391 if (rv < 0) 391 if (rv < 0)
392 return rv; 392 return rv;
393 393
394 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_, rv); 394 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), rv);
395 if (rv == 0) { // Reached the end. 395 if (rv == 0) { // Reached the end.
396 DCHECK(request_body_stream_->IsEOF()); 396 DCHECK(request_body_stream_->IsEOF());
397 } 397 }
398 398
399 next_state_ = STATE_SEND_BODY; 399 next_state_ = STATE_SEND_BODY;
400 return OK; 400 return OK;
401 } 401 }
402 402
403 int QuicHttpStream::DoSendBody() { 403 int QuicHttpStream::DoSendBody() {
404 if (!stream_) 404 if (!stream_)
405 return ERR_UNEXPECTED; 405 return ERR_UNEXPECTED;
406 406
407 CHECK(request_body_stream_); 407 CHECK(request_body_stream_);
408 CHECK(request_body_buf_); 408 CHECK(request_body_buf_.get());
409 const bool eof = request_body_stream_->IsEOF(); 409 const bool eof = request_body_stream_->IsEOF();
410 int len = request_body_buf_->BytesRemaining(); 410 int len = request_body_buf_->BytesRemaining();
411 if (len > 0 || eof) { 411 if (len > 0 || eof) {
412 base::StringPiece data(request_body_buf_->data(), len); 412 base::StringPiece data(request_body_buf_->data(), len);
413 QuicConsumedData rv = stream_->WriteData(data, eof); 413 QuicConsumedData rv = stream_->WriteData(data, eof);
414 request_body_buf_->DidConsume(rv.bytes_consumed); 414 request_body_buf_->DidConsume(rv.bytes_consumed);
415 if (eof) { 415 if (eof) {
416 next_state_ = STATE_OPEN; 416 next_state_ = STATE_OPEN;
417 return OK; 417 return OK;
418 } 418 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 458
459 if (!SpdyHeadersToHttpResponse(headers, 3, response_info_)) { 459 if (!SpdyHeadersToHttpResponse(headers, 3, response_info_)) {
460 DLOG(WARNING) << "Invalid headers"; 460 DLOG(WARNING) << "Invalid headers";
461 return ERR_QUIC_PROTOCOL_ERROR; 461 return ERR_QUIC_PROTOCOL_ERROR;
462 } 462 }
463 // Put the peer's IP address and port into the response. 463 // Put the peer's IP address and port into the response.
464 IPEndPoint address = stream_->GetPeerAddress(); 464 IPEndPoint address = stream_->GetPeerAddress();
465 response_info_->socket_address = HostPortPair::FromIPEndPoint(address); 465 response_info_->socket_address = HostPortPair::FromIPEndPoint(address);
466 response_info_->connection_info = 466 response_info_->connection_info =
467 HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3; 467 HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3;
468 response_info_->vary_data.Init(*request_info_, *response_info_->headers); 468 response_info_->vary_data
469 .Init(*request_info_, *response_info_->headers.get());
469 response_info_->was_npn_negotiated = true; 470 response_info_->was_npn_negotiated = true;
470 response_info_->npn_negotiated_protocol = "quic/1+spdy/3"; 471 response_info_->npn_negotiated_protocol = "quic/1+spdy/3";
471 response_headers_received_ = true; 472 response_headers_received_ = true;
472 473
473 return OK; 474 return OK;
474 } 475 }
475 476
476 void QuicHttpStream::BufferResponseBody(const char* data, int length) { 477 void QuicHttpStream::BufferResponseBody(const char* data, int length) {
477 if (length == 0) 478 if (length == 0)
478 return; 479 return;
479 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); 480 IOBufferWithSize* io_buffer = new IOBufferWithSize(length);
480 memcpy(io_buffer->data(), data, length); 481 memcpy(io_buffer->data(), data, length);
481 response_body_.push_back(make_scoped_refptr(io_buffer)); 482 response_body_.push_back(make_scoped_refptr(io_buffer));
482 } 483 }
483 484
484 } // namespace net 485 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_helper.cc ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698