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 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 * observers of RTT and throughput can be added with | |
| 101 * {@link #addRttObserver} and {@link #addThroughputObserver} and | |
| 102 * removed with {@link #removeRttObserver} and | |
| 103 * {@link #removeThroughputObserver}. 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 observers. | |
| 107 */ | |
| 108 public abstract void enableNetworkQualityEstimator(Executor executor); | |
|
mef
2015/09/25 19:06:42
I wonder whether this must be a runtime method, or
bengr
2015/09/29 23:22:50
Since this is experimental, let's leave it as a se
| |
| 109 | |
| 110 /** | |
| 111 * Enables the network quality estimator for testing. This must be called | |
| 112 * before round trip time and throughput observers 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 * observers will be called. | |
| 118 */ | |
| 119 abstract void enableNetworkQualityEstimator( | |
| 120 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); | |
| 121 | |
| 122 /** | |
| 123 * Registers an observer 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 observer is called on the | |
| 128 * {@link java.util.concurrent.Executor} that is passed to | |
| 129 * {@link #enableNetworkQualityEstimator}. | |
| 130 * @param observer the observer of round trip times. | |
| 131 */ | |
| 132 public abstract void addRttObserver(NetworkQualityRttObserver observer); | |
| 133 | |
| 134 /** | |
| 135 * Removes an observer of round trip times if on the observer list. This | |
| 136 * should be called after an RttObserver is added in order to stop | |
| 137 * receiving observations. | |
| 138 * @param observer the observer of round trip times. | |
| 139 */ | |
| 140 public abstract void removeRttObserver(NetworkQualityRttObserver observer); | |
| 141 | |
| 142 /** | |
| 143 * Registers an observer 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 observer | |
| 148 * is called on the {@link java.util.concurrent.Executor} that is passed to | |
| 149 * {@link #enableNetworkQualityEstimator}. | |
| 150 * @param observer the observer of throughput. | |
| 151 */ | |
| 152 public abstract void addThroughputObserver(NetworkQualityThroughputObserver observer); | |
| 153 | |
| 154 /** | |
| 155 * Removes an observer of throughput. This should be called after a | |
| 156 * ThroughputObserver is added in order to stop receiving observations. | |
| 157 * @param observer the observer of throughput. | |
| 158 */ | |
| 159 public abstract void removeThroughputObserver(NetworkQualityThroughputObserv er observer); | |
| 160 | |
| 161 /** | |
| 97 * Creates a {@link UrlRequestContext} with the given | 162 * Creates a {@link UrlRequestContext} with the given |
| 98 * {@link UrlRequestContextConfig}. | 163 * {@link UrlRequestContextConfig}. |
| 99 * @param context Android {@link Context}. | 164 * @param context Android {@link Context}. |
| 100 * @param config context configuration. | 165 * @param config context configuration. |
| 101 */ | 166 */ |
| 102 public static UrlRequestContext createContext(Context context, | 167 public static UrlRequestContext createContext(Context context, |
| 103 UrlRequestContextConfig config) { | 168 UrlRequestContextConfig config) { |
| 104 UrlRequestContext urlRequestContext = null; | 169 UrlRequestContext urlRequestContext = null; |
| 105 if (config.userAgent().isEmpty()) { | 170 if (config.userAgent().isEmpty()) { |
| 106 config.setUserAgent(UserAgent.from(context)); | 171 config.setUserAgent(UserAgent.from(context)); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 137 } catch (ClassNotFoundException e) { | 202 } catch (ClassNotFoundException e) { |
| 138 // Leave as null. | 203 // Leave as null. |
| 139 } catch (Exception e) { | 204 } catch (Exception e) { |
| 140 throw new IllegalStateException( | 205 throw new IllegalStateException( |
| 141 "Cannot instantiate: " + CRONET_URL_REQUEST_CONTEXT, | 206 "Cannot instantiate: " + CRONET_URL_REQUEST_CONTEXT, |
| 142 e); | 207 e); |
| 143 } | 208 } |
| 144 return urlRequestContext; | 209 return urlRequestContext; |
| 145 } | 210 } |
| 146 } | 211 } |
| OLD | NEW |