Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.net.urlconnection; | 5 package org.chromium.net.urlconnection; |
| 6 | 6 |
| 7 import org.chromium.net.UploadDataProvider; | 7 import org.chromium.net.UploadDataProvider; |
| 8 import org.chromium.net.UploadDataSink; | 8 import org.chromium.net.UploadDataSink; |
| 9 | 9 |
| 10 import java.io.IOException; | 10 import java.io.IOException; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 75 } |
| 76 int sent = Math.min(toSend, mBuffer.limit() - mBuffer.position()); | 76 int sent = Math.min(toSend, mBuffer.limit() - mBuffer.position()); |
| 77 mBuffer.put(buffer, offset + count - toSend, sent); | 77 mBuffer.put(buffer, offset + count - toSend, sent); |
| 78 toSend -= sent; | 78 toSend -= sent; |
| 79 } | 79 } |
| 80 mBytesWritten += count; | 80 mBytesWritten += count; |
| 81 } | 81 } |
| 82 | 82 |
| 83 @Override | 83 @Override |
| 84 public void close() throws IOException { | 84 public void close() throws IOException { |
| 85 if (!mLastChunk) { | 85 if (!mLastChunk) { |
|
pauljensen
2016/02/04 15:27:26
I think we can get rid of this if-statement now.
xunjieli
2016/07/08 14:02:14
Done.
| |
| 86 // Write last chunk. | 86 // Write last chunk. |
| 87 mLastChunk = true; | 87 mLastChunk = true; |
| 88 mMessageLoop.loop(); | |
| 89 } | 88 } |
| 90 mClosed = true; | 89 mClosed = true; |
| 91 } | 90 } |
| 92 | 91 |
| 93 private void checkNotClosed() throws IOException { | 92 private void checkNotClosed() throws IOException { |
| 94 if (mClosed) { | 93 if (mClosed) { |
| 95 throw new IOException("Stream has been closed."); | 94 throw new IOException("Stream has been closed."); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 // Move remaining buffer to the head of the buffer for use in th e | 129 // Move remaining buffer to the head of the buffer for use in th e |
| 131 // next read call. | 130 // next read call. |
| 132 mBuffer.compact(); | 131 mBuffer.compact(); |
| 133 uploadDataSink.onReadSucceeded(false); | 132 uploadDataSink.onReadSucceeded(false); |
| 134 } else { | 133 } else { |
| 135 // byteBuffer has enough capacity to hold the content of mBuffer . | 134 // byteBuffer has enough capacity to hold the content of mBuffer . |
| 136 mBuffer.flip(); | 135 mBuffer.flip(); |
| 137 byteBuffer.put(mBuffer); | 136 byteBuffer.put(mBuffer); |
| 138 // Reuse this buffer. | 137 // Reuse this buffer. |
| 139 mBuffer.clear(); | 138 mBuffer.clear(); |
| 140 // Quit message loop so embedder can write more data. | |
| 141 mMessageLoop.quit(); | |
| 142 uploadDataSink.onReadSucceeded(mLastChunk); | 139 uploadDataSink.onReadSucceeded(mLastChunk); |
| 140 if (!mLastChunk) { | |
| 141 // Quit message loop so embedder can write more data. | |
| 142 mMessageLoop.quit(); | |
| 143 } | |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 | 146 |
| 146 @Override | 147 @Override |
| 147 public void rewind(UploadDataSink uploadDataSink) { | 148 public void rewind(UploadDataSink uploadDataSink) { |
| 148 uploadDataSink.onRewindError( | 149 uploadDataSink.onRewindError( |
| 149 new HttpRetryException("Cannot retry streamed Http body", -1 )); | 150 new HttpRetryException("Cannot retry streamed Http body", -1 )); |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 } | 153 } |
| OLD | NEW |