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 android.content.Context; | 7 import android.content.Context; |
8 import android.util.Log; | 8 import android.util.Log; |
9 | 9 |
10 import java.lang.reflect.Constructor; | 10 import java.lang.reflect.Constructor; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 */ | 87 */ |
88 public abstract void startNetLogToFile(String fileName, boolean logAll); | 88 public abstract void startNetLogToFile(String fileName, boolean logAll); |
89 | 89 |
90 /** | 90 /** |
91 * Stops NetLog logging and flushes file to disk. If a logging session is | 91 * Stops NetLog logging and flushes file to disk. If a logging session is |
92 * not in progress, this call is ignored. | 92 * not in progress, this call is ignored. |
93 */ | 93 */ |
94 public abstract void stopNetLog(); | 94 public abstract void stopNetLog(); |
95 | 95 |
96 /** | 96 /** |
| 97 * Enables the network quality estimator, which collects and reports |
| 98 * measurements of round trip time (RTT) and downstream throughput at |
| 99 * various layers of the network stack. After enabling the estimator, |
| 100 * listeners of RTT and throughput can be added with |
| 101 * {@link #addRttListener} and {@link #addThroughputListener} and |
| 102 * removed with {@link #removeRttListener} and |
| 103 * {@link #removeThroughputListener}. The estimator uses memory and CPU |
| 104 * only when enabled. |
| 105 * @param executor an executor that will be used to notified all |
| 106 * added RTT and throughput listeners. |
| 107 */ |
| 108 public abstract void enableNetworkQualityEstimator(Executor executor); |
| 109 |
| 110 /** |
| 111 * Enables the network quality estimator for testing. This must be called |
| 112 * before round trip time and throughput listeners are added. Set both |
| 113 * boolean parameters to false for default behavior. |
| 114 * @param useLocalHostRequests include requests to localhost in estimates. |
| 115 * @param useSmallerResponses include small responses in throughput estimate
s. |
| 116 * @param executor an {@link java.util.concurrent.Executor} on which all |
| 117 * listeners will be called. |
| 118 */ |
| 119 abstract void enableNetworkQualityEstimator( |
| 120 boolean useLocalHostRequests, boolean useSmallerResponses, Executor
executor); |
| 121 |
| 122 /** |
| 123 * Registers an listener that gets called whenever the network quality |
| 124 * estimator witnesses a sample round trip time. This must be called |
| 125 * after {@link #enableNetworkQualityEstimator}. Round trip times may be |
| 126 * recorded at various layers of the network stack, including TCP, QUIC, |
| 127 * and at the URL request layer. The listener is called on the |
| 128 * {@link java.util.concurrent.Executor} that is passed to |
| 129 * {@link #enableNetworkQualityEstimator}. |
| 130 * @param listener the listener of round trip times. |
| 131 */ |
| 132 public abstract void addRttListener(NetworkQualityRttListener listener); |
| 133 |
| 134 /** |
| 135 * Removes an listener of round trip times if on the listener list. This |
| 136 * should be called after a NetworkQualityRttListener is added in order to |
| 137 * stop receiving observations. |
| 138 * @param listener the listener of round trip times. |
| 139 */ |
| 140 public abstract void removeRttListener(NetworkQualityRttListener listener); |
| 141 |
| 142 /** |
| 143 * Registers an listener that gets called whenever the network quality |
| 144 * estimator witnesses a sample throughput measurement. This must be called |
| 145 * after {@link #enableNetworkQualityEstimator}. Throughput observations |
| 146 * are computed by measuring bytes read over the active network interface |
| 147 * at times when at least one URL response is being received. The listener |
| 148 * is called on the {@link java.util.concurrent.Executor} that is passed to |
| 149 * {@link #enableNetworkQualityEstimator}. |
| 150 * @param listener the listener of throughput. |
| 151 */ |
| 152 public abstract void addThroughputListener(NetworkQualityThroughputListener
listener); |
| 153 |
| 154 /** |
| 155 * Removes an listener of throughput. This should be called after a |
| 156 * NetworkQualityThroughputListener is added in order to stop receiving |
| 157 * observations. |
| 158 * @param listener the listener of throughput. |
| 159 */ |
| 160 public abstract void removeThroughputListener(NetworkQualityThroughputListen
er listener); |
| 161 |
| 162 /** |
97 * Creates a {@link UrlRequestContext} with the given | 163 * Creates a {@link UrlRequestContext} with the given |
98 * {@link UrlRequestContextConfig}. | 164 * {@link UrlRequestContextConfig}. |
99 * @param context Android {@link Context}. | 165 * @param context Android {@link Context}. |
100 * @param config context configuration. | 166 * @param config context configuration. |
101 */ | 167 */ |
102 public static UrlRequestContext createContext(Context context, | 168 public static UrlRequestContext createContext(Context context, |
103 UrlRequestContextConfig config) { | 169 UrlRequestContextConfig config) { |
104 UrlRequestContext urlRequestContext = null; | 170 UrlRequestContext urlRequestContext = null; |
105 if (config.userAgent().isEmpty()) { | 171 if (config.userAgent().isEmpty()) { |
106 config.setUserAgent(UserAgent.from(context)); | 172 config.setUserAgent(UserAgent.from(context)); |
(...skipping 30 matching lines...) Expand all Loading... |
137 } catch (ClassNotFoundException e) { | 203 } catch (ClassNotFoundException e) { |
138 // Leave as null. | 204 // Leave as null. |
139 } catch (Exception e) { | 205 } catch (Exception e) { |
140 throw new IllegalStateException( | 206 throw new IllegalStateException( |
141 "Cannot instantiate: " + CRONET_URL_REQUEST_CONTEXT, | 207 "Cannot instantiate: " + CRONET_URL_REQUEST_CONTEXT, |
142 e); | 208 e); |
143 } | 209 } |
144 return urlRequestContext; | 210 return urlRequestContext; |
145 } | 211 } |
146 } | 212 } |
OLD | NEW |