| Index: components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java
|
| diff --git a/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java b/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java
|
| index e3c510668d09cc8bcacc68cabc39a806a71f674d..24a0a82ae0bd7c82fb56fbee5b2746864b0d5547 100644
|
| --- a/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java
|
| +++ b/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java
|
| @@ -4,182 +4,25 @@
|
|
|
| package org.chromium.net;
|
|
|
| -import org.json.JSONArray;
|
| import org.json.JSONException;
|
| -import org.json.JSONObject;
|
|
|
| /**
|
| * A config for HttpUrlRequestFactory, which allows runtime configuration of
|
| * HttpUrlRequestFactory.
|
| */
|
| -public class HttpUrlRequestFactoryConfig {
|
| +public class HttpUrlRequestFactoryConfig extends UrlRequestContextConfig {
|
|
|
| /**
|
| * Default config enables SPDY, QUIC, in memory http cache.
|
| */
|
| public HttpUrlRequestFactoryConfig() {
|
| - enableLegacyMode(false);
|
| - enableQUIC(false);
|
| - enableSPDY(true);
|
| - enableHttpCache(HttpCache.IN_MEMORY, 100 * 1024);
|
| - }
|
| -
|
| - /**
|
| - * Override the name of the native library backing cronet.
|
| - */
|
| - public HttpUrlRequestFactoryConfig setLibraryName(String libName) {
|
| - return putString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, libName);
|
| + super();
|
| }
|
|
|
| /**
|
| * Create config from json serialized using @toString.
|
| */
|
| public HttpUrlRequestFactoryConfig(String json) throws JSONException {
|
| - mConfig = new JSONObject(json);
|
| - }
|
| -
|
| - /**
|
| - * Boolean, use HttpUrlRequest-based implementation if true. All other
|
| - * keys are not applicable.
|
| - */
|
| - public HttpUrlRequestFactoryConfig enableLegacyMode(boolean value) {
|
| - return putBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE, value);
|
| - }
|
| -
|
| - boolean legacyMode() {
|
| - return mConfig.optBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE);
|
| - }
|
| -
|
| - /**
|
| - * Boolean, enable QUIC if true.
|
| - */
|
| - public HttpUrlRequestFactoryConfig enableQUIC(boolean value) {
|
| - return putBoolean(UrlRequestContextConfig.ENABLE_QUIC, value);
|
| - }
|
| -
|
| - /**
|
| - * Boolean, enable SPDY if true.
|
| - */
|
| - public HttpUrlRequestFactoryConfig enableSPDY(boolean value) {
|
| - return putBoolean(UrlRequestContextConfig.ENABLE_SPDY, value);
|
| - }
|
| -
|
| - String libraryName() {
|
| - return mConfig.optString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME,
|
| - "cronet");
|
| - }
|
| -
|
| - /**
|
| - * Enumeration, Disable or Enable Disk or Memory Cache and specify its
|
| - * maximum size in bytes.
|
| - */
|
| - public enum HttpCache { DISABLED, IN_MEMORY, DISK };
|
| - public HttpUrlRequestFactoryConfig enableHttpCache(HttpCache value,
|
| - long maxSize) {
|
| - switch(value) {
|
| - case DISABLED:
|
| - return putString(UrlRequestContextConfig.HTTP_CACHE,
|
| - UrlRequestContextConfig.HTTP_CACHE_DISABLED);
|
| - case DISK:
|
| - putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize);
|
| - return putString(UrlRequestContextConfig.HTTP_CACHE,
|
| - UrlRequestContextConfig.HTTP_CACHE_DISK);
|
| - case IN_MEMORY:
|
| - putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize);
|
| - return putString(UrlRequestContextConfig.HTTP_CACHE,
|
| - UrlRequestContextConfig.HTTP_CACHE_MEMORY);
|
| - }
|
| - return this;
|
| - }
|
| -
|
| - /**
|
| - * String, path to directory for HTTP Cache and Cookie Storage.
|
| - */
|
| - public HttpUrlRequestFactoryConfig setStoragePath(String value) {
|
| - return putString(UrlRequestContextConfig.STORAGE_PATH, value);
|
| + super(json);
|
| }
|
| -
|
| - /**
|
| - * Explicitly mark |host| as supporting QUIC.
|
| - * Note that enableHttpCache(DISK) is needed to take advantage of 0-RTT
|
| - * connection establishment between sessions.
|
| - *
|
| - * @param host of the server that supports QUIC.
|
| - * @param port of the server that supports QUIC.
|
| - * @param alternatePort to use for QUIC.
|
| - */
|
| - public HttpUrlRequestFactoryConfig addQuicHint(String host,
|
| - int port,
|
| - int alternatePort) {
|
| - if (host.contains("/")) {
|
| - throw new IllegalArgumentException("Illegal QUIC Hint Host: " +
|
| - host);
|
| - }
|
| - try {
|
| - JSONArray quicHints = mConfig.optJSONArray(
|
| - UrlRequestContextConfig.QUIC_HINTS);
|
| - if (quicHints == null) {
|
| - quicHints = new JSONArray();
|
| - mConfig.put(UrlRequestContextConfig.QUIC_HINTS, quicHints);
|
| - }
|
| -
|
| - JSONObject hint = new JSONObject();
|
| - hint.put(UrlRequestContextConfig.QUIC_HINT_HOST, host);
|
| - hint.put(UrlRequestContextConfig.QUIC_HINT_PORT, port);
|
| - hint.put(UrlRequestContextConfig.QUIC_HINT_ALT_PORT, alternatePort);
|
| - quicHints.put(hint);
|
| - } catch (JSONException e) {
|
| - // Intentionally do nothing.
|
| - }
|
| - return this;
|
| - }
|
| -
|
| - /**
|
| - * Get JSON string representation of the config.
|
| - */
|
| - @Override
|
| - public String toString() {
|
| - return mConfig.toString();
|
| - }
|
| -
|
| - /**
|
| - * Sets a boolean value in the config. Returns a reference to the same
|
| - * config object, so you can chain put calls together.
|
| - */
|
| - private HttpUrlRequestFactoryConfig putBoolean(String key, boolean value) {
|
| - try {
|
| - mConfig.put(key, value);
|
| - } catch (JSONException e) {
|
| - // Intentionally do nothing.
|
| - }
|
| - return this;
|
| - }
|
| -
|
| - /**
|
| - * Sets a long value in the config. Returns a reference to the same
|
| - * config object, so you can chain put calls together.
|
| - */
|
| - private HttpUrlRequestFactoryConfig putLong(String key, long value) {
|
| - try {
|
| - mConfig.put(key, value);
|
| - } catch (JSONException e) {
|
| - // Intentionally do nothing.
|
| - }
|
| - return this;
|
| - }
|
| -
|
| - /**
|
| - * Sets a string value in the config. Returns a reference to the same
|
| - * config object, so you can chain put calls together.
|
| - */
|
| - private HttpUrlRequestFactoryConfig putString(String key, String value) {
|
| - try {
|
| - mConfig.put(key, value);
|
| - } catch (JSONException e) {
|
| - // Intentionally do nothing.
|
| - }
|
| - return this;
|
| - }
|
| -
|
| - private JSONObject mConfig = new JSONObject();
|
| }
|
|
|