Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java

Issue 2356923002: Flush chunks on each upload read (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java
diff --git a/components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java b/components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java
index c5e3bd23a66c2ccdc87cbe5627406081fdd43138..0e582e476a672b6b3d539df2383cdbc3005418e4 100644
--- a/components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java
+++ b/components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java
@@ -11,6 +11,7 @@ import android.util.Log;
import java.io.Closeable;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
@@ -260,6 +261,7 @@ final class JavaUrlRequest implements UrlRequest {
final Executor mExecutor;
final HttpURLConnection mUrlConnection;
WritableByteChannel mOutputChannel;
+ OutputStream mUrlConnectionOutputStream;
final UploadDataProvider mUploadProvider;
ByteBuffer mBuffer;
/** This holds the total bytes to send (the content-length). -1 if unknown. */
@@ -303,6 +305,11 @@ final class JavaUrlRequest implements UrlRequest {
while (mBuffer.hasRemaining()) {
mWrittenBytes += mOutputChannel.write(mBuffer);
}
+ // Forces a chunk to be sent, rather than buffering to the DEFAULT_CHUNK_LENGTH.
+ // This allows clients to trickle-upload bytes as they become available without
+ // introducing latency due to buffering.
+ mUrlConnectionOutputStream.flush();
+
if (mWrittenBytes < mTotalBytes || (mTotalBytes == -1 && !finalChunk)) {
mBuffer.clear();
mSinkState.set(SinkState.AWAITING_READ_RESULT);
@@ -351,7 +358,8 @@ final class JavaUrlRequest implements UrlRequest {
mAdditionalStatusDetails = Status.CONNECTING;
mUrlConnection.connect();
mAdditionalStatusDetails = Status.SENDING_REQUEST;
- mOutputChannel = Channels.newChannel(mUrlConnection.getOutputStream());
+ mUrlConnectionOutputStream = mUrlConnection.getOutputStream();
+ mOutputChannel = Channels.newChannel(mUrlConnectionOutputStream);
}
mSinkState.set(SinkState.AWAITING_READ_RESULT);
executeOnUploadExecutor(new CheckedRunnable() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698