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

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

Issue 10910268: net: Make UploadDataStream::Read() asynchronous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 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_stream_parser.h ('k') | net/spdy/spdy_http_stream.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_stream_parser.h" 5 #include "net/http/http_stream_parser.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // We'll repurpose |request_headers_| to store the merged headers and 253 // We'll repurpose |request_headers_| to store the merged headers and
254 // body. 254 // body.
255 request_headers_ = new DrainableIOBuffer( 255 request_headers_ = new DrainableIOBuffer(
256 merged_request_headers_and_body, merged_size); 256 merged_request_headers_and_body, merged_size);
257 257
258 memcpy(request_headers_->data(), request.data(), request.size()); 258 memcpy(request_headers_->data(), request.data(), request.size());
259 request_headers_->DidConsume(request.size()); 259 request_headers_->DidConsume(request.size());
260 260
261 size_t todo = request_body_->size(); 261 size_t todo = request_body_->size();
262 while (todo) { 262 while (todo) {
263 int consumed = request_body_->Read(request_headers_, todo); 263 int consumed = request_body_->ReadSync(request_headers_, todo);
264 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. 264 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked.
265 request_headers_->DidConsume(consumed); 265 request_headers_->DidConsume(consumed);
266 todo -= consumed; 266 todo -= consumed;
267 } 267 }
268 DCHECK(request_body_->IsEOF()); 268 DCHECK(request_body_->IsEOF());
269 // Reset the offset, so the buffer can be read from the beginning. 269 // Reset the offset, so the buffer can be read from the beginning.
270 request_headers_->SetOffset(0); 270 request_headers_->SetOffset(0);
271 did_merge = true; 271 did_merge = true;
272 272
273 net_log_.AddEvent( 273 net_log_.AddEvent(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return connection_->socket()->Write(request_body_buf_, 483 return connection_->socket()->Write(request_body_buf_,
484 request_body_buf_->BytesRemaining(), 484 request_body_buf_->BytesRemaining(),
485 io_callback_); 485 io_callback_);
486 } 486 }
487 487
488 if (sent_last_chunk_) { 488 if (sent_last_chunk_) {
489 io_state_ = STATE_REQUEST_SENT; 489 io_state_ = STATE_REQUEST_SENT;
490 return OK; 490 return OK;
491 } 491 }
492 492
493 const int consumed = request_body_->Read(chunk_buf_, chunk_buf_->size()); 493 const int consumed = request_body_->ReadSync(chunk_buf_, chunk_buf_->size());
494 if (consumed == 0) { // Reached the end. 494 if (consumed == 0) { // Reached the end.
495 DCHECK(request_body_->IsEOF()); 495 DCHECK(request_body_->IsEOF());
496 request_body_buf_->Clear(); 496 request_body_buf_->Clear();
497 const int chunk_length = EncodeChunk(base::StringPiece(), 497 const int chunk_length = EncodeChunk(base::StringPiece(),
498 request_body_buf_->data(), 498 request_body_buf_->data(),
499 request_body_buf_->capacity()); 499 request_body_buf_->capacity());
500 request_body_buf_->DidAppend(chunk_length); 500 request_body_buf_->DidAppend(chunk_length);
501 sent_last_chunk_ = true; 501 sent_last_chunk_ = true;
502 } else if (consumed > 0) { 502 } else if (consumed > 0) {
503 // Encode and send the buffer as 1 chunk. 503 // Encode and send the buffer as 1 chunk.
(...skipping 23 matching lines...) Expand all
527 527
528 // Send the remaining data in the request body buffer. 528 // Send the remaining data in the request body buffer.
529 request_body_buf_->DidConsume(result); 529 request_body_buf_->DidConsume(result);
530 if (request_body_buf_->BytesRemaining() > 0) { 530 if (request_body_buf_->BytesRemaining() > 0) {
531 return connection_->socket()->Write(request_body_buf_, 531 return connection_->socket()->Write(request_body_buf_,
532 request_body_buf_->BytesRemaining(), 532 request_body_buf_->BytesRemaining(),
533 io_callback_); 533 io_callback_);
534 } 534 }
535 535
536 request_body_buf_->Clear(); 536 request_body_buf_->Clear();
537 const int consumed = request_body_->Read(request_body_buf_, 537 const int consumed = request_body_->ReadSync(request_body_buf_,
538 request_body_buf_->capacity()); 538 request_body_buf_->capacity());
539 if (consumed == 0) { // Reached the end. 539 if (consumed == 0) { // Reached the end.
540 io_state_ = STATE_REQUEST_SENT; 540 io_state_ = STATE_REQUEST_SENT;
541 } else if (consumed > 0) { 541 } else if (consumed > 0) {
542 request_body_buf_->DidAppend(consumed); 542 request_body_buf_->DidAppend(consumed);
543 result = connection_->socket()->Write(request_body_buf_, 543 result = connection_->socket()->Write(request_body_buf_,
544 request_body_buf_->BytesRemaining(), 544 request_body_buf_->BytesRemaining(),
545 io_callback_); 545 io_callback_);
546 } else { 546 } else {
547 // UploadDataStream::Read() won't fail if not chunked. 547 // UploadDataStream::Read() won't fail if not chunked.
548 NOTREACHED(); 548 NOTREACHED();
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 request_body->IsInMemory() && 1000 request_body->IsInMemory() &&
1001 request_body->size() > 0) { 1001 request_body->size() > 0) {
1002 size_t merged_size = request_headers.size() + request_body->size(); 1002 size_t merged_size = request_headers.size() + request_body->size();
1003 if (merged_size <= kMaxMergedHeaderAndBodySize) 1003 if (merged_size <= kMaxMergedHeaderAndBodySize)
1004 return true; 1004 return true;
1005 } 1005 }
1006 return false; 1006 return false;
1007 } 1007 }
1008 1008
1009 } // namespace net 1009 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_parser.h ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698