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 54% |
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..ba0e5a8aff2e39ca1c5d4882c07a677c751dea86 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,62 @@ public class HttpUrlRequestFactoryConfig { |
} |
/** |
- * Override the name of the native library backing cronet. |
- */ |
- public HttpUrlRequestFactoryConfig setLibraryName(String libName) { |
- return putString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, libName); |
- } |
- |
- /** |
* Create config from json serialized using @toString. |
*/ |
- public HttpUrlRequestFactoryConfig(String json) throws JSONException { |
+ public UrlRequestContextConfig(String json) throws JSONException { |
mConfig = new JSONObject(json); |
} |
/** |
- * Boolean, use HttpUrlRequest-based implementation if true. All other |
+ * 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); |
+ } |
+ |
+ /** |
+ * Override the user-agent header for all requests. |
+ */ |
+ public UrlRequestContextConfig setUserAgent(String userAgent) { |
+ return putString(UrlRequestContextConfigList.USER_AGENT, userAgent); |
+ } |
+ |
+ String userAgent() { |
+ return mConfig.optString(UrlRequestContextConfigList.USER_AGENT); |
+ } |
+ |
+ /** |
+ * Override the name of the native library backing cronet. |
+ */ |
+ public UrlRequestContextConfig setLibraryName(String libName) { |
+ return putString(UrlRequestContextConfigList.NATIVE_LIBRARY_NAME, |
+ libName); |
} |
/** |
* Boolean, enable QUIC if true. |
*/ |
- public HttpUrlRequestFactoryConfig enableQUIC(boolean value) { |
- return putBoolean(UrlRequestContextConfig.ENABLE_QUIC, value); |
+ public UrlRequestContextConfig enableQUIC(boolean value) { |
+ return putBoolean(UrlRequestContextConfigList.ENABLE_QUIC, value); |
} |
/** |
* Boolean, enable SPDY if true. |
*/ |
- public HttpUrlRequestFactoryConfig enableSPDY(boolean value) { |
- return putBoolean(UrlRequestContextConfig.ENABLE_SPDY, value); |
+ public UrlRequestContextConfig enableSPDY(boolean value) { |
+ return putBoolean(UrlRequestContextConfigList.ENABLE_SPDY, value); |
} |
String libraryName() { |
- return mConfig.optString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, |
- "cronet"); |
+ return mConfig.optString( |
+ UrlRequestContextConfigList.NATIVE_LIBRARY_NAME, "cronet"); |
} |
/** |
@@ -74,20 +88,22 @@ public class HttpUrlRequestFactoryConfig { |
* maximum size in bytes. |
*/ |
public enum HttpCache { DISABLED, IN_MEMORY, DISK }; |
- public HttpUrlRequestFactoryConfig enableHttpCache(HttpCache value, |
+ 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; |
} |
@@ -95,8 +111,8 @@ public class HttpUrlRequestFactoryConfig { |
/** |
* String, path to directory for HTTP Cache and Cookie Storage. |
*/ |
- public HttpUrlRequestFactoryConfig setStoragePath(String value) { |
- return putString(UrlRequestContextConfig.STORAGE_PATH, value); |
+ public UrlRequestContextConfig setStoragePath(String value) { |
+ return putString(UrlRequestContextConfigList.STORAGE_PATH, value); |
} |
/** |
@@ -108,7 +124,7 @@ public class HttpUrlRequestFactoryConfig { |
* @param port of the server that supports QUIC. |
* @param alternatePort to use for QUIC. |
*/ |
- public HttpUrlRequestFactoryConfig addQuicHint(String host, |
+ public UrlRequestContextConfig addQuicHint(String host, |
int port, |
int alternatePort) { |
if (host.contains("/")) { |
@@ -117,16 +133,17 @@ public class HttpUrlRequestFactoryConfig { |
} |
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) { |