Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 UrlRequestContextConfig.HTTP_CACHE_DISK); | 73 UrlRequestContextConfig.HTTP_CACHE_DISK); |
| 73 case IN_MEMORY: | 74 case IN_MEMORY: |
| 74 putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize); | 75 putLong(UrlRequestContextConfig.HTTP_CACHE_MAX_SIZE, maxSize); |
| 75 return putString(UrlRequestContextConfig.HTTP_CACHE, | 76 return putString(UrlRequestContextConfig.HTTP_CACHE, |
| 76 UrlRequestContextConfig.HTTP_CACHE_MEMORY); | 77 UrlRequestContextConfig.HTTP_CACHE_MEMORY); |
| 77 } | 78 } |
| 78 return this; | 79 return this; |
| 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. |
|
mmenke
2014/09/09 14:53:35
Cleanup: A lot of these should be prefixed with @
mef
2014/09/10 16:48:18
Acknowledged.
| |
| 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 |server| as supporting QUIC. | |
| 91 * Note that enableHttpCache(DISK) is needed to take advantage or 0-RTT. | |
|
mmenke
2014/09/09 14:53:35
nit: or -> of.
Also, maybe add "0-RTT connection
mef
2014/09/10 16:48:18
Done.
| |
| 92 * | |
| 93 * @param server URL of the server that supports QUIC | |
| 94 * @param alternatePort to use for QUIC | |
|
mmenke
2014/09/09 14:53:35
nit: End comments with periods.
mef
2014/09/10 16:48:18
Done.
| |
| 95 */ | |
| 96 public HttpUrlRequestFactoryConfig addQuicHint(String server, | |
| 97 int alternatePort) { | |
| 98 try { | |
| 99 JSONArray quicHints = mConfig.optJSONArray( | |
| 100 UrlRequestContextConfig.QUIC_HINTS); | |
| 101 if (quicHints == null) { | |
| 102 quicHints = new JSONArray(); | |
| 103 mConfig.put(UrlRequestContextConfig.QUIC_HINTS, quicHints); | |
| 104 } | |
| 105 | |
| 106 JSONObject hint = new JSONObject(); | |
| 107 hint.put(UrlRequestContextConfig.QUIC_HINT_SERVER, server); | |
| 108 hint.put(UrlRequestContextConfig.QUIC_HINT_ALT_PORT, alternatePort); | |
| 109 quicHints.put(hint); | |
| 110 } catch (JSONException e) { | |
| 111 ; | |
| 112 } | |
| 113 return this; | |
| 114 } | |
| 115 | |
| 116 /** | |
| 89 * Get JSON string representation of the config. | 117 * Get JSON string representation of the config. |
| 90 */ | 118 */ |
| 91 public String toString() { | 119 public String toString() { |
| 92 return mConfig.toString(); | 120 return mConfig.toString(); |
| 93 } | 121 } |
| 94 | 122 |
| 95 /** | 123 /** |
| 96 * Sets a boolean value in the config. Returns a reference to the same | 124 * Sets a boolean value in the config. Returns a reference to the same |
| 97 * config object, so you can chain put calls together. | 125 * config object, so you can chain put calls together. |
| 98 */ | 126 */ |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 126 try { | 154 try { |
| 127 mConfig.put(key, value); | 155 mConfig.put(key, value); |
| 128 } catch (JSONException e) { | 156 } catch (JSONException e) { |
| 129 ; | 157 ; |
| 130 } | 158 } |
| 131 return this; | 159 return this; |
| 132 } | 160 } |
| 133 | 161 |
| 134 private JSONObject mConfig = new JSONObject(); | 162 private JSONObject mConfig = new JSONObject(); |
| 135 } | 163 } |
| OLD | NEW |