Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: components/cronet/android/api/src/org/chromium/net/ExperimentalCronetEngine.java

Issue 2470903002: Add default implementation of experimental methods (Closed)
Patch Set: Added EFFECTIVE_ prefix to CONNECTION_TYPE constants Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package org.chromium.net; 4 package org.chromium.net;
5 5
6 import android.content.Context; 6 import android.content.Context;
7 import android.support.annotation.VisibleForTesting; 7 import android.support.annotation.VisibleForTesting;
8 8
9 import java.io.IOException; 9 import java.io.IOException;
10 import java.net.Proxy; 10 import java.net.Proxy;
11 import java.net.URL; 11 import java.net.URL;
12 import java.net.URLConnection; 12 import java.net.URLConnection;
13 import java.util.Date; 13 import java.util.Date;
14 import java.util.Set; 14 import java.util.Set;
15 import java.util.concurrent.Executor; 15 import java.util.concurrent.Executor;
16 16
17 /** 17 /**
18 * {@link CronetEngine} that exposes experimental features. Use {@link Builder} to build an 18 * {@link CronetEngine} that exposes experimental features. Use {@link Builder} to build an
19 * instance of this class. Every instance of {@link CronetEngine} can be casted to an instance 19 * instance of this class. Every instance of {@link CronetEngine} can be casted to an instance
20 * of this class. 20 * of this class.
21 * 21 *
22 * {@hide since this class exposes experimental features that should be hidden.} 22 * {@hide since this class exposes experimental features that should be hidden.}
23 */ 23 */
24 public abstract class ExperimentalCronetEngine extends CronetEngine { 24 public abstract class ExperimentalCronetEngine extends CronetEngine {
25 /** 25 /**
26 * Unknown rtt throughput value.
pauljensen 2016/11/08 14:00:32 What is "rtt throughput"? rtt should be capitalize
kapishnikov 2016/11/08 15:29:45 Renamed to CONNECTION_METRIC_UNKNOWN and changed t
27 */
28 public static final int RTT_THROUGHPUT_UNKNOWN = -1;
pauljensen 2016/11/08 14:00:32 We need a better name than "RTT_THROUGHPUT". Perha
kapishnikov 2016/11/08 15:29:45 Done.
29
30 /**
31 * The connection type is unknown.
pauljensen 2016/11/08 14:00:32 This needs a lot more description. It should ment
kapishnikov 2016/11/08 15:29:45 Done.
32 */
33 public static final int EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0;
34
35 /**
36 * The device is offline.
37 */
38 public static final int EFFECTIVE_CONNECTION_TYPE_OFFLINE = 1;
39
40 /**
41 * The connection type is slow 2G.
42 */
43 public static final int EFFECTIVE_CONNECTION_TYPE_SLOW_2G = 2;
44
45 /**
46 * The connection type is 2G.
47 */
48 public static final int EFFECTIVE_CONNECTION_TYPE_2G = 3;
49
50 /**
51 * The connection type is 3G.
52 */
53 public static final int EFFECTIVE_CONNECTION_TYPE_3G = 4;
54
55 /**
56 * The connection type is 4G.
57 */
58 public static final int EFFECTIVE_CONNECTION_TYPE_4G = 5;
59
60 /**
26 * Builder for building {@link ExperimentalCronetEngine}. 61 * Builder for building {@link ExperimentalCronetEngine}.
27 */ 62 */
28 public static class Builder extends CronetEngine.Builder { 63 public static class Builder extends CronetEngine.Builder {
29 /** 64 /**
30 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 65 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
31 * 66 *
32 * @param context Android {@link Context} for engine to use. 67 * @param context Android {@link Context} for engine to use.
33 */ 68 */
34 public Builder(Context context) { 69 public Builder(Context context) {
35 super(context); 70 super(context);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 * NetLog files must not already exist in the directory. If activ ely logging, 263 * NetLog files must not already exist in the directory. If activ ely logging,
229 * this method is ignored. 264 * this method is ignored.
230 * @param logAll {@code true} to include basic events, user cookies, 265 * @param logAll {@code true} to include basic events, user cookies,
231 * credentials and all transferred bytes in the log. This option presents a 266 * credentials and all transferred bytes in the log. This option presents a
232 * privacy risk, since it exposes the user's credentials, and sho uld only be 267 * privacy risk, since it exposes the user's credentials, and sho uld only be
233 * used with the user's consent and in situations where the log w on't be public. 268 * used with the user's consent and in situations where the log w on't be public.
234 * {@code false} to just include basic events. 269 * {@code false} to just include basic events.
235 * @param maxSize the maximum total disk space in bytes that should be used by NetLog. Actual 270 * @param maxSize the maximum total disk space in bytes that should be used by NetLog. Actual
236 * disk space usage may exceed this limit slightly. 271 * disk space usage may exceed this limit slightly.
237 */ 272 */
238 public abstract void startNetLogToDisk(String dirPath, boolean logAll, int m axSize); 273 public void startNetLogToDisk(String dirPath, boolean logAll, int maxSize){} ;
239 274
240 /** 275 /**
241 * Returns the effective connection type computed by the network quality 276 * Returns the effective connection type computed by the network quality
242 * estimator. 277 * estimator.
pauljensen 2016/11/08 14:00:32 Add "Call {@link Builder#enableNetworkQualityEstim
kapishnikov 2016/11/08 15:29:45 Done.
243 */ 278 */
244 public abstract int getEffectiveConnectionType(); 279 public int getEffectiveConnectionType() {
280 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
281 };
245 282
246 /** 283 /**
247 * Configures the network quality estimator for testing. This must be called 284 * Configures the network quality estimator for testing. This must be called
248 * before round trip time and throughput listeners are added, and after the 285 * before round trip time and throughput listeners are added, and after the
249 * network quality estimator has been enabled. 286 * network quality estimator has been enabled.
250 * @param useLocalHostRequests include requests to localhost in estimates. 287 * @param useLocalHostRequests include requests to localhost in estimates.
251 * @param useSmallerResponses include small responses in throughput 288 * @param useSmallerResponses include small responses in throughput
252 * estimates. 289 * estimates.
253 */ 290 */
254 public abstract void configureNetworkQualityEstimatorForTesting( 291 public void configureNetworkQualityEstimatorForTesting(
255 boolean useLocalHostRequests, boolean useSmallerResponses); 292 boolean useLocalHostRequests, boolean useSmallerResponses){};
256 293
257 /** 294 /**
258 * Registers a listener that gets called whenever the network quality 295 * Registers a listener that gets called whenever the network quality
259 * estimator witnesses a sample round trip time. This must be called 296 * estimator witnesses a sample round trip time. This must be called
260 * after {@link Builder#enableNetworkQualityEstimator}, and with throw an 297 * after {@link Builder#enableNetworkQualityEstimator}, and with throw an
261 * exception otherwise. Round trip times may be recorded at various layers 298 * exception otherwise. Round trip times may be recorded at various layers
262 * of the network stack, including TCP, QUIC, and at the URL request layer. 299 * of the network stack, including TCP, QUIC, and at the URL request layer.
263 * The listener is called on the {@link java.util.concurrent.Executor} that 300 * The listener is called on the {@link java.util.concurrent.Executor} that
264 * is passed to {@link Builder#enableNetworkQualityEstimator}. 301 * is passed to {@link Builder#enableNetworkQualityEstimator}.
265 * @param listener the listener of round trip times. 302 * @param listener the listener of round trip times.
266 */ 303 */
267 public abstract void addRttListener(NetworkQualityRttListener listener); 304 public void addRttListener(NetworkQualityRttListener listener){};
268 305
269 /** 306 /**
270 * Removes a listener of round trip times if previously registered with 307 * Removes a listener of round trip times if previously registered with
271 * {@link #addRttListener}. This should be called after a 308 * {@link #addRttListener}. This should be called after a
272 * {@link NetworkQualityRttListener} is added in order to stop receiving 309 * {@link NetworkQualityRttListener} is added in order to stop receiving
273 * observations. 310 * observations.
274 * @param listener the listener of round trip times. 311 * @param listener the listener of round trip times.
275 */ 312 */
276 public abstract void removeRttListener(NetworkQualityRttListener listener); 313 public void removeRttListener(NetworkQualityRttListener listener){};
277 314
278 /** 315 /**
279 * Registers a listener that gets called whenever the network quality 316 * Registers a listener that gets called whenever the network quality
280 * estimator witnesses a sample throughput measurement. This must be called 317 * estimator witnesses a sample throughput measurement. This must be called
281 * after {@link Builder#enableNetworkQualityEstimator}. Throughput observati ons 318 * after {@link Builder#enableNetworkQualityEstimator}. Throughput observati ons
282 * are computed by measuring bytes read over the active network interface 319 * are computed by measuring bytes read over the active network interface
283 * at times when at least one URL response is being received. The listener 320 * at times when at least one URL response is being received. The listener
284 * is called on the {@link java.util.concurrent.Executor} that is passed to 321 * is called on the {@link java.util.concurrent.Executor} that is passed to
285 * {@link Builder#enableNetworkQualityEstimator}. 322 * {@link Builder#enableNetworkQualityEstimator}.
286 * @param listener the listener of throughput. 323 * @param listener the listener of throughput.
287 */ 324 */
288 public abstract void addThroughputListener(NetworkQualityThroughputListener listener); 325 public void addThroughputListener(NetworkQualityThroughputListener listener) {};
289 326
290 /** 327 /**
291 * Removes a listener of throughput. This should be called after a 328 * Removes a listener of throughput. This should be called after a
292 * {@link NetworkQualityThroughputListener} is added with 329 * {@link NetworkQualityThroughputListener} is added with
293 * {@link #addThroughputListener} in order to stop receiving observations. 330 * {@link #addThroughputListener} in order to stop receiving observations.
294 * @param listener the listener of throughput. 331 * @param listener the listener of throughput.
295 */ 332 */
296 public abstract void removeThroughputListener(NetworkQualityThroughputListen er listener); 333 public void removeThroughputListener(NetworkQualityThroughputListener listen er){};
297 334
298 /** 335 /**
299 * Establishes a new connection to the resource specified by the {@link URL} {@code url} 336 * Establishes a new connection to the resource specified by the {@link URL} {@code url}
300 * using the given proxy. 337 * using the given proxy.
301 * <p> 338 * <p>
302 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain 339 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain
303 * limitations, see {@link #createURLStreamHandlerFactory} for details. 340 * limitations, see {@link #createURLStreamHandlerFactory} for details.
304 * 341 *
305 * @param url URL of resource to connect to. 342 * @param url URL of resource to connect to.
306 * @param proxy proxy to use when establishing connection. 343 * @param proxy proxy to use when establishing connection.
307 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. 344 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine.
308 * @throws IOException if an error occurs while opening the connection. 345 * @throws IOException if an error occurs while opening the connection.
309 */ 346 */
310 // TODO(pauljensen): Expose once implemented, http://crbug.com/418111 347 // TODO(pauljensen): Expose once implemented, http://crbug.com/418111
311 public abstract URLConnection openConnection(URL url, Proxy proxy) throws IO Exception; 348 public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
349 return url.openConnection(proxy);
350 }
312 351
313 /** 352 /**
314 * Registers a listener that gets called after the end of each request with the request info. 353 * Registers a listener that gets called after the end of each request with the request info.
315 * 354 *
316 * <p>The listener is called on an {@link java.util.concurrent.Executor} pro vided by the 355 * <p>The listener is called on an {@link java.util.concurrent.Executor} pro vided by the
317 * listener. 356 * listener.
318 * 357 *
319 * @param listener the listener for finished requests. 358 * @param listener the listener for finished requests.
320 */ 359 */
321 public abstract void addRequestFinishedListener(RequestFinishedInfo.Listener listener); 360 public void addRequestFinishedListener(RequestFinishedInfo.Listener listener ){};
322 361
323 /** 362 /**
324 * Removes a finished request listener. 363 * Removes a finished request listener.
325 * 364 *
326 * @param listener the listener to remove. 365 * @param listener the listener to remove.
327 */ 366 */
328 public abstract void removeRequestFinishedListener(RequestFinishedInfo.Liste ner listener); 367 public void removeRequestFinishedListener(RequestFinishedInfo.Listener liste ner){};
329 368
330 /** 369 /**
331 * Returns serialized representation of certificate verifier's cache 370 * Returns serialized representation of certificate verifier's cache
332 * which contains the list of hosts/certificates and the certificate 371 * which contains the list of hosts/certificates and the certificate
333 * verification results. May block until data is received from the network 372 * verification results. May block until data is received from the network
334 * thread (will timeout after the specified timeout). In case of timeout, it 373 * thread (will timeout after the specified timeout). In case of timeout, it
335 * returns the previous saved value. 374 * returns the previous saved value.
336 * 375 *
337 * @param timeout in milliseconds. If timeout is 0, it will use default valu e. 376 * @param timeout in milliseconds. If timeout is 0, it will use default valu e.
338 * @return serialized representation of certificate verification results 377 * @return serialized representation of certificate verification results
339 * data. 378 * data.
340 */ 379 */
341 public abstract String getCertVerifierData(long timeout); 380 public String getCertVerifierData(long timeout) {
381 return "";
382 };
342 383
343 /** 384 /**
344 * Returns the HTTP RTT estimate (in milliseconds) computed by the network 385 * Returns the HTTP RTT estimate (in milliseconds) computed by the network
345 * quality estimator. Set to 386 * quality estimator. Set to {@link #RTT_THROUGHPUT_UNKNOWN} if a valid valu e
pauljensen 2016/11/08 14:00:32 "if a valid value is unavailable" made more sense
kapishnikov 2016/11/08 15:29:45 Changed to CONNECTION_METRIC_UNKNOWN + made small
346 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value
347 * is unavailable. This must be called after 387 * is unavailable. This must be called after
348 * {@link Builder#enableNetworkQualityEstimator}, and will throw an 388 * {@link Builder#enableNetworkQualityEstimator}, and will throw an
349 * exception otherwise. 389 * exception otherwise.
350 * @return Estimate of the HTTP RTT in milliseconds. 390 * @return Estimate of the HTTP RTT in milliseconds.
351 */ 391 */
352 public abstract int getHttpRttMs(); 392 public int getHttpRttMs() {
393 return RTT_THROUGHPUT_UNKNOWN;
394 };
353 395
354 /** 396 /**
355 * Returns the transport RTT estimate (in milliseconds) computed by the 397 * Returns the transport RTT estimate (in milliseconds) computed by the
356 * network quality estimator. Set to 398 * network quality estimator. Set to {@link #RTT_THROUGHPUT_UNKNOWN} if
357 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value is 399 * a valid value is unavailable. This must be called after
358 * unavailable. This must be called after
359 * {@link Builder#enableNetworkQualityEstimator}, and will throw an 400 * {@link Builder#enableNetworkQualityEstimator}, and will throw an
360 * exception otherwise. 401 * exception otherwise.
361 * @return Estimate of the transport RTT in milliseconds. 402 * @return Estimate of the transport RTT in milliseconds.
362 */ 403 */
363 public abstract int getTransportRttMs(); 404 public int getTransportRttMs() {
405 return RTT_THROUGHPUT_UNKNOWN;
406 }
364 407
365 /** 408 /**
366 * Returns the downstream throughput estimate (in kilobits per second) 409 * Returns the downstream throughput estimate (in kilobits per second)
367 * computed by the network quality estimator. Set to 410 * computed by the network quality estimator. Set to
368 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value is 411 * {@link #RTT_THROUGHPUT_UNKNOWN} if a valid value is
369 * unavailable. This must be called after 412 * unavailable. This must be called after
370 * {@link Builder#enableNetworkQualityEstimator}, and will 413 * {@link Builder#enableNetworkQualityEstimator}, and will
371 * throw an exception otherwise. 414 * throw an exception otherwise.
372 * @return Estimate of the downstream throughput in kilobits per second. 415 * @return Estimate of the downstream throughput in kilobits per second.
373 */ 416 */
374 public abstract int getDownstreamThroughputKbps(); 417 public int getDownstreamThroughputKbps() {
418 return RTT_THROUGHPUT_UNKNOWN;
419 };
375 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698