| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 type_ = TYPE_CHUNK; | 59 type_ = TYPE_CHUNK; |
| 60 is_last_chunk_ = is_last_chunk; | 60 is_last_chunk_ = is_last_chunk; |
| 61 } | 61 } |
| 62 | 62 |
| 63 uint64 UploadData::Element::GetContentLength() { | 63 uint64 UploadData::Element::GetContentLength() { |
| 64 if (override_content_length_ || content_length_computed_) | 64 if (override_content_length_ || content_length_computed_) |
| 65 return content_length_; | 65 return content_length_; |
| 66 | 66 |
| 67 if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK) | 67 if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK) |
| 68 return static_cast<uint64>(bytes_.size()); | 68 return static_cast<uint64>(bytes_.size()); |
| 69 else if (type_ == TYPE_BLOB) | |
| 70 // The blob reference will be resolved later. | |
| 71 return 0; | |
| 72 | 69 |
| 73 DCHECK_EQ(TYPE_FILE, type_); | 70 DCHECK_EQ(TYPE_FILE, type_); |
| 74 DCHECK(!file_stream_); | 71 DCHECK(!file_stream_); |
| 75 | 72 |
| 76 // TODO(darin): This size calculation could be out of sync with the state of | 73 // TODO(darin): This size calculation could be out of sync with the state of |
| 77 // the file when we get around to reading it. We should probably find a way | 74 // the file when we get around to reading it. We should probably find a way |
| 78 // to lock the file or somehow protect against this error condition. | 75 // to lock the file or somehow protect against this error condition. |
| 79 | 76 |
| 80 content_length_computed_ = true; | 77 content_length_computed_ = true; |
| 81 content_length_ = 0; | 78 content_length_ = 0; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 220 |
| 224 void UploadData::AppendFileRange(const FilePath& file_path, | 221 void UploadData::AppendFileRange(const FilePath& file_path, |
| 225 uint64 offset, uint64 length, | 222 uint64 offset, uint64 length, |
| 226 const base::Time& expected_modification_time) { | 223 const base::Time& expected_modification_time) { |
| 227 DCHECK(!is_chunked_); | 224 DCHECK(!is_chunked_); |
| 228 elements_.push_back(Element()); | 225 elements_.push_back(Element()); |
| 229 elements_.back().SetToFilePathRange(file_path, offset, length, | 226 elements_.back().SetToFilePathRange(file_path, offset, length, |
| 230 expected_modification_time); | 227 expected_modification_time); |
| 231 } | 228 } |
| 232 | 229 |
| 233 void UploadData::AppendBlob(const GURL& blob_url) { | |
| 234 DCHECK(!is_chunked_); | |
| 235 elements_.push_back(Element()); | |
| 236 elements_.back().SetToBlobUrl(blob_url); | |
| 237 } | |
| 238 | |
| 239 void UploadData::AppendChunk(const char* bytes, | 230 void UploadData::AppendChunk(const char* bytes, |
| 240 int bytes_len, | 231 int bytes_len, |
| 241 bool is_last_chunk) { | 232 bool is_last_chunk) { |
| 242 DCHECK(is_chunked_); | 233 DCHECK(is_chunked_); |
| 243 elements_.push_back(Element()); | 234 elements_.push_back(Element()); |
| 244 elements_.back().SetToChunk(bytes, bytes_len, is_last_chunk); | 235 elements_.back().SetToChunk(bytes, bytes_len, is_last_chunk); |
| 245 if (chunk_callback_) | 236 if (chunk_callback_) |
| 246 chunk_callback_->OnChunkAvailable(); | 237 chunk_callback_->OnChunkAvailable(); |
| 247 } | 238 } |
| 248 | 239 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return; | 290 return; |
| 300 | 291 |
| 301 for (size_t i = 0; i < elements_.size(); ++i) | 292 for (size_t i = 0; i < elements_.size(); ++i) |
| 302 *content_length += elements_[i].GetContentLength(); | 293 *content_length += elements_[i].GetContentLength(); |
| 303 } | 294 } |
| 304 | 295 |
| 305 UploadData::~UploadData() { | 296 UploadData::~UploadData() { |
| 306 } | 297 } |
| 307 | 298 |
| 308 } // namespace net | 299 } // namespace net |
| OLD | NEW |