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

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

Issue 2283243002: Allow direct executors in cronet. (Closed)
Patch Set: Improve thread checking 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
Index: components/cronet/android/api/src/org/chromium/net/UrlRequest.java
diff --git a/components/cronet/android/api/src/org/chromium/net/UrlRequest.java b/components/cronet/android/api/src/org/chromium/net/UrlRequest.java
index 932300014c8ae71380fe11d6772e0e5a6f3eef1b..99239c46f882c2217f46d9a4bb8ad10c116cf2a2 100644
--- a/components/cronet/android/api/src/org/chromium/net/UrlRequest.java
+++ b/components/cronet/android/api/src/org/chromium/net/UrlRequest.java
@@ -56,6 +56,7 @@ public interface UrlRequest {
UploadDataProvider mUploadDataProvider;
// Executor to call upload data provider back on.
Executor mUploadDataProviderExecutor;
+ private boolean mAllowDirectExecutor = false;
/**
* Creates a builder for {@link UrlRequest} objects. All callbacks for
@@ -227,6 +228,21 @@ public interface UrlRequest {
}
/**
+ * Marks that the executors this request will use to notify callbacks (for
+ * {@code UploadDataProvider}s and {@code UrlRequest.Callback}s) is intentionally performing
+ * inline execution, like Guava's directExecutor or
+ * {@link java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy}.
+ *
+ * <p><b>Warning:</b> This option makes it easy to accidentally block the network thread.
+ * It should not be used if your callbacks perform disk I/O, acquire locks, or call into
+ * other code you don't carefully control and audit.
+ */
+ public Builder allowDirectExecutor() {
+ mAllowDirectExecutor = true;
+ return this;
+ }
+
+ /**
* Associates the annotation object with this request. May add more than one.
* Passed through to a {@link RequestFinishedInfo.Listener},
* see {@link RequestFinishedInfo#getAnnotations}.
@@ -258,7 +274,8 @@ public interface UrlRequest {
*/
public UrlRequest build() {
final UrlRequest request = mCronetEngine.createRequest(mUrl, mCallback, mExecutor,
- mPriority, mRequestAnnotations, mDisableCache, mDisableConnectionMigration);
+ mPriority, mRequestAnnotations, mDisableCache, mDisableConnectionMigration,
+ mAllowDirectExecutor);
if (mMethod != null) {
request.setHttpMethod(mMethod);
}

Powered by Google App Engine
This is Rietveld 408576698