| 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.JSONException; | 8 import org.json.JSONException; |
| 8 import org.json.JSONObject; | 9 import org.json.JSONObject; |
| 9 | 10 |
| 10 /** | 11 /** |
| 11 * A config for HttpUrlRequestFactory, which allows runtime configuration of | 12 * A config for HttpUrlRequestFactory, which allows runtime configuration of |
| 12 * HttpUrlRequestFactory. | 13 * HttpUrlRequestFactory. |
| 13 */ | 14 */ |
| 14 public class HttpUrlRequestFactoryConfig { | 15 public class HttpUrlRequestFactoryConfig { |
| 15 /** | 16 /** |
| 16 * Default config enables SPDY, QUIC, in memory http cache. | 17 * Default config enables SPDY, QUIC, in memory http cache. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 80 } |
| 80 | 81 |
| 81 /** | 82 /** |
| 82 * String, path to directory for HTTP Cache and Cookie Storage. | 83 * String, path to directory for HTTP Cache and Cookie Storage. |
| 83 */ | 84 */ |
| 84 public HttpUrlRequestFactoryConfig setStoragePath(String value) { | 85 public HttpUrlRequestFactoryConfig setStoragePath(String value) { |
| 85 return putString(UrlRequestContextConfig.STORAGE_PATH, value); | 86 return putString(UrlRequestContextConfig.STORAGE_PATH, value); |
| 86 } | 87 } |
| 87 | 88 |
| 88 /** | 89 /** |
| 90 * Explicitly mark |host| as supporting QUIC. |
| 91 * Note that enableHttpCache(DISK) is needed to take advantage of 0-RTT |
| 92 * connection establishment between sessions. |
| 93 * |
| 94 * @param host of the server that supports QUIC. |
| 95 * @param port of the server that supports QUIC. |
| 96 * @param alternatePort to use for QUIC. |
| 97 */ |
| 98 public HttpUrlRequestFactoryConfig addQuicHint(String host, |
| 99 int port, |
| 100 int alternatePort) { |
| 101 try { |
| 102 JSONArray quicHints = mConfig.optJSONArray( |
| 103 UrlRequestContextConfig.QUIC_HINTS); |
| 104 if (quicHints == null) { |
| 105 quicHints = new JSONArray(); |
| 106 mConfig.put(UrlRequestContextConfig.QUIC_HINTS, quicHints); |
| 107 } |
| 108 |
| 109 JSONObject hint = new JSONObject(); |
| 110 hint.put(UrlRequestContextConfig.QUIC_HINT_HOST, host); |
| 111 hint.put(UrlRequestContextConfig.QUIC_HINT_PORT, port); |
| 112 hint.put(UrlRequestContextConfig.QUIC_HINT_ALT_PORT, alternatePort); |
| 113 quicHints.put(hint); |
| 114 } catch (JSONException e) { |
| 115 ; |
| 116 } |
| 117 return this; |
| 118 } |
| 119 |
| 120 /** |
| 89 * Get JSON string representation of the config. | 121 * Get JSON string representation of the config. |
| 90 */ | 122 */ |
| 91 public String toString() { | 123 public String toString() { |
| 92 return mConfig.toString(); | 124 return mConfig.toString(); |
| 93 } | 125 } |
| 94 | 126 |
| 95 /** | 127 /** |
| 96 * Sets a boolean value in the config. Returns a reference to the same | 128 * Sets a boolean value in the config. Returns a reference to the same |
| 97 * config object, so you can chain put calls together. | 129 * config object, so you can chain put calls together. |
| 98 */ | 130 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 126 try { | 158 try { |
| 127 mConfig.put(key, value); | 159 mConfig.put(key, value); |
| 128 } catch (JSONException e) { | 160 } catch (JSONException e) { |
| 129 ; | 161 ; |
| 130 } | 162 } |
| 131 return this; | 163 return this; |
| 132 } | 164 } |
| 133 | 165 |
| 134 private JSONObject mConfig = new JSONObject(); | 166 private JSONObject mConfig = new JSONObject(); |
| 135 } | 167 } |
| OLD | NEW |