Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/base/upload_data.h" | 5 #include "net/base/upload_data.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 return 0; | 171 return 0; |
| 172 | 172 |
| 173 uint64 len = 0; | 173 uint64 len = 0; |
| 174 std::vector<Element>::iterator it = elements_.begin(); | 174 std::vector<Element>::iterator it = elements_.begin(); |
| 175 for (; it != elements_.end(); ++it) | 175 for (; it != elements_.end(); ++it) |
| 176 len += (*it).GetContentLength(); | 176 len += (*it).GetContentLength(); |
| 177 return len; | 177 return len; |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool UploadData::IsInMemory() const { | 180 bool UploadData::IsInMemory() const { |
| 181 // Chunks are provided as a stream, hence it's not in memory. | 181 // Chunks are in memory, but UploadData does not have all the chunks at |
| 182 // once. Chunks are provided progressively with AppendChunk() as chunks | |
| 183 // are ready. Check is_chunked_ here, rather than relying on the loop | |
| 184 // below, as there is a case that is_chunked_ is set to true, but the | |
| 185 // first chunk is not yet delivered. | |
|
wtc
2012/01/24 20:10:57
Thank you for explaining this to me.
| |
| 182 if (is_chunked_) | 186 if (is_chunked_) |
| 183 return false; | 187 return false; |
| 184 | 188 |
| 185 for (size_t i = 0; i < elements_.size(); ++i) { | 189 for (size_t i = 0; i < elements_.size(); ++i) { |
| 186 if (elements_[i].type() != TYPE_BYTES) | 190 if (elements_[i].type() != TYPE_BYTES) |
| 187 return false; | 191 return false; |
| 188 } | 192 } |
| 189 return true; | 193 return true; |
| 190 } | 194 } |
| 191 | 195 |
| 192 void UploadData::SetElements(const std::vector<Element>& elements) { | 196 void UploadData::SetElements(const std::vector<Element>& elements) { |
| 193 elements_ = elements; | 197 elements_ = elements; |
| 194 } | 198 } |
| 195 | 199 |
| 196 UploadData::~UploadData() { | 200 UploadData::~UploadData() { |
| 197 } | 201 } |
| 198 | 202 |
| 199 } // namespace net | 203 } // namespace net |
| OLD | NEW |