OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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; | 5 package org.chromium.net; |
6 | 6 |
7 import android.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
8 import android.util.Log; | 8 import android.util.Log; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 // Disable connection migration for just this request. | 49 // Disable connection migration for just this request. |
50 boolean mDisableConnectionMigration; | 50 boolean mDisableConnectionMigration; |
51 // Priority of request. Default is medium. | 51 // Priority of request. Default is medium. |
52 @RequestPriority int mPriority = REQUEST_PRIORITY_MEDIUM; | 52 @RequestPriority int mPriority = REQUEST_PRIORITY_MEDIUM; |
53 // Request reporting annotations. Avoid extra object creation if no anno tations added. | 53 // Request reporting annotations. Avoid extra object creation if no anno tations added. |
54 Collection<Object> mRequestAnnotations = Collections.emptyList(); | 54 Collection<Object> mRequestAnnotations = Collections.emptyList(); |
55 // If request is an upload, this provides the request body data. | 55 // If request is an upload, this provides the request body data. |
56 UploadDataProvider mUploadDataProvider; | 56 UploadDataProvider mUploadDataProvider; |
57 // Executor to call upload data provider back on. | 57 // Executor to call upload data provider back on. |
58 Executor mUploadDataProviderExecutor; | 58 Executor mUploadDataProviderExecutor; |
59 private boolean mAllowDirectExecutor = false; | |
59 | 60 |
60 /** | 61 /** |
61 * Creates a builder for {@link UrlRequest} objects. All callbacks for | 62 * Creates a builder for {@link UrlRequest} objects. All callbacks for |
62 * generated {@link UrlRequest} objects will be invoked on | 63 * generated {@link UrlRequest} objects will be invoked on |
63 * {@code executor}'s thread. {@code executor} must not run tasks on the | 64 * {@code executor}'s thread. {@code executor} must not run tasks on the |
64 * current thread to prevent blocking networking operations and causing | 65 * current thread to prevent blocking networking operations and causing |
65 * exceptions during shutdown. | 66 * exceptions during shutdown. |
66 * | 67 * |
67 * @param url {@link java.net.URL} for the generated requests. | 68 * @param url {@link java.net.URL} for the generated requests. |
68 * @param callback callback object that gets invoked on different events . | 69 * @param callback callback object that gets invoked on different events . |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 221 } |
221 if (mMethod == null) { | 222 if (mMethod == null) { |
222 mMethod = "POST"; | 223 mMethod = "POST"; |
223 } | 224 } |
224 mUploadDataProvider = uploadDataProvider; | 225 mUploadDataProvider = uploadDataProvider; |
225 mUploadDataProviderExecutor = executor; | 226 mUploadDataProviderExecutor = executor; |
226 return this; | 227 return this; |
227 } | 228 } |
228 | 229 |
229 /** | 230 /** |
231 * Marks that the executors this request will use to notify callbacks (f or | |
232 * {@code UploadDataProvider}s and {@code UrlRequest.Callback}s) is inte ntionally performing | |
233 * inline execution, like Guava's directExecutor or | |
234 * {@link java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy}. | |
235 * | |
236 * <p><b>Warning:</b> This option makes it easy to accidentally block th e network thread. | |
237 * It should not be used if your callbacks perform disk I/O, acquire loc ks, or call into | |
238 * other code you don't carefully control and audit. | |
239 */ | |
240 public Builder allowDirectExecutor() { | |
241 mAllowDirectExecutor = true; | |
242 return this; | |
243 } | |
244 | |
245 /** | |
230 * Associates the annotation object with this request. May add more than one. | 246 * Associates the annotation object with this request. May add more than one. |
231 * Passed through to a {@link RequestFinishedInfo.Listener}, | 247 * Passed through to a {@link RequestFinishedInfo.Listener}, |
232 * see {@link RequestFinishedInfo#getAnnotations}. | 248 * see {@link RequestFinishedInfo#getAnnotations}. |
233 * | 249 * |
234 * @param annotation an object to pass on to the {@link RequestFinishedI nfo.Listener} with a | 250 * @param annotation an object to pass on to the {@link RequestFinishedI nfo.Listener} with a |
235 * {@link RequestFinishedInfo}. | 251 * {@link RequestFinishedInfo}. |
236 * @return the builder to facilitate chaining. | 252 * @return the builder to facilitate chaining. |
237 * | 253 * |
238 * @hide as it's a prototype. | 254 * @hide as it's a prototype. |
239 */ | 255 */ |
(...skipping 10 matching lines...) Expand all Loading... | |
250 | 266 |
251 /** | 267 /** |
252 * Creates a {@link UrlRequest} using configuration within this | 268 * Creates a {@link UrlRequest} using configuration within this |
253 * {@link Builder}. The returned {@code UrlRequest} can then be started | 269 * {@link Builder}. The returned {@code UrlRequest} can then be started |
254 * by calling {@link UrlRequest#start}. | 270 * by calling {@link UrlRequest#start}. |
255 * | 271 * |
256 * @return constructed {@link UrlRequest} using configuration within | 272 * @return constructed {@link UrlRequest} using configuration within |
257 * this {@link Builder}. | 273 * this {@link Builder}. |
258 */ | 274 */ |
259 public UrlRequest build() { | 275 public UrlRequest build() { |
260 final UrlRequest request = mCronetEngine.createRequest(mUrl, mCallba ck, mExecutor, | 276 final UrlRequest request = mCronetEngine.createRequest(mUrl, mCallba ck, 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.
| |
261 mPriority, mRequestAnnotations, mDisableCache, mDisableConne ctionMigration); | 277 mPriority, mRequestAnnotations, mDisableCache, mDisableConne ctionMigration, |
278 mAllowDirectExecutor); | |
262 if (mMethod != null) { | 279 if (mMethod != null) { |
263 request.setHttpMethod(mMethod); | 280 request.setHttpMethod(mMethod); |
264 } | 281 } |
265 for (Pair<String, String> header : mRequestHeaders) { | 282 for (Pair<String, String> header : mRequestHeaders) { |
266 request.addHeader(header.first, header.second); | 283 request.addHeader(header.first, header.second); |
267 } | 284 } |
268 if (mUploadDataProvider != null) { | 285 if (mUploadDataProvider != null) { |
269 request.setUploadDataProvider(mUploadDataProvider, mUploadDataPr oviderExecutor); | 286 if (mAllowDirectExecutor) { |
287 request.setUploadDataProvider(mUploadDataProvider, mUploadDa taProviderExecutor); | |
288 } else { | |
289 request.setUploadDataProvider(mUploadDataProvider, | |
290 new DirectPreventingExecutor(mUploadDataProviderExec utor)); | |
291 } | |
270 } | 292 } |
271 return request; | 293 return request; |
272 } | 294 } |
273 } | 295 } |
274 | 296 |
275 /** | 297 /** |
276 * Users of Cronet extend this class to receive callbacks indicating the | 298 * Users of Cronet extend this class to receive callbacks indicating the |
277 * progress of a {@link UrlRequest} being processed. An instance of this cla ss | 299 * progress of a {@link UrlRequest} being processed. An instance of this cla ss |
278 * is passed in to {@link UrlRequest.Builder}'s constructor when | 300 * is passed in to {@link UrlRequest.Builder}'s constructor when |
279 * constructing the {@code UrlRequest}. | 301 * constructing the {@code UrlRequest}. |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 * the request's current status. {@code listener} will be invoked | 700 * the request's current status. {@code listener} will be invoked |
679 * back on the {@link Executor} passed in when the request was | 701 * back on the {@link Executor} passed in when the request was |
680 * created. | 702 * created. |
681 */ | 703 */ |
682 public void getStatus(final StatusListener listener); | 704 public void getStatus(final StatusListener listener); |
683 | 705 |
684 // Note: There are deliberately no accessors for the results of the request | 706 // Note: There are deliberately no accessors for the results of the request |
685 // here. Having none removes any ambiguity over when they are populated, | 707 // here. Having none removes any ambiguity over when they are populated, |
686 // particularly in the redirect case. | 708 // particularly in the redirect case. |
687 } | 709 } |
OLD | NEW |