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 |server| as supporting QUIC. | |
91 * Note that enableHttpCache(DISK) is needed to take advantage of 0-RTT | |
92 * connection establishment between sessions. | |
93 * | |
94 * @param server URL of the server that supports QUIC. | |
95 * @param alternatePort to use for QUIC. | |
96 */ | |
97 public HttpUrlRequestFactoryConfig addQuicHint(String server, | |
Ryan Hamilton
2014/09/15 18:29:44
Do you expect callers will effectively hard-code c
mef
2014/09/15 21:01:01
Done.
| |
98 int alternatePort) { | |
99 try { | |
100 JSONArray quicHints = mConfig.optJSONArray( | |
101 UrlRequestContextConfig.QUIC_HINTS); | |
102 if (quicHints == null) { | |
103 quicHints = new JSONArray(); | |
104 mConfig.put(UrlRequestContextConfig.QUIC_HINTS, quicHints); | |
105 } | |
106 | |
107 JSONObject hint = new JSONObject(); | |
108 hint.put(UrlRequestContextConfig.QUIC_HINT_SERVER, server); | |
109 hint.put(UrlRequestContextConfig.QUIC_HINT_ALT_PORT, alternatePort); | |
110 quicHints.put(hint); | |
111 } catch (JSONException e) { | |
112 ; | |
113 } | |
114 return this; | |
115 } | |
116 | |
117 /** | |
89 * Get JSON string representation of the config. | 118 * Get JSON string representation of the config. |
90 */ | 119 */ |
91 public String toString() { | 120 public String toString() { |
92 return mConfig.toString(); | 121 return mConfig.toString(); |
93 } | 122 } |
94 | 123 |
95 /** | 124 /** |
96 * Sets a boolean value in the config. Returns a reference to the same | 125 * Sets a boolean value in the config. Returns a reference to the same |
97 * config object, so you can chain put calls together. | 126 * config object, so you can chain put calls together. |
98 */ | 127 */ |
(...skipping 27 matching lines...) Expand all Loading... | |
126 try { | 155 try { |
127 mConfig.put(key, value); | 156 mConfig.put(key, value); |
128 } catch (JSONException e) { | 157 } catch (JSONException e) { |
129 ; | 158 ; |
130 } | 159 } |
131 return this; | 160 return this; |
132 } | 161 } |
133 | 162 |
134 private JSONObject mConfig = new JSONObject(); | 163 private JSONObject mConfig = new JSONObject(); |
135 } | 164 } |
OLD | NEW |