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/elements_upload_data_stream.h" | 5 #include "net/base/elements_upload_data_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 buf.get(), | 118 buf.get(), |
| 119 buf->BytesRemaining(), | 119 buf->BytesRemaining(), |
| 120 base::Bind(&ElementsUploadDataStream::OnReadElementCompleted, | 120 base::Bind(&ElementsUploadDataStream::OnReadElementCompleted, |
| 121 weak_ptr_factory_.GetWeakPtr(), | 121 weak_ptr_factory_.GetWeakPtr(), |
| 122 buf)); | 122 buf)); |
| 123 if (result == ERR_IO_PENDING) | 123 if (result == ERR_IO_PENDING) |
| 124 return ERR_IO_PENDING; | 124 return ERR_IO_PENDING; |
| 125 ProcessReadResult(buf, result); | 125 ProcessReadResult(buf, result); |
| 126 } | 126 } |
| 127 | 127 |
| 128 if (read_failed_) { | 128 if (read_failed_) |
| 129 // If an error occured during read operation, then pad with zero. | 129 return ERR_FAILED; |
| 130 // Otherwise the server will hang waiting for the rest of the data. | |
| 131 int num_bytes_to_fill = | |
| 132 static_cast<int>(std::min(static_cast<uint64_t>(buf->BytesRemaining()), | |
| 133 size() - position() - buf->BytesConsumed())); | |
| 134 DCHECK_GE(num_bytes_to_fill, 0); | |
| 135 memset(buf->data(), 0, num_bytes_to_fill); | |
| 136 buf->DidConsume(num_bytes_to_fill); | |
| 137 } | |
| 138 | 130 |
| 139 return buf->BytesConsumed(); | 131 return buf->BytesConsumed(); |
| 140 } | 132 } |
| 141 | 133 |
| 142 void ElementsUploadDataStream::OnReadElementCompleted( | 134 void ElementsUploadDataStream::OnReadElementCompleted( |
| 143 const scoped_refptr<DrainableIOBuffer>& buf, | 135 const scoped_refptr<DrainableIOBuffer>& buf, |
| 144 int result) { | 136 int result) { |
| 145 ProcessReadResult(buf, result); | 137 ProcessReadResult(buf, result); |
| 146 | 138 |
| 147 result = ReadElements(buf); | 139 result = ReadElements(buf); |
| 148 if (result != ERR_IO_PENDING) | 140 if (result != ERR_IO_PENDING) |
| 149 OnReadCompleted(result); | 141 OnReadCompleted(result); |
| 150 } | 142 } |
| 151 | 143 |
| 152 void ElementsUploadDataStream::ProcessReadResult( | 144 void ElementsUploadDataStream::ProcessReadResult( |
| 153 const scoped_refptr<DrainableIOBuffer>& buf, | 145 const scoped_refptr<DrainableIOBuffer>& buf, |
| 154 int result) { | 146 int result) { |
| 155 DCHECK_NE(ERR_IO_PENDING, result); | 147 DCHECK_NE(ERR_IO_PENDING, result); |
| 156 DCHECK(!read_failed_); | 148 DCHECK(!read_failed_); |
| 157 | 149 |
| 158 if (result >= 0) { | 150 if (result >= 0) { |
| 159 buf->DidConsume(result); | 151 buf->DidConsume(result); |
| 160 } else { | 152 } else { |
| 161 read_failed_ = true; | 153 read_failed_ = true; |
|
mmenke
2016/06/06 16:22:33
Instead of just setting read_failed_ to true, can
maksims (do not use this acc)
2016/06/21 11:09:25
Done.
| |
| 162 } | 154 } |
| 163 } | 155 } |
| 164 | 156 |
| 165 } // namespace net | 157 } // namespace net |
| OLD | NEW |