OLD | NEW |
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/base/upload_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/base/file_stream.h" | 9 #include "net/base/file_stream.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
| 15 UploadDataStream::~UploadDataStream() { |
| 16 } |
| 17 |
15 UploadDataStream* UploadDataStream::Create(UploadData* data, int* error_code) { | 18 UploadDataStream* UploadDataStream::Create(UploadData* data, int* error_code) { |
16 scoped_ptr<UploadDataStream> stream(new UploadDataStream(data)); | 19 scoped_ptr<UploadDataStream> stream(new UploadDataStream(data)); |
17 int rv = stream->FillBuf(); | 20 int rv = stream->FillBuf(); |
18 if (error_code) | 21 if (error_code) |
19 *error_code = rv; | 22 *error_code = rv; |
20 if (rv != OK) | 23 if (rv != OK) |
21 return NULL; | 24 return NULL; |
22 | 25 |
23 return stream.release(); | 26 return stream.release(); |
24 } | 27 } |
(...skipping 18 matching lines...) Expand all Loading... |
43 buf_(new IOBuffer(kBufSize)), | 46 buf_(new IOBuffer(kBufSize)), |
44 buf_len_(0), | 47 buf_len_(0), |
45 next_element_(0), | 48 next_element_(0), |
46 next_element_offset_(0), | 49 next_element_offset_(0), |
47 next_element_remaining_(0), | 50 next_element_remaining_(0), |
48 total_size_(data->is_chunked() ? 0 : data->GetContentLength()), | 51 total_size_(data->is_chunked() ? 0 : data->GetContentLength()), |
49 current_position_(0), | 52 current_position_(0), |
50 eof_(false) { | 53 eof_(false) { |
51 } | 54 } |
52 | 55 |
53 UploadDataStream::~UploadDataStream() { | |
54 } | |
55 | |
56 int UploadDataStream::FillBuf() { | 56 int UploadDataStream::FillBuf() { |
57 std::vector<UploadData::Element>& elements = *data_->elements(); | 57 std::vector<UploadData::Element>& elements = *data_->elements(); |
58 | 58 |
59 while (buf_len_ < kBufSize && next_element_ < elements.size()) { | 59 while (buf_len_ < kBufSize && next_element_ < elements.size()) { |
60 bool advance_to_next_element = false; | 60 bool advance_to_next_element = false; |
61 | 61 |
62 UploadData::Element& element = elements[next_element_]; | 62 UploadData::Element& element = elements[next_element_]; |
63 | 63 |
64 size_t size_remaining = kBufSize - buf_len_; | 64 size_t size_remaining = kBufSize - buf_len_; |
65 if (element.type() == UploadData::TYPE_BYTES || | 65 if (element.type() == UploadData::TYPE_BYTES || |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (!data_->is_chunked() || | 132 if (!data_->is_chunked() || |
133 (!elements.empty() && elements.back().is_last_chunk())) { | 133 (!elements.empty() && elements.back().is_last_chunk())) { |
134 eof_ = true; | 134 eof_ = true; |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 return OK; | 138 return OK; |
139 } | 139 } |
140 | 140 |
141 } // namespace net | 141 } // namespace net |
OLD | NEW |