| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 org.json.JSONArray; | 7 import org.json.JSONArray; |
| 8 import org.json.JSONException; | 8 import org.json.JSONException; |
| 9 import org.json.JSONObject; | 9 import org.json.JSONObject; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * A config for HttpUrlRequestFactory, which allows runtime configuration of | 12 * A config for HttpUrlRequestFactory, which allows runtime configuration of |
| 13 * HttpUrlRequestFactory. | 13 * HttpUrlRequestFactory. |
| 14 */ | 14 */ |
| 15 public class HttpUrlRequestFactoryConfig { | 15 public class HttpUrlRequestFactoryConfig { |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Default config enables SPDY, QUIC, in memory http cache. | 18 * Default config enables SPDY, QUIC, in memory http cache. |
| 19 */ | 19 */ |
| 20 public HttpUrlRequestFactoryConfig() { | 20 public HttpUrlRequestFactoryConfig() { |
| 21 enableLegacyMode(false); | 21 enableLegacyMode(false); |
| 22 enableQUIC(false); | 22 enableQUIC(false); |
| 23 enableSPDY(true); | 23 enableSPDY(true); |
| 24 enableHttpCache(HttpCache.IN_MEMORY, 100 * 1024); | 24 enableHttpCache(HttpCache.IN_MEMORY, 100 * 1024); |
| 25 } | 25 } |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Override the name of the native library backing cronet. | |
| 29 */ | |
| 30 public HttpUrlRequestFactoryConfig setLibraryName(String libName) { | |
| 31 return putString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, libName); | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * Create config from json serialized using @toString. | 28 * Create config from json serialized using @toString. |
| 36 */ | 29 */ |
| 37 public HttpUrlRequestFactoryConfig(String json) throws JSONException { | 30 public HttpUrlRequestFactoryConfig(String json) throws JSONException { |
| 38 mConfig = new JSONObject(json); | 31 mConfig = new JSONObject(json); |
| 39 } | 32 } |
| 40 | 33 |
| 41 /** | 34 /** |
| 42 * Boolean, use HttpUrlRequest-based implementation if true. All other | 35 * Boolean, use HttpUrlRequest-based implementation if true. All other |
| 43 * keys are not applicable. | 36 * keys are not applicable. |
| 44 */ | 37 */ |
| 45 public HttpUrlRequestFactoryConfig enableLegacyMode(boolean value) { | 38 public HttpUrlRequestFactoryConfig enableLegacyMode(boolean value) { |
| 46 return putBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE, value); | 39 return putBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE, value); |
| 47 } | 40 } |
| 48 | 41 |
| 49 boolean legacyMode() { | 42 boolean legacyMode() { |
| 50 return mConfig.optBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE); | 43 return mConfig.optBoolean(UrlRequestContextConfig.ENABLE_LEGACY_MODE); |
| 51 } | 44 } |
| 52 | 45 |
| 46 /** |
| 47 * Override the user-agent header for all requests. |
| 48 */ |
| 49 public HttpUrlRequestFactoryConfig setUserAgent(String userAgent) { |
| 50 return putString(UrlRequestContextConfig.USER_AGENT, userAgent); |
| 51 } |
| 52 |
| 53 String userAgent() { |
| 54 return mConfig.optString(UrlRequestContextConfig.USER_AGENT); |
| 55 } |
| 56 |
| 57 /** |
| 58 * Override the name of the native library backing cronet. |
| 59 */ |
| 60 public HttpUrlRequestFactoryConfig setLibraryName(String libName) { |
| 61 return putString(UrlRequestContextConfig.NATIVE_LIBRARY_NAME, libName); |
| 62 } |
| 63 |
| 53 /** | 64 /** |
| 54 * Boolean, enable QUIC if true. | 65 * Boolean, enable QUIC if true. |
| 55 */ | 66 */ |
| 56 public HttpUrlRequestFactoryConfig enableQUIC(boolean value) { | 67 public HttpUrlRequestFactoryConfig enableQUIC(boolean value) { |
| 57 return putBoolean(UrlRequestContextConfig.ENABLE_QUIC, value); | 68 return putBoolean(UrlRequestContextConfig.ENABLE_QUIC, value); |
| 58 } | 69 } |
| 59 | 70 |
| 60 /** | 71 /** |
| 61 * Boolean, enable SPDY if true. | 72 * Boolean, enable SPDY if true. |
| 62 */ | 73 */ |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 try { | 183 try { |
| 173 mConfig.put(key, value); | 184 mConfig.put(key, value); |
| 174 } catch (JSONException e) { | 185 } catch (JSONException e) { |
| 175 // Intentionally do nothing. | 186 // Intentionally do nothing. |
| 176 } | 187 } |
| 177 return this; | 188 return this; |
| 178 } | 189 } |
| 179 | 190 |
| 180 private JSONObject mConfig = new JSONObject(); | 191 private JSONObject mConfig = new JSONObject(); |
| 181 } | 192 } |
| OLD | NEW |