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

Side by Side 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 unified diff | Download patch
OLDNEW
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
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
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 11 matching lines...) Expand all
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,
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 request.setUploadDataProvider(mUploadDataProvider, mUploadDataPr oviderExecutor);
270 } 287 }
271 return request; 288 return request;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 * the request's current status. {@code listener} will be invoked 695 * the request's current status. {@code listener} will be invoked
679 * back on the {@link Executor} passed in when the request was 696 * back on the {@link Executor} passed in when the request was
680 * created. 697 * created.
681 */ 698 */
682 public void getStatus(final StatusListener listener); 699 public void getStatus(final StatusListener listener);
683 700
684 // Note: There are deliberately no accessors for the results of the request 701 // Note: There are deliberately no accessors for the results of the request
685 // here. Having none removes any ambiguity over when they are populated, 702 // here. Having none removes any ambiguity over when they are populated,
686 // particularly in the redirect case. 703 // particularly in the redirect case.
687 } 704 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698