Chromium Code Reviews| 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..01bcfc8aeff3391e9fab1c6e33eb20867012e4e8 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, |
|
mef
2016/08/30 16:29:44
Can this executor be also just wrapped into Direct
Charles
2016/08/30 20:11:06
I didn't do that in this case because we pool the
mef
2016/08/31 17:26:52
Acknowledged.
|
| - mPriority, mRequestAnnotations, mDisableCache, mDisableConnectionMigration); |
| + mPriority, mRequestAnnotations, mDisableCache, mDisableConnectionMigration, |
| + mAllowDirectExecutor); |
| if (mMethod != null) { |
| request.setHttpMethod(mMethod); |
| } |
| @@ -266,7 +283,12 @@ public interface UrlRequest { |
| request.addHeader(header.first, header.second); |
| } |
| if (mUploadDataProvider != null) { |
| - request.setUploadDataProvider(mUploadDataProvider, mUploadDataProviderExecutor); |
| + if (mAllowDirectExecutor) { |
| + request.setUploadDataProvider(mUploadDataProvider, mUploadDataProviderExecutor); |
| + } else { |
| + request.setUploadDataProvider(mUploadDataProvider, |
| + new DirectPreventingExecutor(mUploadDataProviderExecutor)); |
| + } |
| } |
| return request; |
| } |