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

Side by Side Diff: net/base/chunked_upload_data_stream.cc

Issue 1465803002: Remove ScopedVector from chunked_upload_data_stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « net/base/chunked_upload_data_stream.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base/chunked_upload_data_stream.h" 5 #include "net/base/chunked_upload_data_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.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 10 matching lines...) Expand all
21 21
22 ChunkedUploadDataStream::~ChunkedUploadDataStream() { 22 ChunkedUploadDataStream::~ChunkedUploadDataStream() {
23 } 23 }
24 24
25 void ChunkedUploadDataStream::AppendData( 25 void ChunkedUploadDataStream::AppendData(
26 const char* data, int data_len, bool is_done) { 26 const char* data, int data_len, bool is_done) {
27 DCHECK(!all_data_appended_); 27 DCHECK(!all_data_appended_);
28 DCHECK(data_len > 0 || is_done); 28 DCHECK(data_len > 0 || is_done);
29 if (data_len > 0) { 29 if (data_len > 0) {
30 DCHECK(data); 30 DCHECK(data);
31 upload_data_.push_back(new std::vector<char>(data, data + data_len)); 31 upload_data_.push_back(
32 make_scoped_ptr(new std::vector<char>(data, data + data_len)));
32 } 33 }
33 all_data_appended_ = is_done; 34 all_data_appended_ = is_done;
34 35
35 if (!read_buffer_.get()) 36 if (!read_buffer_.get())
36 return; 37 return;
37 38
38 int result = ReadChunk(read_buffer_.get(), read_buffer_len_); 39 int result = ReadChunk(read_buffer_.get(), read_buffer_len_);
39 // Shouldn't get an error or ERR_IO_PENDING. 40 // Shouldn't get an error or ERR_IO_PENDING.
40 DCHECK_GE(result, 0); 41 DCHECK_GE(result, 0);
41 read_buffer_ = NULL; 42 read_buffer_ = NULL;
(...skipping 25 matching lines...) Expand all
67 read_buffer_ = NULL; 68 read_buffer_ = NULL;
68 read_buffer_len_ = 0; 69 read_buffer_len_ = 0;
69 read_index_ = 0; 70 read_index_ = 0;
70 read_offset_ = 0; 71 read_offset_ = 0;
71 } 72 }
72 73
73 int ChunkedUploadDataStream::ReadChunk(IOBuffer* buf, int buf_len) { 74 int ChunkedUploadDataStream::ReadChunk(IOBuffer* buf, int buf_len) {
74 // Copy as much data as possible from |upload_data_| to |buf|. 75 // Copy as much data as possible from |upload_data_| to |buf|.
75 int bytes_read = 0; 76 int bytes_read = 0;
76 while (read_index_ < upload_data_.size() && bytes_read < buf_len) { 77 while (read_index_ < upload_data_.size() && bytes_read < buf_len) {
77 std::vector<char>* data = upload_data_[read_index_]; 78 std::vector<char>* data = upload_data_[read_index_].get();
78 size_t bytes_to_read = 79 size_t bytes_to_read =
79 std::min(static_cast<size_t>(buf_len - bytes_read), 80 std::min(static_cast<size_t>(buf_len - bytes_read),
80 data->size() - read_offset_); 81 data->size() - read_offset_);
81 memcpy(buf->data() + bytes_read, 82 memcpy(buf->data() + bytes_read,
82 vector_as_array(data) + read_offset_, 83 vector_as_array(data) + read_offset_,
83 bytes_to_read); 84 bytes_to_read);
84 bytes_read += bytes_to_read; 85 bytes_read += bytes_to_read;
85 read_offset_ += bytes_to_read; 86 read_offset_ += bytes_to_read;
86 if (read_offset_ == data->size()) { 87 if (read_offset_ == data->size()) {
87 read_index_++; 88 read_index_++;
88 read_offset_ = 0; 89 read_offset_ = 0;
89 } 90 }
90 } 91 }
91 DCHECK_LE(bytes_read, buf_len); 92 DCHECK_LE(bytes_read, buf_len);
92 93
93 // If no data was written, and not all data has been appended, return 94 // If no data was written, and not all data has been appended, return
94 // ERR_IO_PENDING. The read will be completed in the next call to AppendData. 95 // ERR_IO_PENDING. The read will be completed in the next call to AppendData.
95 if (bytes_read == 0 && !all_data_appended_) 96 if (bytes_read == 0 && !all_data_appended_)
96 return ERR_IO_PENDING; 97 return ERR_IO_PENDING;
97 98
98 if (read_index_ == upload_data_.size() && all_data_appended_) 99 if (read_index_ == upload_data_.size() && all_data_appended_)
99 SetIsFinalChunk(); 100 SetIsFinalChunk();
100 return bytes_read; 101 return bytes_read;
101 } 102 }
102 103
103 } // namespace net 104 } // namespace net
OLDNEW
« no previous file with comments | « net/base/chunked_upload_data_stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698