OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.Context; | 7 import android.content.Context; |
8 import android.support.annotation.IntDef; | 8 import android.support.annotation.IntDef; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
11 import org.json.JSONArray; | |
12 import org.json.JSONException; | |
13 import org.json.JSONObject; | |
14 | |
15 import java.io.File; | 11 import java.io.File; |
16 import java.lang.annotation.Retention; | 12 import java.lang.annotation.Retention; |
17 import java.lang.annotation.RetentionPolicy; | 13 import java.lang.annotation.RetentionPolicy; |
18 import java.lang.reflect.Constructor; | 14 import java.lang.reflect.Constructor; |
19 import java.net.Proxy; | 15 import java.net.Proxy; |
20 import java.net.URL; | 16 import java.net.URL; |
21 import java.net.URLConnection; | 17 import java.net.URLConnection; |
22 import java.net.URLStreamHandlerFactory; | 18 import java.net.URLStreamHandlerFactory; |
19 import java.util.LinkedList; | |
23 import java.util.List; | 20 import java.util.List; |
24 import java.util.Map; | 21 import java.util.Map; |
25 import java.util.concurrent.Executor; | 22 import java.util.concurrent.Executor; |
26 | 23 |
27 /** | 24 /** |
28 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack | 25 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack |
29 * available on the current platform. | 26 * available on the current platform. |
30 */ | 27 */ |
31 public abstract class CronetEngine { | 28 public abstract class CronetEngine { |
32 /** | 29 /** |
33 * A builder for {@link CronetEngine}s, which allows runtime configuration o f | 30 * A builder for {@link CronetEngine}s, which allows runtime configuration o f |
34 * {@code CronetEngine}. Configuration options are set on the builder and | 31 * {@code CronetEngine}. Configuration options are set on the builder and |
35 * then {@link #build} is called to create the {@code CronetEngine}. | 32 * then {@link #build} is called to create the {@code CronetEngine}. |
36 */ | 33 */ |
37 public static class Builder { | 34 public static class Builder { |
38 private final JSONObject mConfig; | 35 // A hint that a host supports QUIC. |
36 static class QuicHint { | |
37 // The host. | |
38 final String mHost; | |
39 // The port on which to use QUIC. | |
mef
2015/11/09 16:56:33
Port of the server that supports QUIC.
pauljensen
2015/12/02 03:50:01
Done.
| |
40 final int mPort; | |
41 // Another port on which to use QUIC. | |
mef
2015/11/09 16:56:33
Alternate protocol port.
pauljensen
2015/12/02 03:50:01
Done.
| |
42 final int mAlternatePort; | |
43 | |
44 QuicHint(String host, int port, int alternatePort) { | |
45 mHost = host; | |
46 mPort = port; | |
47 mAlternatePort = alternatePort; | |
48 } | |
49 } | |
50 | |
51 // Private fields are simply storage of configuration for the resulting CronetEngine. | |
52 // See setters below for verbose descriptions. | |
39 private final Context mContext; | 53 private final Context mContext; |
54 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); | |
55 private String mUserAgent = ""; | |
56 private String mStoragePath = ""; | |
57 private boolean mLegacyModeEnabled; | |
58 private String mLibraryName = "cronet"; | |
59 private boolean mQuicEnabled; | |
60 private boolean mHttp2Enabled; | |
61 private boolean mSdchEnabled; | |
62 private String mDataReductionProxyKey; | |
63 private String mDataReductionProxyPrimaryProxy; | |
64 private String mDataReductionProxyFallbackProxy; | |
65 private String mDataReductionProxySecureProxyCheckUrl; | |
66 private boolean mDisableCache; | |
67 private int mHttpCacheMode; | |
68 private long mHttpCacheMaxSize; | |
69 private String mExperimentalQuicConnectionOptions; | |
70 private long mMockCertVerifier; | |
40 | 71 |
41 /** | 72 /** |
42 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. | 73 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. |
43 * @param context Android {@link Context} for engine to use. | 74 * @param context Android {@link Context} for engine to use. |
44 */ | 75 */ |
45 public Builder(Context context) { | 76 public Builder(Context context) { |
46 mConfig = new JSONObject(); | |
47 mContext = context; | 77 mContext = context; |
48 enableLegacyMode(false); | 78 enableLegacyMode(false); |
49 enableQUIC(false); | 79 enableQUIC(false); |
50 enableHTTP2(true); | 80 enableHTTP2(true); |
51 enableSDCH(false); | 81 enableSDCH(false); |
52 enableHttpCache(HTTP_CACHE_DISABLED, 0); | 82 enableHttpCache(HTTP_CACHE_DISABLED, 0); |
53 } | 83 } |
54 | 84 |
55 /** | 85 /** |
56 * Constructs a User-Agent string including Cronet version, and | 86 * Constructs a User-Agent string including Cronet version, and |
57 * application name and version. | 87 * application name and version. |
58 * | 88 * |
59 * @return User-Agent string. | 89 * @return User-Agent string. |
60 */ | 90 */ |
61 public String getDefaultUserAgent() { | 91 public String getDefaultUserAgent() { |
62 return UserAgent.from(mContext); | 92 return UserAgent.from(mContext); |
63 } | 93 } |
64 | 94 |
65 /** | 95 /** |
66 * Overrides the User-Agent header for all requests. | 96 * Overrides the User-Agent header for all requests. |
67 * @return the builder to facilitate chaining. | 97 * @return the builder to facilitate chaining. |
68 */ | 98 */ |
69 public Builder setUserAgent(String userAgent) { | 99 public Builder setUserAgent(String userAgent) { |
70 return putString(CronetEngineBuilderList.USER_AGENT, userAgent); | 100 mUserAgent = userAgent; |
101 return this; | |
71 } | 102 } |
72 | 103 |
73 String getUserAgent() { | 104 String getUserAgent() { |
74 return mConfig.optString(CronetEngineBuilderList.USER_AGENT); | 105 return mUserAgent; |
75 } | 106 } |
76 | 107 |
77 /** | 108 /** |
78 * Sets directory for HTTP Cache and Cookie Storage. The directory must | 109 * Sets directory for HTTP Cache and Cookie Storage. The directory must |
79 * exist. | 110 * exist. |
80 * <p> | 111 * <p> |
81 * <b>NOTE:</b> Do not use the same storage directory with more than one | 112 * <b>NOTE:</b> Do not use the same storage directory with more than one |
82 * {@code CronetEngine} at a time. Access to the storage directory does | 113 * {@code CronetEngine} at a time. Access to the storage directory does |
83 * not support concurrent access by multiple {@code CronetEngine}s. | 114 * not support concurrent access by multiple {@code CronetEngine}s. |
84 * | 115 * |
85 * @param value path to existing directory. | 116 * @param value path to existing directory. |
86 * @return the builder to facilitate chaining. | 117 * @return the builder to facilitate chaining. |
87 */ | 118 */ |
88 public Builder setStoragePath(String value) { | 119 public Builder setStoragePath(String value) { |
89 if (!new File(value).isDirectory()) { | 120 if (!new File(value).isDirectory()) { |
90 throw new IllegalArgumentException( | 121 throw new IllegalArgumentException( |
91 "Storage path must be set to existing directory"); | 122 "Storage path must be set to existing directory"); |
92 } | 123 } |
93 | 124 mStoragePath = value; |
94 return putString(CronetEngineBuilderList.STORAGE_PATH, value); | 125 return this; |
95 } | 126 } |
96 | 127 |
97 String storagePath() { | 128 String storagePath() { |
98 return mConfig.optString(CronetEngineBuilderList.STORAGE_PATH); | 129 return mStoragePath; |
99 } | 130 } |
100 | 131 |
101 /** | 132 /** |
102 * Sets whether falling back to implementation based on system's | 133 * Sets whether falling back to implementation based on system's |
103 * {@link java.net.HttpURLConnection} implementation is enabled. | 134 * {@link java.net.HttpURLConnection} implementation is enabled. |
104 * Defaults to disabled. | 135 * Defaults to disabled. |
105 * @return the builder to facilitate chaining. | 136 * @return the builder to facilitate chaining. |
106 * @deprecated Not supported by the new API. | 137 * @deprecated Not supported by the new API. |
107 */ | 138 */ |
108 @Deprecated | 139 @Deprecated |
109 public Builder enableLegacyMode(boolean value) { | 140 public Builder enableLegacyMode(boolean value) { |
110 return putBoolean(CronetEngineBuilderList.ENABLE_LEGACY_MODE, value) ; | 141 mLegacyModeEnabled = value; |
142 return this; | |
111 } | 143 } |
112 | 144 |
113 boolean legacyMode() { | 145 boolean legacyMode() { |
114 return mConfig.optBoolean(CronetEngineBuilderList.ENABLE_LEGACY_MODE ); | 146 return mLegacyModeEnabled; |
115 } | 147 } |
116 | 148 |
117 /** | 149 /** |
118 * Overrides the name of the native library backing Cronet. | 150 * Overrides the name of the native library backing Cronet. |
119 * @return the builder to facilitate chaining. | 151 * @return the builder to facilitate chaining. |
120 */ | 152 */ |
121 Builder setLibraryName(String libName) { | 153 Builder setLibraryName(String libName) { |
122 return putString(CronetEngineBuilderList.NATIVE_LIBRARY_NAME, libNam e); | 154 mLibraryName = libName; |
155 return this; | |
123 } | 156 } |
124 | 157 |
125 String libraryName() { | 158 String libraryName() { |
126 return mConfig.optString(CronetEngineBuilderList.NATIVE_LIBRARY_NAME , "cronet"); | 159 return mLibraryName; |
127 } | 160 } |
128 | 161 |
129 /** | 162 /** |
130 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l | 163 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l |
131 * is enabled. Defaults to disabled. | 164 * is enabled. Defaults to disabled. |
132 * @return the builder to facilitate chaining. | 165 * @return the builder to facilitate chaining. |
133 */ | 166 */ |
134 public Builder enableQUIC(boolean value) { | 167 public Builder enableQUIC(boolean value) { |
135 return putBoolean(CronetEngineBuilderList.ENABLE_QUIC, value); | 168 mQuicEnabled = value; |
169 return this; | |
170 } | |
171 | |
172 boolean quicEnabled() { | |
173 return mQuicEnabled; | |
136 } | 174 } |
137 | 175 |
138 /** | 176 /** |
139 * Sets whether <a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a> | 177 * Sets whether <a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a> |
140 * protocol is enabled. Defaults to enabled. | 178 * protocol is enabled. Defaults to enabled. |
141 * @return the builder to facilitate chaining. | 179 * @return the builder to facilitate chaining. |
142 */ | 180 */ |
143 public Builder enableHTTP2(boolean value) { | 181 public Builder enableHTTP2(boolean value) { |
144 return putBoolean(CronetEngineBuilderList.ENABLE_SPDY, value); | 182 mHttp2Enabled = value; |
183 return this; | |
184 } | |
185 | |
186 boolean http2Enabled() { | |
187 return mHttp2Enabled; | |
145 } | 188 } |
146 | 189 |
147 /** | 190 /** |
148 * Sets whether | 191 * Sets whether |
149 * <a | 192 * <a |
150 * href="https://lists.w3.org/Archives/Public/ietf-http-wg/2008JulSep/at t-0441/Shared_Dictionary_Compression_over_HTTP.pdf"> | 193 * href="https://lists.w3.org/Archives/Public/ietf-http-wg/2008JulSep/at t-0441/Shared_Dictionary_Compression_over_HTTP.pdf"> |
151 * SDCH</a> compression is enabled. Defaults to disabled. | 194 * SDCH</a> compression is enabled. Defaults to disabled. |
152 * @return the builder to facilitate chaining. | 195 * @return the builder to facilitate chaining. |
153 */ | 196 */ |
154 public Builder enableSDCH(boolean value) { | 197 public Builder enableSDCH(boolean value) { |
155 return putBoolean(CronetEngineBuilderList.ENABLE_SDCH, value); | 198 mSdchEnabled = value; |
199 return this; | |
200 } | |
201 | |
202 boolean sdchEnabled() { | |
203 return mSdchEnabled; | |
156 } | 204 } |
157 | 205 |
158 /** | 206 /** |
159 * Enables | 207 * Enables |
160 * <a href="https://developer.chrome.com/multidevice/data-compression">D ata | 208 * <a href="https://developer.chrome.com/multidevice/data-compression">D ata |
161 * Reduction Proxy</a>. Defaults to disabled. | 209 * Reduction Proxy</a>. Defaults to disabled. |
162 * @param key key to use when authenticating with the proxy. | 210 * @param key key to use when authenticating with the proxy. |
163 * @return the builder to facilitate chaining. | 211 * @return the builder to facilitate chaining. |
164 */ | 212 */ |
165 public Builder enableDataReductionProxy(String key) { | 213 public Builder enableDataReductionProxy(String key) { |
166 return (putString(CronetEngineBuilderList.DATA_REDUCTION_PROXY_KEY, key)); | 214 mDataReductionProxyKey = key; |
215 return this; | |
216 } | |
217 | |
218 String dataReductionProxyKey() { | |
219 return mDataReductionProxyKey; | |
167 } | 220 } |
168 | 221 |
169 /** | 222 /** |
170 * Overrides | 223 * Overrides |
171 * <a href="https://developer.chrome.com/multidevice/data-compression"> | 224 * <a href="https://developer.chrome.com/multidevice/data-compression"> |
172 * Data Reduction Proxy</a> configuration parameters with a primary | 225 * Data Reduction Proxy</a> configuration parameters with a primary |
173 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s | 226 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s |
174 * are specified as [scheme://]host[:port]. Used for testing. | 227 * are specified as [scheme://]host[:port]. Used for testing. |
175 * @param primaryProxy the primary data reduction proxy to use. | 228 * @param primaryProxy the primary data reduction proxy to use. |
176 * @param fallbackProxy a fallback data reduction proxy to use. | 229 * @param fallbackProxy a fallback data reduction proxy to use. |
177 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure | 230 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure |
178 * proxy is allowed. | 231 * proxy is allowed. |
179 * @return the builder to facilitate chaining. | 232 * @return the builder to facilitate chaining. |
180 * @hide | 233 * @hide |
181 * @deprecated Marked as deprecated because @hide doesn't properly hide but | 234 * @deprecated Marked as deprecated because @hide doesn't properly hide but |
182 * javadocs are built with nodeprecated="yes". | 235 * javadocs are built with nodeprecated="yes". |
183 */ | 236 */ |
184 public Builder setDataReductionProxyOptions( | 237 public Builder setDataReductionProxyOptions( |
185 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) { | 238 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) { |
186 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty() | 239 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty() |
187 || secureProxyCheckUrl.isEmpty()) { | 240 || secureProxyCheckUrl.isEmpty()) { |
188 throw new IllegalArgumentException( | 241 throw new IllegalArgumentException( |
189 "Primary and fallback proxies and check url must be set" ); | 242 "Primary and fallback proxies and check url must be set" ); |
190 } | 243 } |
191 putString(CronetEngineBuilderList.DATA_REDUCTION_PRIMARY_PROXY, prim aryProxy); | 244 mDataReductionProxyPrimaryProxy = primaryProxy; |
192 putString(CronetEngineBuilderList.DATA_REDUCTION_FALLBACK_PROXY, fal lbackProxy); | 245 mDataReductionProxyFallbackProxy = fallbackProxy; |
193 putString(CronetEngineBuilderList.DATA_REDUCTION_SECURE_PROXY_CHECK_ URL, | 246 mDataReductionProxySecureProxyCheckUrl = secureProxyCheckUrl; |
194 secureProxyCheckUrl); | |
195 return this; | 247 return this; |
196 } | 248 } |
197 | 249 |
250 String dataReductionProxyPrimaryProxy() { | |
251 return mDataReductionProxyPrimaryProxy; | |
252 } | |
253 | |
254 String dataReductionProxyFallbackProxy() { | |
255 return mDataReductionProxyFallbackProxy; | |
256 } | |
257 | |
258 String dataReductionProxySecureProxyCheckUrl() { | |
259 return mDataReductionProxySecureProxyCheckUrl; | |
260 } | |
261 | |
198 /** @deprecated not really deprecated but hidden. */ | 262 /** @deprecated not really deprecated but hidden. */ |
199 @IntDef({ | 263 @IntDef({ |
200 HTTP_CACHE_DISABLED, HTTP_CACHE_IN_MEMORY, HTTP_CACHE_DISK_NO_HT TP, HTTP_CACHE_DISK, | 264 HTTP_CACHE_DISABLED, HTTP_CACHE_IN_MEMORY, HTTP_CACHE_DISK_NO_HT TP, HTTP_CACHE_DISK, |
201 }) | 265 }) |
202 @Retention(RetentionPolicy.SOURCE) | 266 @Retention(RetentionPolicy.SOURCE) |
203 public @interface HttpCacheSetting {} | 267 public @interface HttpCacheSetting {} |
204 | 268 |
205 /** | 269 /** |
206 * Setting to disable HTTP cache. Some data may still be temporarily sto red in memory. | 270 * Setting to disable HTTP cache. Some data may still be temporarily sto red in memory. |
207 * Passed to {@link #enableHttpCache}. | 271 * Passed to {@link #enableHttpCache}. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 public Builder enableHttpCache(@HttpCacheSetting int cacheMode, long max Size) { | 304 public Builder enableHttpCache(@HttpCacheSetting int cacheMode, long max Size) { |
241 if (cacheMode == HTTP_CACHE_DISK || cacheMode == HTTP_CACHE_DISK_NO_ HTTP) { | 305 if (cacheMode == HTTP_CACHE_DISK || cacheMode == HTTP_CACHE_DISK_NO_ HTTP) { |
242 if (storagePath().isEmpty()) { | 306 if (storagePath().isEmpty()) { |
243 throw new IllegalArgumentException("Storage path must be set "); | 307 throw new IllegalArgumentException("Storage path must be set "); |
244 } | 308 } |
245 } else { | 309 } else { |
246 if (!storagePath().isEmpty()) { | 310 if (!storagePath().isEmpty()) { |
247 throw new IllegalArgumentException("Storage path must be emp ty"); | 311 throw new IllegalArgumentException("Storage path must be emp ty"); |
248 } | 312 } |
249 } | 313 } |
250 putBoolean(CronetEngineBuilderList.LOAD_DISABLE_CACHE, | 314 mDisableCache = |
251 cacheMode == HTTP_CACHE_DISABLED || cacheMode == HTTP_CACHE_ DISK_NO_HTTP); | 315 (cacheMode == HTTP_CACHE_DISABLED || cacheMode == HTTP_CACHE _DISK_NO_HTTP); |
252 putLong(CronetEngineBuilderList.HTTP_CACHE_MAX_SIZE, maxSize); | 316 mHttpCacheMaxSize = maxSize; |
253 | 317 |
254 switch (cacheMode) { | 318 switch (cacheMode) { |
255 case HTTP_CACHE_DISABLED: | 319 case HTTP_CACHE_DISABLED: |
256 return putString(CronetEngineBuilderList.HTTP_CACHE, | 320 mHttpCacheMode = HttpCacheType.DISABLED; |
257 CronetEngineBuilderList.HTTP_CACHE_DISABLED); | 321 break; |
258 case HTTP_CACHE_DISK_NO_HTTP: | 322 case HTTP_CACHE_DISK_NO_HTTP: |
259 case HTTP_CACHE_DISK: | 323 case HTTP_CACHE_DISK: |
260 return putString(CronetEngineBuilderList.HTTP_CACHE, | 324 mHttpCacheMode = HttpCacheType.DISK; |
261 CronetEngineBuilderList.HTTP_CACHE_DISK); | 325 break; |
262 | |
263 case HTTP_CACHE_IN_MEMORY: | 326 case HTTP_CACHE_IN_MEMORY: |
264 return putString(CronetEngineBuilderList.HTTP_CACHE, | 327 mHttpCacheMode = HttpCacheType.MEMORY; |
265 CronetEngineBuilderList.HTTP_CACHE_MEMORY); | 328 break; |
329 default: | |
330 throw new IllegalArgumentException("Unknown cache mode"); | |
266 } | 331 } |
267 return this; | 332 return this; |
268 } | 333 } |
269 | 334 |
335 boolean cacheDisabled() { | |
336 return mDisableCache; | |
337 } | |
338 | |
339 long httpCacheMaxSize() { | |
340 return mHttpCacheMaxSize; | |
341 } | |
342 | |
343 int httpCacheMode() { | |
344 return mHttpCacheMode; | |
345 } | |
346 | |
270 /** | 347 /** |
271 * Adds hint that {@code host} supports QUIC. | 348 * Adds hint that {@code host} supports QUIC. |
272 * Note that {@link #enableHttpCache enableHttpCache} | 349 * Note that {@link #enableHttpCache enableHttpCache} |
273 * ({@link HttpCache#DISK DISK}) is needed to take advantage of 0-RTT | 350 * ({@link HttpCache#DISK DISK}) is needed to take advantage of 0-RTT |
274 * connection establishment between sessions. | 351 * connection establishment between sessions. |
275 * | 352 * |
276 * @param host hostname of the server that supports QUIC. | 353 * @param host hostname of the server that supports QUIC. |
277 * @param port host of the server that supports QUIC. | 354 * @param port host of the server that supports QUIC. |
278 * @param alternatePort alternate port to use for QUIC. | 355 * @param alternatePort alternate port to use for QUIC. |
279 * @return the builder to facilitate chaining. | 356 * @return the builder to facilitate chaining. |
280 */ | 357 */ |
281 public Builder addQuicHint(String host, int port, int alternatePort) { | 358 public Builder addQuicHint(String host, int port, int alternatePort) { |
282 if (host.contains("/")) { | 359 if (host.contains("/")) { |
283 throw new IllegalArgumentException("Illegal QUIC Hint Host: " + host); | 360 throw new IllegalArgumentException("Illegal QUIC Hint Host: " + host); |
284 } | 361 } |
285 try { | 362 mQuicHints.add(new QuicHint(host, port, alternatePort)); |
286 JSONArray quicHints = mConfig.optJSONArray(CronetEngineBuilderLi st.QUIC_HINTS); | 363 return this; |
287 if (quicHints == null) { | 364 } |
288 quicHints = new JSONArray(); | |
289 mConfig.put(CronetEngineBuilderList.QUIC_HINTS, quicHints); | |
290 } | |
291 | 365 |
292 JSONObject hint = new JSONObject(); | 366 List<QuicHint> quicHints() { |
293 hint.put(CronetEngineBuilderList.QUIC_HINT_HOST, host); | 367 return mQuicHints; |
294 hint.put(CronetEngineBuilderList.QUIC_HINT_PORT, port); | |
295 hint.put(CronetEngineBuilderList.QUIC_HINT_ALT_PORT, alternatePo rt); | |
296 quicHints.put(hint); | |
297 } catch (JSONException e) { | |
298 // Intentionally do nothing. | |
299 } | |
300 return this; | |
301 } | 368 } |
302 | 369 |
303 /** | 370 /** |
304 * Sets experimental QUIC connection options, overwriting any pre-existi ng | 371 * Sets experimental QUIC connection options, overwriting any pre-existi ng |
305 * options. List of options is subject to change. | 372 * options. List of options is subject to change. |
306 * | 373 * |
307 * @param quicConnectionOptions comma-separated QUIC options (for exampl e | 374 * @param quicConnectionOptions comma-separated QUIC options (for exampl e |
308 * "PACE,IW10") to use if QUIC is enabled. | 375 * "PACE,IW10") to use if QUIC is enabled. |
309 * @return the builder to facilitate chaining. | 376 * @return the builder to facilitate chaining. |
310 */ | 377 */ |
311 public Builder setExperimentalQuicConnectionOptions(String quicConnectio nOptions) { | 378 public Builder setExperimentalQuicConnectionOptions(String quicConnectio nOptions) { |
312 return putString(CronetEngineBuilderList.QUIC_OPTIONS, quicConnectio nOptions); | 379 mExperimentalQuicConnectionOptions = quicConnectionOptions; |
380 return this; | |
381 } | |
382 | |
383 String experimentalQuicConnectionOptions() { | |
384 return mExperimentalQuicConnectionOptions; | |
313 } | 385 } |
314 | 386 |
315 /** | 387 /** |
316 * Sets a native MockCertVerifier for testing. | 388 * Sets a native MockCertVerifier for testing. |
317 */ | 389 */ |
318 Builder setMockCertVerifierForTesting(long mockCertVerifier) { | 390 Builder setMockCertVerifierForTesting(long mockCertVerifier) { |
319 return putString( | 391 mMockCertVerifier = mockCertVerifier; |
320 CronetEngineBuilderList.MOCK_CERT_VERIFIER, String.valueOf(m ockCertVerifier)); | 392 return this; |
393 } | |
394 | |
395 long mockCertVerifier() { | |
396 return mMockCertVerifier; | |
321 } | 397 } |
322 | 398 |
323 /** | 399 /** |
324 * Gets a JSON string representation of the builder. | |
325 */ | |
326 String toJSONString() { | |
327 return mConfig.toString(); | |
328 } | |
329 | |
330 /** | |
331 * Returns {@link Context} for builder. | 400 * Returns {@link Context} for builder. |
332 * | 401 * |
333 * @return {@link Context} for builder. | 402 * @return {@link Context} for builder. |
334 */ | 403 */ |
335 Context getContext() { | 404 Context getContext() { |
336 return mContext; | 405 return mContext; |
337 } | 406 } |
338 | 407 |
339 /** | 408 /** |
340 * Sets a boolean value in the config. Returns a reference to the same | |
341 * config object, so you can chain put calls together. | |
342 * @return the builder to facilitate chaining. | |
343 */ | |
344 private Builder putBoolean(String key, boolean value) { | |
345 try { | |
346 mConfig.put(key, value); | |
347 } catch (JSONException e) { | |
348 // Intentionally do nothing. | |
349 } | |
350 return this; | |
351 } | |
352 | |
353 /** | |
354 * Sets a long value in the config. Returns a reference to the same | |
355 * config object, so you can chain put calls together. | |
356 * @return the builder to facilitate chaining. | |
357 */ | |
358 private Builder putLong(String key, long value) { | |
359 try { | |
360 mConfig.put(key, value); | |
361 } catch (JSONException e) { | |
362 // Intentionally do nothing. | |
363 } | |
364 return this; | |
365 } | |
366 | |
367 /** | |
368 * Sets a string value in the config. Returns a reference to the same | |
369 * config object, so you can chain put calls together. | |
370 * @return the builder to facilitate chaining. | |
371 */ | |
372 private Builder putString(String key, String value) { | |
373 try { | |
374 mConfig.put(key, value); | |
375 } catch (JSONException e) { | |
376 // Intentionally do nothing. | |
377 } | |
378 return this; | |
379 } | |
380 | |
381 /** | |
382 * Build a {@link CronetEngine} using this builder's configuration. | 409 * Build a {@link CronetEngine} using this builder's configuration. |
383 */ | 410 */ |
384 public CronetEngine build() { | 411 public CronetEngine build() { |
385 return createContext(this); | 412 return createContext(this); |
386 } | 413 } |
387 } | 414 } |
388 | 415 |
389 private static final String TAG = "UrlRequestFactory"; | 416 private static final String TAG = "UrlRequestFactory"; |
390 private static final String CRONET_URL_REQUEST_CONTEXT = | 417 private static final String CRONET_URL_REQUEST_CONTEXT = |
391 "org.chromium.net.CronetUrlRequestContext"; | 418 "org.chromium.net.CronetUrlRequestContext"; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 cronetEngine = possibleEngine; | 689 cronetEngine = possibleEngine; |
663 } | 690 } |
664 } catch (ClassNotFoundException e) { | 691 } catch (ClassNotFoundException e) { |
665 // Leave as null. | 692 // Leave as null. |
666 } catch (Exception e) { | 693 } catch (Exception e) { |
667 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); | 694 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); |
668 } | 695 } |
669 return cronetEngine; | 696 return cronetEngine; |
670 } | 697 } |
671 } | 698 } |
OLD | NEW |