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

Unified Diff: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java

Issue 2131323002: [Cronet] Check whether request is done before spinning up message loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comment Created 4 years, 5 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
Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
index b23842377659d99bb4239b945e3279ae7651541d..03c4b4bae3378684f3183dca75011d1a23987d1e 100644
--- a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
+++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
@@ -14,6 +14,15 @@ import java.io.OutputStream;
* extend in order to be used in {@link CronetHttpURLConnection}.
*/
abstract class CronetOutputStream extends OutputStream {
+ private IOException mException;
+ private boolean mClosed;
+ private boolean mRequestCompleted;
+
+ @Override
+ public void close() throws IOException {
+ mClosed = true;
+ }
+
/**
* Tells the underlying implementation that connection has been established.
* Used in {@link CronetHttpURLConnection}.
@@ -30,4 +39,28 @@ abstract class CronetOutputStream extends OutputStream {
* Returns {@link UploadDataProvider} implementation.
*/
abstract UploadDataProvider getUploadDataProvider();
+
+ /**
+ * Signals that the request is done. If there is no error,
+ * {@code exception} is null. Used by {@link CronetHttpURLConnection}.
+ */
+ void setRequestCompleted(IOException exception) {
+ mException = exception;
+ mRequestCompleted = true;
+ }
+
+ /**
+ * Throws an IOException if the stream is closed or the request is done.
+ */
+ protected void checkNotClosed() throws IOException {
+ if (mRequestCompleted) {
+ if (mException != null) {
+ throw mException;
+ }
+ throw new IOException("Writing after request completed.");
+ }
+ if (mClosed) {
+ throw new IOException("Stream has been closed.");
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698