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

Side by Side Diff: components/cronet/android/api/src/org/chromium/net/CronetEngine.java

Issue 1849753002: [Cronet] Separate Cronet implementation and API by package name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 4 years, 5 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 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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.net.http.HttpResponseCache; 9 import android.net.http.HttpResponseCache;
10 import android.support.annotation.IntDef; 10 import android.support.annotation.IntDef;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 * older devices. 54 * older devices.
55 */ 55 */
56 public abstract static class LibraryLoader { 56 public abstract static class LibraryLoader {
57 /** 57 /**
58 * Loads the native library. 58 * Loads the native library.
59 * @param libName name of the library to load 59 * @param libName name of the library to load
60 */ 60 */
61 public abstract void loadLibrary(String libName); 61 public abstract void loadLibrary(String libName);
62 } 62 }
63 63
64 // A hint that a host supports QUIC. 64 /**
65 static class QuicHint { 65 * A hint that a host supports QUIC.
66 * @hide only used by internal implementation.
67 */
68 public static class QuicHint {
66 // The host. 69 // The host.
67 final String mHost; 70 public final String mHost;
68 // Port of the server that supports QUIC. 71 // Port of the server that supports QUIC.
69 final int mPort; 72 public final int mPort;
70 // Alternate protocol port. 73 // Alternate protocol port.
71 final int mAlternatePort; 74 public final int mAlternatePort;
72 75
73 QuicHint(String host, int port, int alternatePort) { 76 QuicHint(String host, int port, int alternatePort) {
74 mHost = host; 77 mHost = host;
75 mPort = port; 78 mPort = port;
76 mAlternatePort = alternatePort; 79 mAlternatePort = alternatePort;
77 } 80 }
78 } 81 }
79 82
80 // A public key pin. 83 /**
81 static class Pkp { 84 * A public key pin.
85 * @hide only used by internal implementation.
86 */
87 public static class Pkp {
82 // Host to pin for. 88 // Host to pin for.
83 final String mHost; 89 public final String mHost;
84 // Array of SHA-256 hashes of keys. 90 // Array of SHA-256 hashes of keys.
85 final byte[][] mHashes; 91 public final byte[][] mHashes;
86 // Should pin apply to subdomains? 92 // Should pin apply to subdomains?
87 final boolean mIncludeSubdomains; 93 public final boolean mIncludeSubdomains;
88 // When the pin expires. 94 // When the pin expires.
89 final Date mExpirationDate; 95 public final Date mExpirationDate;
90 96
91 Pkp(String host, byte[][] hashes, boolean includeSubdomains, Date ex pirationDate) { 97 Pkp(String host, byte[][] hashes, boolean includeSubdomains, Date ex pirationDate) {
92 mHost = host; 98 mHost = host;
93 mHashes = hashes; 99 mHashes = hashes;
94 mIncludeSubdomains = includeSubdomains; 100 mIncludeSubdomains = includeSubdomains;
95 mExpirationDate = expirationDate; 101 mExpirationDate = expirationDate;
96 } 102 }
97 } 103 }
98 104
99 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[ 0-9\\.]*$"); 105 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[ 0-9\\.]*$");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 * using this function. 163 * using this function.
158 * 164 *
159 * @param userAgent the User-Agent string to use for all requests. 165 * @param userAgent the User-Agent string to use for all requests.
160 * @return the builder to facilitate chaining. 166 * @return the builder to facilitate chaining.
161 */ 167 */
162 public Builder setUserAgent(String userAgent) { 168 public Builder setUserAgent(String userAgent) {
163 mUserAgent = userAgent; 169 mUserAgent = userAgent;
164 return this; 170 return this;
165 } 171 }
166 172
167 String getUserAgent() { 173 /**
174 * @hide only used by internal implementation.
175 */
176 public String getUserAgent() {
168 return mUserAgent; 177 return mUserAgent;
169 } 178 }
170 179
171 /** 180 /**
172 * Sets directory for HTTP Cache and Cookie Storage. The directory must 181 * Sets directory for HTTP Cache and Cookie Storage. The directory must
173 * exist. 182 * exist.
174 * <p> 183 * <p>
175 * <b>NOTE:</b> Do not use the same storage directory with more than one 184 * <b>NOTE:</b> Do not use the same storage directory with more than one
176 * {@code CronetEngine} at a time. Access to the storage directory does 185 * {@code CronetEngine} at a time. Access to the storage directory does
177 * not support concurrent access by multiple {@code CronetEngine}s. 186 * not support concurrent access by multiple {@code CronetEngine}s.
178 * 187 *
179 * @param value path to existing directory. 188 * @param value path to existing directory.
180 * @return the builder to facilitate chaining. 189 * @return the builder to facilitate chaining.
181 */ 190 */
182 public Builder setStoragePath(String value) { 191 public Builder setStoragePath(String value) {
183 if (!new File(value).isDirectory()) { 192 if (!new File(value).isDirectory()) {
184 throw new IllegalArgumentException( 193 throw new IllegalArgumentException(
185 "Storage path must be set to existing directory"); 194 "Storage path must be set to existing directory");
186 } 195 }
187 mStoragePath = value; 196 mStoragePath = value;
188 return this; 197 return this;
189 } 198 }
190 199
191 String storagePath() { 200 /**
201 * @hide only used by internal implementation.
202 */
203 public String storagePath() {
192 return mStoragePath; 204 return mStoragePath;
193 } 205 }
194 206
195 /** 207 /**
196 * Sets whether the resulting {@link CronetEngine} uses an 208 * Sets whether the resulting {@link CronetEngine} uses an
197 * implementation based on the system's 209 * implementation based on the system's
198 * {@link java.net.HttpURLConnection} implementation, or if this is 210 * {@link java.net.HttpURLConnection} implementation, or if this is
199 * only done as a backup if the native implementation fails to load. 211 * only done as a backup if the native implementation fails to load.
200 * Defaults to disabled. 212 * Defaults to disabled.
201 * @param value {@code true} makes the resulting {@link CronetEngine} 213 * @param value {@code true} makes the resulting {@link CronetEngine}
202 * use an implementation based on the system's 214 * use an implementation based on the system's
203 * {@link java.net.HttpURLConnection} implementation 215 * {@link java.net.HttpURLConnection} implementation
204 * without trying to load the native implementation. 216 * without trying to load the native implementation.
205 * {@code false} makes the resulting {@code CronetEngine} 217 * {@code false} makes the resulting {@code CronetEngine}
206 * use the native implementation, or if that fails to load, 218 * use the native implementation, or if that fails to load,
207 * falls back to an implementation based on the system's 219 * falls back to an implementation based on the system's
208 * {@link java.net.HttpURLConnection} implementation. 220 * {@link java.net.HttpURLConnection} implementation.
209 * @return the builder to facilitate chaining. 221 * @return the builder to facilitate chaining.
210 * @deprecated Not supported by the new API. 222 * @deprecated Not supported by the new API.
211 * @hide 223 * @hide
212 */ 224 */
213 @Deprecated 225 @Deprecated
214 public Builder enableLegacyMode(boolean value) { 226 public Builder enableLegacyMode(boolean value) {
215 mLegacyModeEnabled = value; 227 mLegacyModeEnabled = value;
216 return this; 228 return this;
217 } 229 }
218 230
219 boolean legacyMode() { 231 /**
232 * @hide only used by internal implementation.
233 */
234 public boolean legacyMode() {
220 return mLegacyModeEnabled; 235 return mLegacyModeEnabled;
221 } 236 }
222 237
223 /** 238 /**
224 * Overrides the name of the native library backing Cronet. 239 * Overrides the name of the native library backing Cronet.
225 * @param libName the name of the native library backing Cronet. 240 * @param libName the name of the native library backing Cronet.
226 * @return the builder to facilitate chaining. 241 * @return the builder to facilitate chaining.
242 * @hide only used by internal implementation.
227 */ 243 */
228 Builder setLibraryName(String libName) { 244 public Builder setLibraryName(String libName) {
229 mLibraryName = libName; 245 mLibraryName = libName;
230 return this; 246 return this;
231 } 247 }
232 248
233 /** 249 /**
234 * Sets a {@link LibraryLoader} to be used to load the native library. 250 * Sets a {@link LibraryLoader} to be used to load the native library.
235 * If not set, the library will be loaded using {@link System#loadLibrar y}. 251 * If not set, the library will be loaded using {@link System#loadLibrar y}.
236 * @param loader {@code LibraryLoader} to be used to load the native lib rary. 252 * @param loader {@code LibraryLoader} to be used to load the native lib rary.
237 * @return the builder to facilitate chaining. 253 * @return the builder to facilitate chaining.
238 */ 254 */
239 public Builder setLibraryLoader(LibraryLoader loader) { 255 public Builder setLibraryLoader(LibraryLoader loader) {
240 mLibraryLoader = loader; 256 mLibraryLoader = loader;
241 return this; 257 return this;
242 } 258 }
243 259
244 void loadLibrary() { 260 /**
261 * @hide only used by internal implementation.
262 */
263 public void loadLibrary() {
245 if (mLibraryLoader == null) { 264 if (mLibraryLoader == null) {
246 System.loadLibrary(mLibraryName); 265 System.loadLibrary(mLibraryName);
247 } else { 266 } else {
248 mLibraryLoader.loadLibrary(mLibraryName); 267 mLibraryLoader.loadLibrary(mLibraryName);
249 } 268 }
250 } 269 }
251 270
252 /** 271 /**
253 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l 272 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l
254 * is enabled. Defaults to disabled. If QUIC is enabled, then QUIC User Agent Id 273 * is enabled. Defaults to disabled. If QUIC is enabled, then QUIC User Agent Id
255 * containing application name and Cronet version is sent to the server. 274 * containing application name and Cronet version is sent to the server.
256 * @param value {@code true} to enable QUIC, {@code false} to disable. 275 * @param value {@code true} to enable QUIC, {@code false} to disable.
257 * @return the builder to facilitate chaining. 276 * @return the builder to facilitate chaining.
258 */ 277 */
259 public Builder enableQUIC(boolean value) { 278 public Builder enableQUIC(boolean value) {
260 mQuicEnabled = value; 279 mQuicEnabled = value;
261 return this; 280 return this;
262 } 281 }
263 282
264 boolean quicEnabled() { 283 /**
284 * @hide only used by internal implementation.
285 */
286 public boolean quicEnabled() {
265 return mQuicEnabled; 287 return mQuicEnabled;
266 } 288 }
267 289
268 /** 290 /**
269 * Constructs default QUIC User Agent Id string including application na me 291 * Constructs default QUIC User Agent Id string including application na me
270 * and Cronet version. Returns empty string if QUIC is not enabled. 292 * and Cronet version. Returns empty string if QUIC is not enabled.
271 * 293 *
272 * @param context Android {@link Context} to get package name from. 294 * @param context Android {@link Context} to get package name from.
273 * @return QUIC User Agent ID string. 295 * @return QUIC User Agent ID string.
296 * @hide only used by internal implementation.
274 */ 297 */
275 // TODO(mef): remove |context| parameter when legacy ChromiumUrlRequestC ontext is removed. 298 // TODO(mef): remove |context| parameter when legacy ChromiumUrlRequestC ontext is removed.
276 String getDefaultQuicUserAgentId(Context context) { 299 public String getDefaultQuicUserAgentId(Context context) {
277 return mQuicEnabled ? UserAgent.getQuicUserAgentIdFrom(context) : "" ; 300 return mQuicEnabled ? UserAgent.getQuicUserAgentIdFrom(context) : "" ;
278 } 301 }
279 302
280 /** 303 /**
281 * Sets whether <a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a> 304 * Sets whether <a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a>
282 * protocol is enabled. Defaults to enabled. 305 * protocol is enabled. Defaults to enabled.
283 * @param value {@code true} to enable HTTP/2, {@code false} to disable. 306 * @param value {@code true} to enable HTTP/2, {@code false} to disable.
284 * @return the builder to facilitate chaining. 307 * @return the builder to facilitate chaining.
285 */ 308 */
286 public Builder enableHTTP2(boolean value) { 309 public Builder enableHTTP2(boolean value) {
287 mHttp2Enabled = value; 310 mHttp2Enabled = value;
288 return this; 311 return this;
289 } 312 }
290 313
291 boolean http2Enabled() { 314 /**
315 * @hide only used by internal implementation.
316 */
317 public boolean http2Enabled() {
292 return mHttp2Enabled; 318 return mHttp2Enabled;
293 } 319 }
294 320
295 /** 321 /**
296 * Sets whether 322 * Sets whether
297 * <a 323 * <a
298 * href="https://lists.w3.org/Archives/Public/ietf-http-wg/2008JulSep/at t-0441/Shared_Dictionary_Compression_over_HTTP.pdf"> 324 * href="https://lists.w3.org/Archives/Public/ietf-http-wg/2008JulSep/at t-0441/Shared_Dictionary_Compression_over_HTTP.pdf">
299 * SDCH</a> compression is enabled. Defaults to disabled. 325 * SDCH</a> compression is enabled. Defaults to disabled.
300 * @param value {@code true} to enable SDCH, {@code false} to disable. 326 * @param value {@code true} to enable SDCH, {@code false} to disable.
301 * @return the builder to facilitate chaining. 327 * @return the builder to facilitate chaining.
302 */ 328 */
303 public Builder enableSDCH(boolean value) { 329 public Builder enableSDCH(boolean value) {
304 mSdchEnabled = value; 330 mSdchEnabled = value;
305 return this; 331 return this;
306 } 332 }
307 333
308 boolean sdchEnabled() { 334 /**
335 * @hide only used by internal implementation.
336 */
337 public boolean sdchEnabled() {
309 return mSdchEnabled; 338 return mSdchEnabled;
310 } 339 }
311 340
312 /** 341 /**
313 * Enables 342 * Enables
314 * <a href="https://developer.chrome.com/multidevice/data-compression">D ata 343 * <a href="https://developer.chrome.com/multidevice/data-compression">D ata
315 * Reduction Proxy</a>. Defaults to disabled. 344 * Reduction Proxy</a>. Defaults to disabled.
316 * @param key key to use when authenticating with the proxy. 345 * @param key key to use when authenticating with the proxy.
317 * @return the builder to facilitate chaining. 346 * @return the builder to facilitate chaining.
318 */ 347 */
319 public Builder enableDataReductionProxy(String key) { 348 public Builder enableDataReductionProxy(String key) {
320 mDataReductionProxyKey = key; 349 mDataReductionProxyKey = key;
321 return this; 350 return this;
322 } 351 }
323 352
324 String dataReductionProxyKey() { 353 /**
354 * @hide only used by internal implementation.
355 */
356 public String dataReductionProxyKey() {
325 return mDataReductionProxyKey; 357 return mDataReductionProxyKey;
326 } 358 }
327 359
328 /** 360 /**
329 * Overrides 361 * Overrides
330 * <a href="https://developer.chrome.com/multidevice/data-compression"> 362 * <a href="https://developer.chrome.com/multidevice/data-compression">
331 * Data Reduction Proxy</a> configuration parameters with a primary 363 * Data Reduction Proxy</a> configuration parameters with a primary
332 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s 364 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s
333 * are specified as [scheme://]host[:port]. Used for testing. 365 * are specified as [scheme://]host[:port]. Used for testing.
334 * @param primaryProxy the primary data reduction proxy to use. 366 * @param primaryProxy the primary data reduction proxy to use.
335 * @param fallbackProxy a fallback data reduction proxy to use. 367 * @param fallbackProxy a fallback data reduction proxy to use.
336 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure 368 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure
337 * proxy is allowed. 369 * proxy is allowed.
338 * @return the builder to facilitate chaining. 370 * @return the builder to facilitate chaining.
339 * @hide as it's a prototype. 371 * @hide as it's a prototype.
340 */ 372 */
341 public Builder setDataReductionProxyOptions( 373 public Builder setDataReductionProxyOptions(
342 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) { 374 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) {
343 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty() 375 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty()
344 || secureProxyCheckUrl.isEmpty()) { 376 || secureProxyCheckUrl.isEmpty()) {
345 throw new IllegalArgumentException( 377 throw new IllegalArgumentException(
346 "Primary and fallback proxies and check url must be set" ); 378 "Primary and fallback proxies and check url must be set" );
347 } 379 }
348 mDataReductionProxyPrimaryProxy = primaryProxy; 380 mDataReductionProxyPrimaryProxy = primaryProxy;
349 mDataReductionProxyFallbackProxy = fallbackProxy; 381 mDataReductionProxyFallbackProxy = fallbackProxy;
350 mDataReductionProxySecureProxyCheckUrl = secureProxyCheckUrl; 382 mDataReductionProxySecureProxyCheckUrl = secureProxyCheckUrl;
351 return this; 383 return this;
352 } 384 }
353 385
354 String dataReductionProxyPrimaryProxy() { 386 /**
387 * @hide only used by internal implementation.
388 */
389 public String dataReductionProxyPrimaryProxy() {
355 return mDataReductionProxyPrimaryProxy; 390 return mDataReductionProxyPrimaryProxy;
356 } 391 }
357 392
358 String dataReductionProxyFallbackProxy() { 393 /**
394 * @hide only used by internal implementation.
395 */
396 public String dataReductionProxyFallbackProxy() {
359 return mDataReductionProxyFallbackProxy; 397 return mDataReductionProxyFallbackProxy;
360 } 398 }
361 399
362 String dataReductionProxySecureProxyCheckUrl() { 400 /**
401 * @hide only used by internal implementation.
402 */
403 public String dataReductionProxySecureProxyCheckUrl() {
363 return mDataReductionProxySecureProxyCheckUrl; 404 return mDataReductionProxySecureProxyCheckUrl;
364 } 405 }
365 406
366 /** @hide */ 407 /** @hide */
367 @IntDef({ 408 @IntDef({
368 HTTP_CACHE_DISABLED, HTTP_CACHE_IN_MEMORY, HTTP_CACHE_DISK_NO_HT TP, HTTP_CACHE_DISK, 409 HTTP_CACHE_DISABLED, HTTP_CACHE_IN_MEMORY, HTTP_CACHE_DISK_NO_HT TP, HTTP_CACHE_DISK,
369 }) 410 })
370 @Retention(RetentionPolicy.SOURCE) 411 @Retention(RetentionPolicy.SOURCE)
371 public @interface HttpCacheSetting {} 412 public @interface HttpCacheSetting {}
372 413
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 break; 470 break;
430 case HTTP_CACHE_IN_MEMORY: 471 case HTTP_CACHE_IN_MEMORY:
431 mHttpCacheMode = HttpCacheType.MEMORY; 472 mHttpCacheMode = HttpCacheType.MEMORY;
432 break; 473 break;
433 default: 474 default:
434 throw new IllegalArgumentException("Unknown cache mode"); 475 throw new IllegalArgumentException("Unknown cache mode");
435 } 476 }
436 return this; 477 return this;
437 } 478 }
438 479
439 boolean cacheDisabled() { 480 /**
481 * @hide only used by internal implementation.
482 */
483 public boolean cacheDisabled() {
440 return mDisableCache; 484 return mDisableCache;
441 } 485 }
442 486
443 long httpCacheMaxSize() { 487 /**
488 * @hide only used by internal implementation.
489 */
490 public long httpCacheMaxSize() {
444 return mHttpCacheMaxSize; 491 return mHttpCacheMaxSize;
445 } 492 }
446 493
447 int httpCacheMode() { 494 /**
495 * @hide only used by internal implementation.
496 */
497 public int httpCacheMode() {
448 return mHttpCacheMode; 498 return mHttpCacheMode;
449 } 499 }
450 500
451 /** 501 /**
452 * Adds hint that {@code host} supports QUIC. 502 * Adds hint that {@code host} supports QUIC.
453 * Note that {@link #enableHttpCache enableHttpCache} 503 * Note that {@link #enableHttpCache enableHttpCache}
454 * ({@link #HTTP_CACHE_DISK}) is needed to take advantage of 0-RTT 504 * ({@link #HTTP_CACHE_DISK}) is needed to take advantage of 0-RTT
455 * connection establishment between sessions. 505 * connection establishment between sessions.
456 * 506 *
457 * @param host hostname of the server that supports QUIC. 507 * @param host hostname of the server that supports QUIC.
458 * @param port host of the server that supports QUIC. 508 * @param port host of the server that supports QUIC.
459 * @param alternatePort alternate port to use for QUIC. 509 * @param alternatePort alternate port to use for QUIC.
460 * @return the builder to facilitate chaining. 510 * @return the builder to facilitate chaining.
461 */ 511 */
462 public Builder addQuicHint(String host, int port, int alternatePort) { 512 public Builder addQuicHint(String host, int port, int alternatePort) {
463 if (host.contains("/")) { 513 if (host.contains("/")) {
464 throw new IllegalArgumentException("Illegal QUIC Hint Host: " + host); 514 throw new IllegalArgumentException("Illegal QUIC Hint Host: " + host);
465 } 515 }
466 mQuicHints.add(new QuicHint(host, port, alternatePort)); 516 mQuicHints.add(new QuicHint(host, port, alternatePort));
467 return this; 517 return this;
468 } 518 }
469 519
470 List<QuicHint> quicHints() { 520 /**
521 * @hide only used by internal implementation.
522 */
523 public List<QuicHint> quicHints() {
471 return mQuicHints; 524 return mQuicHints;
472 } 525 }
473 526
474 /** 527 /**
475 * <p> 528 * <p>
476 * Pins a set of public keys for a given host. By pinning a set of publi c keys, 529 * Pins a set of public keys for a given host. By pinning a set of publi c keys,
477 * {@code pinsSha256}, communication with {@code hostName} is required t o 530 * {@code pinsSha256}, communication with {@code hostName} is required t o
478 * authenticate with a certificate with a public key from the set of pin ned ones. 531 * authenticate with a certificate with a public key from the set of pin ned ones.
479 * An app can pin the public key of the root certificate, any of the int ermediate 532 * An app can pin the public key of the root certificate, any of the int ermediate
480 * certificates or the end-entry certificate. Authentication will fail a nd secure 533 * certificates or the end-entry certificate. Authentication will fail a nd secure
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 587 }
535 // Add new element to PKP list. 588 // Add new element to PKP list.
536 mPkps.add(new Pkp(idnHostName, hashes.toArray(new byte[hashes.size() ][]), 589 mPkps.add(new Pkp(idnHostName, hashes.toArray(new byte[hashes.size() ][]),
537 includeSubdomains, expirationDate)); 590 includeSubdomains, expirationDate));
538 return this; 591 return this;
539 } 592 }
540 593
541 /** 594 /**
542 * Returns list of public key pins. 595 * Returns list of public key pins.
543 * @return list of public key pins. 596 * @return list of public key pins.
597 * @hide only used by internal implementation.
544 */ 598 */
545 List<Pkp> publicKeyPins() { 599 public List<Pkp> publicKeyPins() {
546 return mPkps; 600 return mPkps;
547 } 601 }
548 602
549 /** 603 /**
550 * Enables or disables public key pinning bypass for local trust anchors . Disabling the 604 * Enables or disables public key pinning bypass for local trust anchors . Disabling the
551 * bypass for local trust anchors is highly discouraged since it may pro hibit the app 605 * bypass for local trust anchors is highly discouraged since it may pro hibit the app
552 * from communicating with the pinned hosts. E.g., a user may want to se nd all traffic 606 * from communicating with the pinned hosts. E.g., a user may want to se nd all traffic
553 * through an SSL enabled proxy by changing the device proxy settings an d adding the 607 * through an SSL enabled proxy by changing the device proxy settings an d adding the
554 * proxy certificate to the list of local trust anchor. Disabling the by pass will most 608 * proxy certificate to the list of local trust anchor. Disabling the by pass will most
555 * likly prevent the app from sending any traffic to the pinned hosts. F or more 609 * likly prevent the app from sending any traffic to the pinned hosts. F or more
556 * information see 'How does key pinning interact with local proxies and filters?' at 610 * information see 'How does key pinning interact with local proxies and filters?' at
557 * https://www.chromium.org/Home/chromium-security/security-faq 611 * https://www.chromium.org/Home/chromium-security/security-faq
558 * 612 *
559 * @param value {@code true} to enable the bypass, {@code false} to disa ble. 613 * @param value {@code true} to enable the bypass, {@code false} to disa ble.
560 * @return the builder to facilitate chaining. 614 * @return the builder to facilitate chaining.
561 */ 615 */
562 public Builder enablePublicKeyPinningBypassForLocalTrustAnchors(boolean value) { 616 public Builder enablePublicKeyPinningBypassForLocalTrustAnchors(boolean value) {
563 mPublicKeyPinningBypassForLocalTrustAnchorsEnabled = value; 617 mPublicKeyPinningBypassForLocalTrustAnchorsEnabled = value;
564 return this; 618 return this;
565 } 619 }
566 620
567 boolean publicKeyPinningBypassForLocalTrustAnchorsEnabled() { 621 /**
622 * @hide only used by internal implementation.
623 */
624 public boolean publicKeyPinningBypassForLocalTrustAnchorsEnabled() {
568 return mPublicKeyPinningBypassForLocalTrustAnchorsEnabled; 625 return mPublicKeyPinningBypassForLocalTrustAnchorsEnabled;
569 } 626 }
570 627
571 /** 628 /**
572 * Checks whether a given string represents a valid host name for PKP an d converts it 629 * Checks whether a given string represents a valid host name for PKP an d converts it
573 * to ASCII Compatible Encoding representation according to RFC 1122, RF C 1123 and 630 * to ASCII Compatible Encoding representation according to RFC 1122, RF C 1123 and
574 * RFC 3490. This method is more restrictive than required by RFC 7469. Thus, a host 631 * RFC 3490. This method is more restrictive than required by RFC 7469. Thus, a host
575 * that contains digits and the dot character only is considered invalid . 632 * that contains digits and the dot character only is considered invalid .
576 * 633 *
577 * Note: Currently Cronet doesn't have native implementation of host nam e validation that 634 * Note: Currently Cronet doesn't have native implementation of host nam e validation that
(...skipping 23 matching lines...) Expand all
601 * Sets experimental options to be used in Cronet. 658 * Sets experimental options to be used in Cronet.
602 * 659 *
603 * @param options JSON formatted experimental options. 660 * @param options JSON formatted experimental options.
604 * @return the builder to facilitate chaining. 661 * @return the builder to facilitate chaining.
605 */ 662 */
606 public Builder setExperimentalOptions(String options) { 663 public Builder setExperimentalOptions(String options) {
607 mExperimentalOptions = options; 664 mExperimentalOptions = options;
608 return this; 665 return this;
609 } 666 }
610 667
611 String experimentalOptions() { 668 /**
669 * @hide only used by internal implementation.
670 */
671 public String experimentalOptions() {
612 return mExperimentalOptions; 672 return mExperimentalOptions;
613 } 673 }
614 674
615 /** 675 /**
616 * Sets a native MockCertVerifier for testing. See 676 * Sets a native MockCertVerifier for testing. See
617 * {@code MockCertVerifier.createMockCertVerifier} for a method that 677 * {@code MockCertVerifier.createMockCertVerifier} for a method that
618 * can be used to create a MockCertVerifier. 678 * can be used to create a MockCertVerifier.
619 * @param mockCertVerifier pointer to native MockCertVerifier. 679 * @param mockCertVerifier pointer to native MockCertVerifier.
620 * @return the builder to facilitate chaining. 680 * @return the builder to facilitate chaining.
621 * @hide 681 * @hide
622 */ 682 */
623 @VisibleForTesting 683 @VisibleForTesting
624 public Builder setMockCertVerifierForTesting(long mockCertVerifier) { 684 public Builder setMockCertVerifierForTesting(long mockCertVerifier) {
625 mMockCertVerifier = mockCertVerifier; 685 mMockCertVerifier = mockCertVerifier;
626 return this; 686 return this;
627 } 687 }
628 688
629 long mockCertVerifier() { 689 /**
690 * @hide only used by internal implementation.
691 */
692 public long mockCertVerifier() {
630 return mMockCertVerifier; 693 return mMockCertVerifier;
631 } 694 }
632 695
633 /** 696 /**
634 * Enables the network quality estimator, which collects and reports 697 * Enables the network quality estimator, which collects and reports
635 * measurements of round trip time (RTT) and downstream throughput at 698 * measurements of round trip time (RTT) and downstream throughput at
636 * various layers of the network stack. After enabling the estimator, 699 * various layers of the network stack. After enabling the estimator,
637 * listeners of RTT and throughput can be added with 700 * listeners of RTT and throughput can be added with
638 * {@link #addRttListener} and {@link #addThroughputListener} and 701 * {@link #addRttListener} and {@link #addThroughputListener} and
639 * removed with {@link #removeRttListener} and 702 * removed with {@link #removeRttListener} and
640 * {@link #removeThroughputListener}. The estimator uses memory and CPU 703 * {@link #removeThroughputListener}. The estimator uses memory and CPU
641 * only when enabled. 704 * only when enabled.
642 * @param value {@code true} to enable network quality estimator, 705 * @param value {@code true} to enable network quality estimator,
643 * {@code false} to disable. 706 * {@code false} to disable.
644 * @hide as it's a prototype. 707 * @hide as it's a prototype.
645 * @return the builder to facilitate chaining. 708 * @return the builder to facilitate chaining.
646 */ 709 */
647 public Builder enableNetworkQualityEstimator(boolean value) { 710 public Builder enableNetworkQualityEstimator(boolean value) {
648 mNetworkQualityEstimatorEnabled = value; 711 mNetworkQualityEstimatorEnabled = value;
649 return this; 712 return this;
650 } 713 }
651 714
652 /** 715 /**
653 * @return true if the network quality estimator has been enabled for 716 * @return true if the network quality estimator has been enabled for
654 * this builder. 717 * this builder.
655 * @hide as it's a prototype. 718 * @hide as it's a prototype and only used by internal implementation.
656 */ 719 */
657 boolean networkQualityEstimatorEnabled() { 720 public boolean networkQualityEstimatorEnabled() {
658 return mNetworkQualityEstimatorEnabled; 721 return mNetworkQualityEstimatorEnabled;
659 } 722 }
660 723
661 /** 724 /**
662 * Initializes CachingCertVerifier's cache with certVerifierData which h as 725 * Initializes CachingCertVerifier's cache with certVerifierData which h as
663 * the results of certificate verification. 726 * the results of certificate verification.
664 * @param certVerifierData a serialized representation of certificate 727 * @param certVerifierData a serialized representation of certificate
665 * verification results. 728 * verification results.
666 * @return the builder to facilitate chaining. 729 * @return the builder to facilitate chaining.
667 */ 730 */
668 public Builder setCertVerifierData(String certVerifierData) { 731 public Builder setCertVerifierData(String certVerifierData) {
669 mCertVerifierData = certVerifierData; 732 mCertVerifierData = certVerifierData;
670 return this; 733 return this;
671 } 734 }
672 735
673 String certVerifierData() { 736 /**
737 * @hide only used by internal implementation.
738 */
739 public String certVerifierData() {
674 return mCertVerifierData; 740 return mCertVerifierData;
675 } 741 }
676 742
677 /** 743 /**
678 * Returns {@link Context} for builder. 744 * Returns {@link Context} for builder.
679 * 745 *
680 * @return {@link Context} for builder. 746 * @return {@link Context} for builder.
747 * @hide only used by internal implementation.
681 */ 748 */
682 Context getContext() { 749 public Context getContext() {
683 return mContext; 750 return mContext;
684 } 751 }
685 752
686 /** 753 /**
687 * Build a {@link CronetEngine} using this builder's configuration. 754 * Build a {@link CronetEngine} using this builder's configuration.
688 * @return constructed {@link CronetEngine}. 755 * @return constructed {@link CronetEngine}.
689 */ 756 */
690 public CronetEngine build() { 757 public CronetEngine build() {
691 if (getUserAgent() == null) { 758 if (getUserAgent() == null) {
692 setUserAgent(getDefaultUserAgent()); 759 setUserAgent(getDefaultUserAgent());
693 } 760 }
694 CronetEngine cronetEngine = null; 761 CronetEngine cronetEngine = null;
695 if (!legacyMode()) { 762 if (!legacyMode()) {
696 cronetEngine = createCronetEngine(this); 763 cronetEngine = createCronetEngine(this);
697 } 764 }
698 if (cronetEngine == null) { 765 if (cronetEngine == null) {
699 cronetEngine = new JavaCronetEngine(getUserAgent()); 766 cronetEngine = new JavaCronetEngine(getUserAgent());
700 } 767 }
701 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString() ); 768 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString() );
702 // Clear MOCK_CERT_VERIFIER reference if there is any, since 769 // Clear MOCK_CERT_VERIFIER reference if there is any, since
703 // the ownership has been transferred to the engine. 770 // the ownership has been transferred to the engine.
704 mMockCertVerifier = 0; 771 mMockCertVerifier = 0;
705 return cronetEngine; 772 return cronetEngine;
706 } 773 }
707 } 774 }
708 775
709 private static final String TAG = "UrlRequestFactory"; 776 private static final String TAG = "UrlRequestFactory";
710 private static final String CRONET_URL_REQUEST_CONTEXT = 777 private static final String CRONET_URL_REQUEST_CONTEXT =
711 "org.chromium.net.CronetUrlRequestContext"; 778 "org.chromium.net.impl.CronetUrlRequestContext";
712 779
713 /** 780 /**
714 * Creates a {@link UrlRequest} object. All callbacks will 781 * Creates a {@link UrlRequest} object. All callbacks will
715 * be called on {@code executor}'s thread. {@code executor} must not run 782 * be called on {@code executor}'s thread. {@code executor} must not run
716 * tasks on the current thread to prevent blocking networking operations 783 * tasks on the current thread to prevent blocking networking operations
717 * and causing exceptions during shutdown. Request is given medium priority, 784 * and causing exceptions during shutdown. Request is given medium priority,
718 * see {@link UrlRequest.Builder#REQUEST_PRIORITY_MEDIUM}. To specify other 785 * see {@link UrlRequest.Builder#REQUEST_PRIORITY_MEDIUM}. To specify other
719 * priorities see {@link #createRequest(String, UrlRequest.Callback, 786 * priorities see {@link #createRequest(String, UrlRequest.Callback,
720 * Executor, int priority)}. 787 * Executor, int priority)}.
721 * 788 *
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 * @param httpMethod the HTTP method to use for the stream 861 * @param httpMethod the HTTP method to use for the stream
795 * @param requestHeaders the list of request headers 862 * @param requestHeaders the list of request headers
796 * @param priority priority of the stream which should be one of the 863 * @param priority priority of the stream which should be one of the
797 * {@link BidirectionalStream.Builder#STREAM_PRIORITY_IDLE STREAM_PR IORITY_*} 864 * {@link BidirectionalStream.Builder#STREAM_PRIORITY_IDLE STREAM_PR IORITY_*}
798 * values. 865 * values.
799 * @param disableAutoFlush whether auto flush should be disabled 866 * @param disableAutoFlush whether auto flush should be disabled
800 * @param delayRequestHeadersUntilFirstFlush whether to delay sending reques t 867 * @param delayRequestHeadersUntilFirstFlush whether to delay sending reques t
801 * headers until flush() is called, and try to combine them 868 * headers until flush() is called, and try to combine them
802 * with the next data frame. 869 * with the next data frame.
803 * @return a new stream. 870 * @return a new stream.
871 * @hide only used by internal implementation.
804 */ 872 */
805 abstract BidirectionalStream createBidirectionalStream(String url, 873 public abstract BidirectionalStream createBidirectionalStream(String url,
806 BidirectionalStream.Callback callback, Executor executor, String htt pMethod, 874 BidirectionalStream.Callback callback, Executor executor, String htt pMethod,
807 List<Map.Entry<String, String>> requestHeaders, 875 List<Map.Entry<String, String>> requestHeaders,
808 @BidirectionalStream.Builder.StreamPriority int priority, boolean di sableAutoFlush, 876 @BidirectionalStream.Builder.StreamPriority int priority, boolean di sableAutoFlush,
809 boolean delayRequestHeadersUntilFirstFlush); 877 boolean delayRequestHeadersUntilFirstFlush);
810 878
811 /** 879 /**
812 * @return {@code true} if the engine is enabled. 880 * @return {@code true} if the engine is enabled.
881 * @hide only used by internal implementation.
813 */ 882 */
814 abstract boolean isEnabled(); 883 public abstract boolean isEnabled();
815 884
816 /** 885 /**
817 * @return a human-readable version string of the engine. 886 * @return a human-readable version string of the engine.
818 */ 887 */
819 public abstract String getVersionString(); 888 public abstract String getVersionString();
820 889
821 /** 890 /**
822 * Shuts down the {@link CronetEngine} if there are no active requests, 891 * Shuts down the {@link CronetEngine} if there are no active requests,
823 * otherwise throws an exception. 892 * otherwise throws an exception.
824 * 893 *
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 985
917 /** 986 /**
918 * Configures the network quality estimator for testing. This must be called 987 * Configures the network quality estimator for testing. This must be called
919 * before round trip time and throughput listeners are added, and after the 988 * before round trip time and throughput listeners are added, and after the
920 * network quality estimator has been enabled. 989 * network quality estimator has been enabled.
921 * @param useLocalHostRequests include requests to localhost in estimates. 990 * @param useLocalHostRequests include requests to localhost in estimates.
922 * @param useSmallerResponses include small responses in throughput 991 * @param useSmallerResponses include small responses in throughput
923 * estimates. 992 * estimates.
924 * @hide as it's a prototype. 993 * @hide as it's a prototype.
925 */ 994 */
926 abstract void configureNetworkQualityEstimatorForTesting( 995 public abstract void configureNetworkQualityEstimatorForTesting(
927 boolean useLocalHostRequests, boolean useSmallerResponses); 996 boolean useLocalHostRequests, boolean useSmallerResponses);
928 997
929 /** 998 /**
930 * Registers a listener that gets called whenever the network quality 999 * Registers a listener that gets called whenever the network quality
931 * estimator witnesses a sample round trip time. This must be called 1000 * estimator witnesses a sample round trip time. This must be called
932 * after {@link #enableNetworkQualityEstimator}, and with throw an 1001 * after {@link #enableNetworkQualityEstimator}, and with throw an
933 * exception otherwise. Round trip times may be recorded at various layers 1002 * exception otherwise. Round trip times may be recorded at various layers
934 * of the network stack, including TCP, QUIC, and at the URL request layer. 1003 * of the network stack, including TCP, QUIC, and at the URL request layer.
935 * The listener is called on the {@link java.util.concurrent.Executor} that 1004 * The listener is called on the {@link java.util.concurrent.Executor} that
936 * is passed to {@link #enableNetworkQualityEstimator}. 1005 * is passed to {@link #enableNetworkQualityEstimator}.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 * Information about a finished request. Passed to {@link RequestFinishedLis tener}. 1153 * Information about a finished request. Passed to {@link RequestFinishedLis tener}.
1085 * 1154 *
1086 * @hide as it's a prototype. 1155 * @hide as it's a prototype.
1087 */ 1156 */
1088 public static final class UrlRequestInfo { 1157 public static final class UrlRequestInfo {
1089 private final String mUrl; 1158 private final String mUrl;
1090 private final Collection<Object> mAnnotations; 1159 private final Collection<Object> mAnnotations;
1091 private final UrlRequestMetrics mMetrics; 1160 private final UrlRequestMetrics mMetrics;
1092 @Nullable private final UrlResponseInfo mResponseInfo; 1161 @Nullable private final UrlResponseInfo mResponseInfo;
1093 1162
1094 UrlRequestInfo(String url, Collection<Object> annotations, UrlRequestMet rics metrics, 1163 /**
1164 * @hide only used by internal implementation.
1165 */
1166 public UrlRequestInfo(String url, Collection<Object> annotations, UrlReq uestMetrics metrics,
1095 @Nullable UrlResponseInfo responseInfo) { 1167 @Nullable UrlResponseInfo responseInfo) {
1096 mUrl = url; 1168 mUrl = url;
1097 mAnnotations = annotations; 1169 mAnnotations = annotations;
1098 mMetrics = metrics; 1170 mMetrics = metrics;
1099 mResponseInfo = responseInfo; 1171 mResponseInfo = responseInfo;
1100 } 1172 }
1101 1173
1102 /** Returns the request's original URL. */ 1174 /** Returns the request's original URL. */
1103 public String getUrl() { 1175 public String getUrl() {
1104 return mUrl; 1176 return mUrl;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 * @hide as it's a prototype. 1273 * @hide as it's a prototype.
1202 */ 1274 */
1203 public interface RequestFinishedListener { 1275 public interface RequestFinishedListener {
1204 /** 1276 /**
1205 * Invoked with request info. 1277 * Invoked with request info.
1206 * @param requestInfo {@link UrlRequestInfo} for finished request. 1278 * @param requestInfo {@link UrlRequestInfo} for finished request.
1207 */ 1279 */
1208 void onRequestFinished(UrlRequestInfo requestInfo); 1280 void onRequestFinished(UrlRequestInfo requestInfo);
1209 } 1281 }
1210 } 1282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698