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.util.Log; | 8 import android.util.Log; |
9 | 9 |
10 import org.json.JSONArray; | 10 import org.json.JSONArray; |
11 import org.json.JSONException; | 11 import org.json.JSONException; |
12 import org.json.JSONObject; | 12 import org.json.JSONObject; |
13 | 13 |
14 import java.io.File; | 14 import java.io.File; |
15 import java.lang.reflect.Constructor; | 15 import java.lang.reflect.Constructor; |
16 import java.net.Proxy; | |
17 import java.net.URL; | |
18 import java.net.URLConnection; | |
19 import java.net.URLStreamHandlerFactory; | |
16 import java.util.concurrent.Executor; | 20 import java.util.concurrent.Executor; |
17 | 21 |
18 /** | 22 /** |
19 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack | 23 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack |
20 * available on the current platform. | 24 * available on the current platform. |
21 */ | 25 */ |
22 public abstract class CronetEngine { | 26 public abstract class CronetEngine { |
23 /** | 27 /** |
24 * A builder for {@link CronetEngine}s, which allows runtime configuration o f | 28 * A builder for {@link CronetEngine}s, which allows runtime configuration o f |
25 * {@code CronetEngine}. Configuration options are set on the builder and | 29 * {@code CronetEngine}. Configuration options are set on the builder and |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 * <a href="https://developer.chrome.com/multidevice/data-compression"> | 164 * <a href="https://developer.chrome.com/multidevice/data-compression"> |
161 * Data Reduction Proxy</a> configuration parameters with a primary | 165 * Data Reduction Proxy</a> configuration parameters with a primary |
162 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s | 166 * proxy name, fallback proxy name, and a secure proxy check URL. Proxie s |
163 * are specified as [scheme://]host[:port]. Used for testing. | 167 * are specified as [scheme://]host[:port]. Used for testing. |
164 * @param primaryProxy the primary data reduction proxy to use. | 168 * @param primaryProxy the primary data reduction proxy to use. |
165 * @param fallbackProxy a fallback data reduction proxy to use. | 169 * @param fallbackProxy a fallback data reduction proxy to use. |
166 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure | 170 * @param secureProxyCheckUrl a URL to fetch to determine if using a sec ure |
167 * proxy is allowed. | 171 * proxy is allowed. |
168 * @return the builder to facilitate chaining. | 172 * @return the builder to facilitate chaining. |
169 * @hide | 173 * @hide |
174 * @deprecated Marked as deprecated because @hide doesn't properly hide but | |
175 * javadocs are built with nodeprecated="yes". | |
170 */ | 176 */ |
171 public Builder setDataReductionProxyOptions( | 177 public Builder setDataReductionProxyOptions( |
172 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) { | 178 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) { |
173 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty() | 179 if (primaryProxy.isEmpty() || fallbackProxy.isEmpty() |
174 || secureProxyCheckUrl.isEmpty()) { | 180 || secureProxyCheckUrl.isEmpty()) { |
175 throw new IllegalArgumentException( | 181 throw new IllegalArgumentException( |
176 "Primary and fallback proxies and check url must be set" ); | 182 "Primary and fallback proxies and check url must be set" ); |
177 } | 183 } |
178 putString(CronetEngineBuilderList.DATA_REDUCTION_PRIMARY_PROXY, prim aryProxy); | 184 putString(CronetEngineBuilderList.DATA_REDUCTION_PRIMARY_PROXY, prim aryProxy); |
179 putString(CronetEngineBuilderList.DATA_REDUCTION_FALLBACK_PROXY, fal lbackProxy); | 185 putString(CronetEngineBuilderList.DATA_REDUCTION_FALLBACK_PROXY, fal lbackProxy); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 * Removes a listener of throughput. This should be called after a | 516 * Removes a listener of throughput. This should be called after a |
511 * {@link NetworkQualityThroughputListener} is added with | 517 * {@link NetworkQualityThroughputListener} is added with |
512 * {@link #addThroughputListener} in order to stop receiving observations. | 518 * {@link #addThroughputListener} in order to stop receiving observations. |
513 * @param listener the listener of throughput. | 519 * @param listener the listener of throughput. |
514 * @deprecated not really deprecated but hidden for now as it's a prototype. | 520 * @deprecated not really deprecated but hidden for now as it's a prototype. |
515 */ | 521 */ |
516 @Deprecated | 522 @Deprecated |
517 public abstract void removeThroughputListener(NetworkQualityThroughputListen er listener); | 523 public abstract void removeThroughputListener(NetworkQualityThroughputListen er listener); |
518 | 524 |
519 /** | 525 /** |
526 * Establishes a new connection to the resource specified by the {@link URL} {@code url}. | |
527 * <p> | |
528 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain | |
529 * limitations, see {@link #createURLStreamHandlerFactory} for details. | |
530 * | |
531 * @param url URL of resource to connect to. | |
532 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. | |
533 */ | |
534 public abstract URLConnection openConnection(URL url); | |
535 | |
536 /** | |
537 * Establishes a new connection to the resource specified by the {@link URL} {@code url} | |
538 * using the given proxy. | |
539 * <p> | |
540 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain | |
541 * limitations, see {@link #createURLStreamHandlerFactory} for details. | |
542 * | |
543 * @param url URL of resource to connect to. | |
544 * @param proxy proxy to use when establishing connection. | |
545 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. | |
546 * @hide | |
547 * @deprecated Marked as deprecated because @hide doesn't properly hide but | |
548 * javadocs are built with nodeprecated="yes". | |
549 * TODO(pauljensen): Expose once implemented, http://crbug.com/41811 1 | |
550 */ | |
551 public abstract URLConnection openConnection(URL url, Proxy proxy); | |
552 | |
553 /** | |
554 * Creates a {@link URLStreamHandlerFactory} to handle HTTP and HTTPS | |
555 * traffic. An instance of this class can be installed via | |
556 * {@link java.net.URL#setURLStreamHandlerFactory} thus using this CronetEng ine by default for | |
xunjieli
2015/10/08 14:17:56
optional nit: Can use shorthand {@link URL#setURLS
pauljensen
2015/10/08 14:40:34
Done.
| |
557 * all requests created via {@link java.net.URL#openConnection}. | |
558 * <p> | |
559 * Cronet does not use certain HTTP features provided via the system: | |
560 * <ul> | |
561 * <li>the HTTP cache installed via | |
562 * {@link android.net.http.HttpResponseCache#install(java.io.File, long) | |
563 * HttpResponseCache.install()}</li> | |
564 * <li>the HTTP authentication method installed via | |
565 * {@link java.net.Authenticator#setDefault}</li> | |
566 * <li>the HTTP cookie storage installed via {@link java.net.CookieHandler#s etDefault}</li> | |
567 * </ul> | |
568 * <p> | |
569 * While Cronet supports and encourages requests using the HTTPS protocol, | |
570 * Cronet does not provide support for the | |
571 * {@link javax.net.ssl.HttpsURLConnection} API. This lack of support also | |
572 * includes not using certain HTTPS features provided via the system: | |
573 * <ul> | |
574 * <li>the HTTPS hostname verifier installed via {@link | |
575 * javax.net.ssl.HttpsURLConnection#setDefaultHostnameVerifier(javax.net.s sl.HostnameVerifier) | |
576 * HttpsURLConnection.setDefaultHostnameVerifier()}</li> | |
577 * <li>the HTTPS socket factory installed via {@link | |
578 * javax.net.ssl.HttpsURLConnection#setDefaultSSLSocketFactory(javax.net.s sl.SSLSocketFactory) | |
579 * HttpsURLConnection.setDefaultSSLSocketFactory()}</li> | |
580 * </ul> | |
581 * | |
582 * @return an {@link java.net.URLStreamHandlerFactory} instance implemented by this | |
xunjieli
2015/10/08 14:17:56
optional nit: Since URLStreamHandlerFactory is imp
pauljensen
2015/10/08 14:40:34
Done.
| |
583 * CronetEngine. | |
584 */ | |
585 public abstract URLStreamHandlerFactory createURLStreamHandlerFactory(); | |
586 | |
587 /** | |
520 * Creates a {@link CronetEngine} with the given {@link Builder}. | 588 * Creates a {@link CronetEngine} with the given {@link Builder}. |
521 * @param context Android {@link Context}. | 589 * @param context Android {@link Context}. |
522 * @param config engine configuration. | 590 * @param config engine configuration. |
523 * @deprecated Use {@link CronetEngine.Builder}. | 591 * @deprecated Use {@link CronetEngine.Builder}. |
524 */ | 592 */ |
525 @Deprecated | 593 @Deprecated |
526 public static CronetEngine createContext(Builder config) { | 594 public static CronetEngine createContext(Builder config) { |
527 CronetEngine cronetEngine = null; | 595 CronetEngine cronetEngine = null; |
528 if (config.userAgent().isEmpty()) { | 596 if (config.userAgent().isEmpty()) { |
529 config.setUserAgent(UserAgent.from(config.getContext())); | 597 config.setUserAgent(UserAgent.from(config.getContext())); |
(...skipping 24 matching lines...) Expand all Loading... | |
554 cronetEngine = possibleEngine; | 622 cronetEngine = possibleEngine; |
555 } | 623 } |
556 } catch (ClassNotFoundException e) { | 624 } catch (ClassNotFoundException e) { |
557 // Leave as null. | 625 // Leave as null. |
558 } catch (Exception e) { | 626 } catch (Exception e) { |
559 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); | 627 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); |
560 } | 628 } |
561 return cronetEngine; | 629 return cronetEngine; |
562 } | 630 } |
563 } | 631 } |
OLD | NEW |