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

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: Addressed Paul's comments 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 * The value of a connection metric is unknown.
27 */
28 public static final int CONNECTION_METRIC_UNKNOWN = -1;
29
30 /**
31 * The estimate of the effective connection type is unknown.
32 *
33 * @see #getEffectiveConnectionType
34 */
35 public static final int EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0;
36
37 /**
38 * The device is offline.
39 *
40 * @see #getEffectiveConnectionType
41 */
42 public static final int EFFECTIVE_CONNECTION_TYPE_OFFLINE = 1;
43
44 /**
45 * The estimate of the effective connection type is slow 2G.
46 *
47 * @see #getEffectiveConnectionType
48 */
49 public static final int EFFECTIVE_CONNECTION_TYPE_SLOW_2G = 2;
50
51 /**
52 * The estimate of the effective connection type is 2G.
53 *
54 * @see #getEffectiveConnectionType
55 */
56 public static final int EFFECTIVE_CONNECTION_TYPE_2G = 3;
57
58 /**
59 * The estimate of the effective connection type is 3G.
60 *
61 * @see #getEffectiveConnectionType
62 */
63 public static final int EFFECTIVE_CONNECTION_TYPE_3G = 4;
64
65 /**
66 * The estimate of the effective connection type is 4G.
67 *
68 * @see #getEffectiveConnectionType
69 */
70 public static final int EFFECTIVE_CONNECTION_TYPE_4G = 5;
71
72 /**
26 * Builder for building {@link ExperimentalCronetEngine}. 73 * Builder for building {@link ExperimentalCronetEngine}.
27 */ 74 */
28 public static class Builder extends CronetEngine.Builder { 75 public static class Builder extends CronetEngine.Builder {
29 /** 76 /**
30 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 77 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
31 * 78 *
32 * @param context Android {@link Context} for engine to use. 79 * @param context Android {@link Context} for engine to use.
33 */ 80 */
34 public Builder(Context context) { 81 public Builder(Context context) {
35 super(context); 82 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, 275 * NetLog files must not already exist in the directory. If activ ely logging,
229 * this method is ignored. 276 * this method is ignored.
230 * @param logAll {@code true} to include basic events, user cookies, 277 * @param logAll {@code true} to include basic events, user cookies,
231 * credentials and all transferred bytes in the log. This option presents a 278 * 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 279 * 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. 280 * 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. 281 * {@code false} to just include basic events.
235 * @param maxSize the maximum total disk space in bytes that should be used by NetLog. Actual 282 * @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. 283 * disk space usage may exceed this limit slightly.
237 */ 284 */
238 public abstract void startNetLogToDisk(String dirPath, boolean logAll, int m axSize); 285 public void startNetLogToDisk(String dirPath, boolean logAll, int maxSize){} ;
239 286
240 /** 287 /**
241 * Returns the effective connection type computed by the network quality 288 * Returns an estimate of the effective connection type computed by the netw ork quality
242 * estimator. 289 * estimator. Call {@link Builder#enableNetworkQualityEstimator} to begin co mputing this
290 * value.
291 *
292 * @return the estimated connection type. The returned value is one of
293 * {@link #EFFECTIVE_CONNECTION_TYPE_UNKNOWN EFFECTIVE_CONNECTION_TYPE_* }.
243 */ 294 */
244 public abstract int getEffectiveConnectionType(); 295 public int getEffectiveConnectionType() {
296 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
297 };
pauljensen 2016/11/09 19:55:16 please remove all these semicolons after the }'s
kapishnikov 2016/11/09 20:17:19 Done.
245 298
246 /** 299 /**
247 * Configures the network quality estimator for testing. This must be called 300 * Configures the network quality estimator for testing. This must be called
248 * before round trip time and throughput listeners are added, and after the 301 * before round trip time and throughput listeners are added, and after the
249 * network quality estimator has been enabled. 302 * network quality estimator has been enabled.
250 * @param useLocalHostRequests include requests to localhost in estimates. 303 * @param useLocalHostRequests include requests to localhost in estimates.
251 * @param useSmallerResponses include small responses in throughput 304 * @param useSmallerResponses include small responses in throughput
252 * estimates. 305 * estimates.
253 */ 306 */
254 public abstract void configureNetworkQualityEstimatorForTesting( 307 public void configureNetworkQualityEstimatorForTesting(
255 boolean useLocalHostRequests, boolean useSmallerResponses); 308 boolean useLocalHostRequests, boolean useSmallerResponses){};
256 309
257 /** 310 /**
258 * Registers a listener that gets called whenever the network quality 311 * Registers a listener that gets called whenever the network quality
259 * estimator witnesses a sample round trip time. This must be called 312 * estimator witnesses a sample round trip time. This must be called
260 * after {@link Builder#enableNetworkQualityEstimator}, and with throw an 313 * after {@link Builder#enableNetworkQualityEstimator}, and with throw an
261 * exception otherwise. Round trip times may be recorded at various layers 314 * 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. 315 * 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 316 * The listener is called on the {@link java.util.concurrent.Executor} that
264 * is passed to {@link Builder#enableNetworkQualityEstimator}. 317 * is passed to {@link Builder#enableNetworkQualityEstimator}.
265 * @param listener the listener of round trip times. 318 * @param listener the listener of round trip times.
266 */ 319 */
267 public abstract void addRttListener(NetworkQualityRttListener listener); 320 public void addRttListener(NetworkQualityRttListener listener){};
268 321
269 /** 322 /**
270 * Removes a listener of round trip times if previously registered with 323 * Removes a listener of round trip times if previously registered with
271 * {@link #addRttListener}. This should be called after a 324 * {@link #addRttListener}. This should be called after a
272 * {@link NetworkQualityRttListener} is added in order to stop receiving 325 * {@link NetworkQualityRttListener} is added in order to stop receiving
273 * observations. 326 * observations.
274 * @param listener the listener of round trip times. 327 * @param listener the listener of round trip times.
275 */ 328 */
276 public abstract void removeRttListener(NetworkQualityRttListener listener); 329 public void removeRttListener(NetworkQualityRttListener listener){};
277 330
278 /** 331 /**
279 * Registers a listener that gets called whenever the network quality 332 * Registers a listener that gets called whenever the network quality
280 * estimator witnesses a sample throughput measurement. This must be called 333 * estimator witnesses a sample throughput measurement. This must be called
281 * after {@link Builder#enableNetworkQualityEstimator}. Throughput observati ons 334 * after {@link Builder#enableNetworkQualityEstimator}. Throughput observati ons
282 * are computed by measuring bytes read over the active network interface 335 * 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 336 * 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 337 * is called on the {@link java.util.concurrent.Executor} that is passed to
285 * {@link Builder#enableNetworkQualityEstimator}. 338 * {@link Builder#enableNetworkQualityEstimator}.
286 * @param listener the listener of throughput. 339 * @param listener the listener of throughput.
287 */ 340 */
288 public abstract void addThroughputListener(NetworkQualityThroughputListener listener); 341 public void addThroughputListener(NetworkQualityThroughputListener listener) {};
289 342
290 /** 343 /**
291 * Removes a listener of throughput. This should be called after a 344 * Removes a listener of throughput. This should be called after a
292 * {@link NetworkQualityThroughputListener} is added with 345 * {@link NetworkQualityThroughputListener} is added with
293 * {@link #addThroughputListener} in order to stop receiving observations. 346 * {@link #addThroughputListener} in order to stop receiving observations.
294 * @param listener the listener of throughput. 347 * @param listener the listener of throughput.
295 */ 348 */
296 public abstract void removeThroughputListener(NetworkQualityThroughputListen er listener); 349 public void removeThroughputListener(NetworkQualityThroughputListener listen er){};
297 350
298 /** 351 /**
299 * Establishes a new connection to the resource specified by the {@link URL} {@code url} 352 * Establishes a new connection to the resource specified by the {@link URL} {@code url}
300 * using the given proxy. 353 * using the given proxy.
301 * <p> 354 * <p>
302 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain 355 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain
303 * limitations, see {@link #createURLStreamHandlerFactory} for details. 356 * limitations, see {@link #createURLStreamHandlerFactory} for details.
304 * 357 *
305 * @param url URL of resource to connect to. 358 * @param url URL of resource to connect to.
306 * @param proxy proxy to use when establishing connection. 359 * @param proxy proxy to use when establishing connection.
307 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. 360 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine.
308 * @throws IOException if an error occurs while opening the connection. 361 * @throws IOException if an error occurs while opening the connection.
309 */ 362 */
310 // TODO(pauljensen): Expose once implemented, http://crbug.com/418111 363 // TODO(pauljensen): Expose once implemented, http://crbug.com/418111
311 public abstract URLConnection openConnection(URL url, Proxy proxy) throws IO Exception; 364 public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
365 return url.openConnection(proxy);
366 }
312 367
313 /** 368 /**
314 * Registers a listener that gets called after the end of each request with the request info. 369 * Registers a listener that gets called after the end of each request with the request info.
315 * 370 *
316 * <p>The listener is called on an {@link java.util.concurrent.Executor} pro vided by the 371 * <p>The listener is called on an {@link java.util.concurrent.Executor} pro vided by the
317 * listener. 372 * listener.
318 * 373 *
319 * @param listener the listener for finished requests. 374 * @param listener the listener for finished requests.
320 */ 375 */
321 public abstract void addRequestFinishedListener(RequestFinishedInfo.Listener listener); 376 public void addRequestFinishedListener(RequestFinishedInfo.Listener listener ){};
322 377
323 /** 378 /**
324 * Removes a finished request listener. 379 * Removes a finished request listener.
325 * 380 *
326 * @param listener the listener to remove. 381 * @param listener the listener to remove.
327 */ 382 */
328 public abstract void removeRequestFinishedListener(RequestFinishedInfo.Liste ner listener); 383 public void removeRequestFinishedListener(RequestFinishedInfo.Listener liste ner){};
329 384
330 /** 385 /**
331 * Returns serialized representation of certificate verifier's cache 386 * Returns serialized representation of certificate verifier's cache
332 * which contains the list of hosts/certificates and the certificate 387 * which contains the list of hosts/certificates and the certificate
333 * verification results. May block until data is received from the network 388 * verification results. May block until data is received from the network
334 * thread (will timeout after the specified timeout). In case of timeout, it 389 * thread (will timeout after the specified timeout). In case of timeout, it
335 * returns the previous saved value. 390 * returns the previous saved value.
336 * 391 *
337 * @param timeout in milliseconds. If timeout is 0, it will use default valu e. 392 * @param timeout in milliseconds. If timeout is 0, it will use default valu e.
338 * @return serialized representation of certificate verification results 393 * @return serialized representation of certificate verification results
339 * data. 394 * data.
340 */ 395 */
341 public abstract String getCertVerifierData(long timeout); 396 public String getCertVerifierData(long timeout) {
397 return "";
398 };
342 399
343 /** 400 /**
344 * Returns the HTTP RTT estimate (in milliseconds) computed by the network 401 * Returns the HTTP RTT estimate (in milliseconds) computed by the network
345 * quality estimator. Set to 402 * quality estimator. Set to {@link #CONNECTION_METRIC_UNKNOWN} if the value
346 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value
347 * is unavailable. This must be called after 403 * is unavailable. This must be called after
348 * {@link Builder#enableNetworkQualityEstimator}, and will throw an 404 * {@link Builder#enableNetworkQualityEstimator}, and will throw an
349 * exception otherwise. 405 * exception otherwise.
350 * @return Estimate of the HTTP RTT in milliseconds. 406 * @return Estimate of the HTTP RTT in milliseconds.
351 */ 407 */
352 public abstract int getHttpRttMs(); 408 public int getHttpRttMs() {
409 return CONNECTION_METRIC_UNKNOWN;
410 };
353 411
354 /** 412 /**
355 * Returns the transport RTT estimate (in milliseconds) computed by the 413 * Returns the transport RTT estimate (in milliseconds) computed by the
356 * network quality estimator. Set to 414 * network quality estimator. Set to {@link #CONNECTION_METRIC_UNKNOWN} if
357 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value is 415 * the value is unavailable. This must be called after
358 * unavailable. This must be called after
359 * {@link Builder#enableNetworkQualityEstimator}, and will throw an 416 * {@link Builder#enableNetworkQualityEstimator}, and will throw an
360 * exception otherwise. 417 * exception otherwise.
361 * @return Estimate of the transport RTT in milliseconds. 418 * @return Estimate of the transport RTT in milliseconds.
362 */ 419 */
363 public abstract int getTransportRttMs(); 420 public int getTransportRttMs() {
421 return CONNECTION_METRIC_UNKNOWN;
422 }
364 423
365 /** 424 /**
366 * Returns the downstream throughput estimate (in kilobits per second) 425 * Returns the downstream throughput estimate (in kilobits per second)
367 * computed by the network quality estimator. Set to 426 * computed by the network quality estimator. Set to
368 * {@link RttThroughputValues.INVALID_RTT_THROUGHPUT} if a valid value is 427 * {@link #CONNECTION_METRIC_UNKNOWN} if the value is
369 * unavailable. This must be called after 428 * unavailable. This must be called after
370 * {@link Builder#enableNetworkQualityEstimator}, and will 429 * {@link Builder#enableNetworkQualityEstimator}, and will
371 * throw an exception otherwise. 430 * throw an exception otherwise.
372 * @return Estimate of the downstream throughput in kilobits per second. 431 * @return Estimate of the downstream throughput in kilobits per second.
373 */ 432 */
374 public abstract int getDownstreamThroughputKbps(); 433 public int getDownstreamThroughputKbps() {
434 return CONNECTION_METRIC_UNKNOWN;
435 };
375 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698