Index: components/cronet/android/java/src/org/chromium/net/UrlRequestContextConfig.java |
diff --git a/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java b/components/cronet/android/java/src/org/chromium/net/UrlRequestContextConfig.java |
similarity index 51% |
copy from components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java |
copy to components/cronet/android/java/src/org/chromium/net/UrlRequestContextConfig.java |
index e3c510668d09cc8bcacc68cabc39a806a71f674d..514b868db148327ed8bb10f2e984846372480276 100644 |
--- a/components/cronet/android/java/src/org/chromium/net/HttpUrlRequestFactoryConfig.java |
+++ b/components/cronet/android/java/src/org/chromium/net/UrlRequestContextConfig.java |
@@ -9,15 +9,15 @@ import org.json.JSONException; |
import org.json.JSONObject; |
/** |
- * A config for HttpUrlRequestFactory, which allows runtime configuration of |
- * HttpUrlRequestFactory. |
+ * A config for UrlRequestContext, which allows runtime configuration of |
+ * UrlRequestContext. |
*/ |
-public class HttpUrlRequestFactoryConfig { |
+public class UrlRequestContextConfig { |
/** |
* Default config enables SPDY, QUIC, in memory http cache. |
*/ |
- public HttpUrlRequestFactoryConfig() { |
+ public UrlRequestContextConfig() { |
enableLegacyMode(false); |
enableQUIC(false); |
enableSPDY(true); |
@@ -25,48 +25,69 @@ public class HttpUrlRequestFactoryConfig { |
} |
/** |
- * Override the name of the native library backing cronet. |
+ * Create config from json serialized using @toString. |
*/ |
- public HttpUrlRequestFactoryConfig setLibraryName(String libName) { |
- return putString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, libName); |
+ public UrlRequestContextConfig(String json) throws JSONException { |
+ mConfig = new JSONObject(json); |
} |
/** |
- * Create config from json serialized using @toString. |
+ * Override the user-agent header for all requests. |
*/ |
- public HttpUrlRequestFactoryConfig(String json) throws JSONException { |
- mConfig = new JSONObject(json); |
+ public UrlRequestContextConfig setUserAgent(String userAgent) { |
+ return putString(UrlRequestContextConfigList.USER_AGENT, userAgent); |
+ } |
+ |
+ String userAgent() { |
+ return mConfig.optString(UrlRequestContextConfigList.USER_AGENT); |
} |
/** |
- * Boolean, use HttpUrlRequest-based implementation if true. All other |
+ * String, path to directory for HTTP Cache and Cookie Storage. |
+ */ |
+ public UrlRequestContextConfig setStoragePath(String value) { |
+ return putString(UrlRequestContextConfigList.STORAGE_PATH, value); |
+ } |
+ |
+ /** |
+ * Boolean, use HttpUrlConnection-based implementation if true. All other |
* keys are not applicable. |
*/ |
- public HttpUrlRequestFactoryConfig enableLegacyMode(boolean value) { |
- return putBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE, value); |
+ public UrlRequestContextConfig enableLegacyMode(boolean value) { |
+ return putBoolean(UrlRequestContextConfigList.ENABLE_LEGACY_MODE, |
+ value); |
} |
boolean legacyMode() { |
- return mConfig.optBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE); |
+ return mConfig.optBoolean( |
+ UrlRequestContextConfigList.ENABLE_LEGACY_MODE); |
} |
/** |
- * Boolean, enable QUIC if true. |
+ * Override the name of the native library backing cronet. |
*/ |
- public HttpUrlRequestFactoryConfig enableQUIC(boolean value) { |
- return putBoolean(UrlRequestContextConfig.ENABLE_QUIC, value); |
+ public UrlRequestContextConfig setLibraryName(String libName) { |
+ return putString(UrlRequestContextConfigList.NATIVE_LIBRARY_NAME, |
+ libName); |
+ } |
+ |
+ String libraryName() { |
+ return mConfig.optString( |
+ UrlRequestContextConfigList.NATIVE_LIBRARY_NAME, "cronet"); |
} |
/** |
- * Boolean, enable SPDY if true. |
+ * Boolean, enable QUIC if true. |
*/ |
- public HttpUrlRequestFactoryConfig enableSPDY(boolean value) { |
- return putBoolean(UrlRequestContextConfig.ENABLE_SPDY, value); |
+ public UrlRequestContextConfig enableQUIC(boolean value) { |
+ return putBoolean(UrlRequestContextConfigList.ENABLE_QUIC, value); |
} |
- String libraryName() { |
- return mConfig.optString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, |
- "cronet"); |
+ /** |
+ * Boolean, enable SPDY if true. |
+ */ |
+ public UrlRequestContextConfig enableSPDY(boolean value) { |
+ return putBoolean(UrlRequestContextConfigList.ENABLE_SPDY, value); |
} |
/** |
@@ -74,32 +95,27 @@ public class HttpUrlRequestFactoryConfig { |
* maximum size in bytes. |
*/ |
public enum HttpCache { DISABLED, IN_MEMORY, DISK }; |
- public HttpUrlRequestFactoryConfig enableHttpCache(HttpCache value, |
- long maxSize) { |
+ public UrlRequestContextConfig enableHttpCache(HttpCache value, |
+ long maxSize) { |
switch(value) { |
case DISABLED: |
- return putString(UrlRequestContextConfig.HTTP_CACHE, |
- UrlRequestContextConfig.HTTP_CACHE_DISABLED); |
+ return putString(UrlRequestContextConfigList.HTTP_CACHE, |
+ UrlRequestContextConfigList.HTTP_CACHE_DISABLED); |
case DISK: |
- putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize); |
- return putString(UrlRequestContextConfig.HTTP_CACHE, |
- UrlRequestContextConfig.HTTP_CACHE_DISK); |
+ putLong(UrlRequestContextConfigList.HTTP_CACHE_MAX_SIZE, |
+ maxSize); |
+ return putString(UrlRequestContextConfigList.HTTP_CACHE, |
+ UrlRequestContextConfigList.HTTP_CACHE_DISK); |
case IN_MEMORY: |
- putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize); |
- return putString(UrlRequestContextConfig.HTTP_CACHE, |
- UrlRequestContextConfig.HTTP_CACHE_MEMORY); |
+ putLong(UrlRequestContextConfigList.HTTP_CACHE_MAX_SIZE, |
+ maxSize); |
+ return putString(UrlRequestContextConfigList.HTTP_CACHE, |
+ UrlRequestContextConfigList.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); |
- } |
- |
- /** |
* Explicitly mark |host| as supporting QUIC. |
* Note that enableHttpCache(DISK) is needed to take advantage of 0-RTT |
* connection establishment between sessions. |
@@ -108,25 +124,26 @@ public class HttpUrlRequestFactoryConfig { |
* @param port of the server that supports QUIC. |
* @param alternatePort to use for QUIC. |
*/ |
- public HttpUrlRequestFactoryConfig addQuicHint(String host, |
- int port, |
- int alternatePort) { |
+ public UrlRequestContextConfig addQuicHint(String host, |
+ int port, |
+ int alternatePort) { |
if (host.contains("/")) { |
- throw new IllegalArgumentException("Illegal QUIC Hint Host: " + |
- host); |
+ throw new IllegalArgumentException("Illegal QUIC Hint Host: " |
+ + host); |
} |
try { |
JSONArray quicHints = mConfig.optJSONArray( |
- UrlRequestContextConfig.QUIC_HINTS); |
+ UrlRequestContextConfigList.QUIC_HINTS); |
if (quicHints == null) { |
quicHints = new JSONArray(); |
- mConfig.put(UrlRequestContextConfig.QUIC_HINTS, quicHints); |
+ mConfig.put(UrlRequestContextConfigList.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); |
+ hint.put(UrlRequestContextConfigList.QUIC_HINT_HOST, host); |
+ hint.put(UrlRequestContextConfigList.QUIC_HINT_PORT, port); |
+ hint.put(UrlRequestContextConfigList.QUIC_HINT_ALT_PORT, |
+ alternatePort); |
quicHints.put(hint); |
} catch (JSONException e) { |
// Intentionally do nothing. |
@@ -146,7 +163,7 @@ public class HttpUrlRequestFactoryConfig { |
* 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) { |
+ private UrlRequestContextConfig putBoolean(String key, boolean value) { |
try { |
mConfig.put(key, value); |
} catch (JSONException e) { |
@@ -159,7 +176,7 @@ public class HttpUrlRequestFactoryConfig { |
* 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) { |
+ private UrlRequestContextConfig putLong(String key, long value) { |
try { |
mConfig.put(key, value); |
} catch (JSONException e) { |
@@ -172,7 +189,7 @@ public class HttpUrlRequestFactoryConfig { |
* 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) { |
+ private UrlRequestContextConfig putString(String key, String value) { |
try { |
mConfig.put(key, value); |
} catch (JSONException e) { |