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_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 "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 *upload_data_->elements_mutable(); | 74 *upload_data_->elements_mutable(); |
75 | 75 |
76 int bytes_copied = 0; | 76 int bytes_copied = 0; |
77 while (bytes_copied < buf_len && element_index_ < elements.size()) { | 77 while (bytes_copied < buf_len && element_index_ < elements.size()) { |
78 UploadElement& element = elements[element_index_]; | 78 UploadElement& element = elements[element_index_]; |
79 | 79 |
80 bytes_copied += element.ReadSync(buf->data() + bytes_copied, | 80 bytes_copied += element.ReadSync(buf->data() + bytes_copied, |
81 buf_len - bytes_copied); | 81 buf_len - bytes_copied); |
82 | 82 |
83 if (element.BytesRemaining() == 0) | 83 if (element.BytesRemaining() == 0) |
84 ++element_index_; | 84 ++element_index_; |
85 | 85 |
86 if (is_chunked() && !merge_chunks_) | 86 if (is_chunked() && !merge_chunks_) |
87 break; | 87 break; |
88 } | 88 } |
89 | 89 |
90 current_position_ += bytes_copied; | 90 current_position_ += bytes_copied; |
91 if (is_chunked() && !IsEOF() && bytes_copied == 0) | 91 if (is_chunked() && !IsEOF() && bytes_copied == 0) |
92 return ERR_IO_PENDING; | 92 return ERR_IO_PENDING; |
93 | 93 |
94 return bytes_copied; | 94 return bytes_copied; |
95 } | 95 } |
96 | 96 |
97 bool UploadDataStream::IsEOF() const { | 97 bool UploadDataStream::IsEOF() const { |
98 const std::vector<UploadElement>& elements = *upload_data_->elements(); | 98 const std::vector<UploadElement>& elements = *upload_data_->elements(); |
99 | 99 |
100 // Check if all elements are consumed. | 100 // Check if all elements are consumed. |
101 if (element_index_ == elements.size()) { | 101 if (element_index_ == elements.size()) { |
102 // If the upload data is chunked, check if the last element is the | 102 // If the upload data is chunked, check if the last chunk is appended. |
103 // last chunk. | 103 if (!upload_data_->is_chunked() || upload_data_->last_chunk_appended()) |
104 if (!upload_data_->is_chunked() || | |
105 (!elements.empty() && elements.back().is_last_chunk())) { | |
106 return true; | 104 return true; |
107 } | |
108 } | 105 } |
109 return false; | 106 return false; |
110 } | 107 } |
111 | 108 |
112 bool UploadDataStream::IsInMemory() const { | 109 bool UploadDataStream::IsInMemory() const { |
113 DCHECK(initialized_successfully_); | 110 DCHECK(initialized_successfully_); |
114 | 111 |
115 return upload_data_->IsInMemory(); | 112 return upload_data_->IsInMemory(); |
116 } | 113 } |
117 | 114 |
118 } // namespace net | 115 } // namespace net |
OLD | NEW |