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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/UrlRequestBuilderImpl.java

Issue 2476983002: Fix null annotations, and move checks into RequestFinishedInfo (Closed)
Patch Set: Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package org.chromium.net.impl; 4 package org.chromium.net.impl;
5 5
6 import android.annotation.SuppressLint; 6 import android.annotation.SuppressLint;
7 import android.util.Log; 7 import android.util.Log;
8 import android.util.Pair; 8 import android.util.Pair;
9 9
10 import org.chromium.net.CronetEngine; 10 import org.chromium.net.CronetEngine;
11 import org.chromium.net.ExperimentalUrlRequest; 11 import org.chromium.net.ExperimentalUrlRequest;
12 import org.chromium.net.UploadDataProvider; 12 import org.chromium.net.UploadDataProvider;
13 import org.chromium.net.UrlRequest; 13 import org.chromium.net.UrlRequest;
14 14
15 import java.util.ArrayList; 15 import java.util.ArrayList;
16 import java.util.Collection; 16 import java.util.Collection;
17 import java.util.Collections;
18 import java.util.concurrent.Executor; 17 import java.util.concurrent.Executor;
19 18
20 /** 19 /**
21 * Implements {@link org.chromium.net.ExperimentalUrlRequest.Builder}. 20 * Implements {@link org.chromium.net.ExperimentalUrlRequest.Builder}.
22 */ 21 */
23 public class UrlRequestBuilderImpl extends ExperimentalUrlRequest.Builder { 22 public class UrlRequestBuilderImpl extends ExperimentalUrlRequest.Builder {
24 private static final String ACCEPT_ENCODING = "Accept-Encoding"; 23 private static final String ACCEPT_ENCODING = "Accept-Encoding";
25 private static final String TAG = "UrlRequestBuilder"; 24 private static final String TAG = "UrlRequestBuilder";
26 25
27 // All fields are temporary storage of ExperimentalUrlRequest configuration to be 26 // All fields are temporary storage of ExperimentalUrlRequest configuration to be
(...skipping 13 matching lines...) Expand all
41 // List of request headers, stored as header field name and value pairs. 40 // List of request headers, stored as header field name and value pairs.
42 private final ArrayList<Pair<String, String>> mRequestHeaders = new ArrayLis t<>(); 41 private final ArrayList<Pair<String, String>> mRequestHeaders = new ArrayLis t<>();
43 // Disable the cache for just this request. 42 // Disable the cache for just this request.
44 private boolean mDisableCache; 43 private boolean mDisableCache;
45 // Disable connection migration for just this request. 44 // Disable connection migration for just this request.
46 private boolean mDisableConnectionMigration; 45 private boolean mDisableConnectionMigration;
47 // Priority of request. Default is medium. 46 // Priority of request. Default is medium.
48 @CronetEngineBase.RequestPriority 47 @CronetEngineBase.RequestPriority
49 private int mPriority = REQUEST_PRIORITY_MEDIUM; 48 private int mPriority = REQUEST_PRIORITY_MEDIUM;
50 // Request reporting annotations. Avoid extra object creation if no annotati ons added. 49 // Request reporting annotations. Avoid extra object creation if no annotati ons added.
51 private Collection<Object> mRequestAnnotations = Collections.emptyList(); 50 private Collection<Object> mRequestAnnotations;
52 // If request is an upload, this provides the request body data. 51 // If request is an upload, this provides the request body data.
53 private UploadDataProvider mUploadDataProvider; 52 private UploadDataProvider mUploadDataProvider;
54 // Executor to call upload data provider back on. 53 // Executor to call upload data provider back on.
55 private Executor mUploadDataProviderExecutor; 54 private Executor mUploadDataProviderExecutor;
56 private boolean mAllowDirectExecutor = false; 55 private boolean mAllowDirectExecutor = false;
57 56
58 /** 57 /**
59 * Creates a builder for {@link UrlRequest} objects. All callbacks for 58 * Creates a builder for {@link UrlRequest} objects. All callbacks for
60 * generated {@link UrlRequest} objects will be invoked on 59 * generated {@link UrlRequest} objects will be invoked on
61 * {@code executor}'s thread. {@code executor} must not run tasks on the 60 * {@code executor}'s thread. {@code executor} must not run tasks on the
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 public UrlRequestBuilderImpl allowDirectExecutor() { 154 public UrlRequestBuilderImpl allowDirectExecutor() {
156 mAllowDirectExecutor = true; 155 mAllowDirectExecutor = true;
157 return this; 156 return this;
158 } 157 }
159 158
160 @Override 159 @Override
161 public UrlRequestBuilderImpl addRequestAnnotation(Object annotation) { 160 public UrlRequestBuilderImpl addRequestAnnotation(Object annotation) {
162 if (annotation == null) { 161 if (annotation == null) {
163 throw new NullPointerException("Invalid metrics annotation."); 162 throw new NullPointerException("Invalid metrics annotation.");
164 } 163 }
165 if (mRequestAnnotations.isEmpty()) { 164 if (mRequestAnnotations == null) {
166 mRequestAnnotations = new ArrayList<>(); 165 mRequestAnnotations = new ArrayList<>();
167 } 166 }
168 mRequestAnnotations.add(annotation); 167 mRequestAnnotations.add(annotation);
169 return this; 168 return this;
170 } 169 }
171 170
172 @Override 171 @Override
173 public UrlRequestBase build() { 172 public UrlRequestBase build() {
174 @SuppressLint("WrongConstant") // TODO(jbudorick): Remove this after rol ling to the N SDK. 173 @SuppressLint("WrongConstant") // TODO(jbudorick): Remove this after rol ling to the N SDK.
175 final UrlRequestBase request = mCronetEngine.createRequest(mUrl, mCallba ck, mExecutor, 174 final UrlRequestBase request = mCronetEngine.createRequest(mUrl, mCallba ck, mExecutor,
176 mPriority, mRequestAnnotations, mDisableCache, mDisableConnectio nMigration, 175 mPriority, mRequestAnnotations, mDisableCache, mDisableConnectio nMigration,
177 mAllowDirectExecutor); 176 mAllowDirectExecutor);
178 if (mMethod != null) { 177 if (mMethod != null) {
179 request.setHttpMethod(mMethod); 178 request.setHttpMethod(mMethod);
180 } 179 }
181 for (Pair<String, String> header : mRequestHeaders) { 180 for (Pair<String, String> header : mRequestHeaders) {
182 request.addHeader(header.first, header.second); 181 request.addHeader(header.first, header.second);
183 } 182 }
184 if (mUploadDataProvider != null) { 183 if (mUploadDataProvider != null) {
185 request.setUploadDataProvider(mUploadDataProvider, mUploadDataProvid erExecutor); 184 request.setUploadDataProvider(mUploadDataProvider, mUploadDataProvid erExecutor);
186 } 185 }
187 return request; 186 return request;
188 } 187 }
189 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698