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

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

Issue 2045703003: Enable NQE when Cronet Engine is built (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mef comments Created 4 years, 5 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.net.http.HttpResponseCache; 9 import android.net.http.HttpResponseCache;
10 import android.support.annotation.IntDef; 10 import android.support.annotation.IntDef;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 private boolean mSdchEnabled; 113 private boolean mSdchEnabled;
114 private String mDataReductionProxyKey; 114 private String mDataReductionProxyKey;
115 private String mDataReductionProxyPrimaryProxy; 115 private String mDataReductionProxyPrimaryProxy;
116 private String mDataReductionProxyFallbackProxy; 116 private String mDataReductionProxyFallbackProxy;
117 private String mDataReductionProxySecureProxyCheckUrl; 117 private String mDataReductionProxySecureProxyCheckUrl;
118 private boolean mDisableCache; 118 private boolean mDisableCache;
119 private int mHttpCacheMode; 119 private int mHttpCacheMode;
120 private long mHttpCacheMaxSize; 120 private long mHttpCacheMaxSize;
121 private String mExperimentalOptions; 121 private String mExperimentalOptions;
122 private long mMockCertVerifier; 122 private long mMockCertVerifier;
123 private boolean mNetworkQualityEstimatorEnabled;
123 124
124 /** 125 /**
125 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 126 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
126 * @param context Android {@link Context} for engine to use. 127 * @param context Android {@link Context} for engine to use.
127 */ 128 */
128 public Builder(Context context) { 129 public Builder(Context context) {
129 mContext = context; 130 mContext = context;
130 setLibraryName("cronet"); 131 setLibraryName("cronet");
131 enableLegacyMode(false); 132 enableLegacyMode(false);
132 enableQUIC(false); 133 enableQUIC(false);
133 enableHTTP2(true); 134 enableHTTP2(true);
134 enableSDCH(false); 135 enableSDCH(false);
135 enableHttpCache(HTTP_CACHE_DISABLED, 0); 136 enableHttpCache(HTTP_CACHE_DISABLED, 0);
137 enableNetworkQualityEstimator(false);
136 } 138 }
137 139
138 /** 140 /**
139 * Constructs a User-Agent string including application name and version , 141 * Constructs a User-Agent string including application name and version ,
140 * system build version, model and id, and Cronet version. 142 * system build version, model and id, and Cronet version.
141 * 143 *
142 * @return User-Agent string. 144 * @return User-Agent string.
143 */ 145 */
144 public String getDefaultUserAgent() { 146 public String getDefaultUserAgent() {
145 return UserAgent.from(mContext); 147 return UserAgent.from(mContext);
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 public Builder setMockCertVerifierForTesting(long mockCertVerifier) { 599 public Builder setMockCertVerifierForTesting(long mockCertVerifier) {
598 mMockCertVerifier = mockCertVerifier; 600 mMockCertVerifier = mockCertVerifier;
599 return this; 601 return this;
600 } 602 }
601 603
602 long mockCertVerifier() { 604 long mockCertVerifier() {
603 return mMockCertVerifier; 605 return mMockCertVerifier;
604 } 606 }
605 607
606 /** 608 /**
609 * Enables the network quality estimator, which collects and reports
610 * measurements of round trip time (RTT) and downstream throughput at
611 * various layers of the network stack. After enabling the estimator,
612 * listeners of RTT and throughput can be added with
613 * {@link #addRttListener} and {@link #addThroughputListener} and
614 * removed with {@link #removeRttListener} and
615 * {@link #removeThroughputListener}. The estimator uses memory and CPU
616 * only when enabled.
617 * @param value {@code true} to enable network quality estimator,
618 * {@code false} to disable.
619 * @hide as it's a prototype.
620 * @return the builder to facilitate chaining.
621 */
622 public Builder enableNetworkQualityEstimator(boolean value) {
623 mNetworkQualityEstimatorEnabled = value;
624 return this;
625 }
626
627 /**
628 * @return true if the network quality estimator has been enabled for
629 * this builder.
630 * @hide as it's a prototype.
631 */
632 boolean networkQualityEstimatorEnabled() {
633 return mNetworkQualityEstimatorEnabled;
634 }
635
636 /**
607 * Returns {@link Context} for builder. 637 * Returns {@link Context} for builder.
608 * 638 *
609 * @return {@link Context} for builder. 639 * @return {@link Context} for builder.
610 */ 640 */
611 Context getContext() { 641 Context getContext() {
612 return mContext; 642 return mContext;
613 } 643 }
614 644
615 /** 645 /**
616 * Build a {@link CronetEngine} using this builder's configuration. 646 * Build a {@link CronetEngine} using this builder's configuration.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 * useful data as no metrics have yet been collected. 826 * useful data as no metrics have yet been collected.
797 * 827 *
798 * @return differences in metrics collected by Cronet, since the last call 828 * @return differences in metrics collected by Cronet, since the last call
799 * to {@code getGlobalMetricsDeltas()}, serialized as a 829 * to {@code getGlobalMetricsDeltas()}, serialized as a
800 * <a href=https://developers.google.com/protocol-buffers>protobuf 830 * <a href=https://developers.google.com/protocol-buffers>protobuf
801 * </a>. 831 * </a>.
802 */ 832 */
803 public abstract byte[] getGlobalMetricsDeltas(); 833 public abstract byte[] getGlobalMetricsDeltas();
804 834
805 /** 835 /**
836 * Sets the executor which will be used to notify RequestFinished
837 * listeners, and to notify network quality RTT listeners
838 * that do not provide an executor.
839 * TODO(tbansal): http://crbug.com/618034 Remove this API. In short term,
840 * once all Cronet embedders supply a valid executor with
841 * NetworkQualityRTTListener, update the above comment to reflect that
842 * {@link executor} is only used to notify RequestFinishedListeners.
843 * @hide as it's a prototype.
844 */
845 public abstract void setRequestFinishedListenerExecutor(Executor executor);
846
847 /**
806 * Enables the network quality estimator, which collects and reports 848 * Enables the network quality estimator, which collects and reports
807 * measurements of round trip time (RTT) and downstream throughput at 849 * measurements of round trip time (RTT) and downstream throughput at
808 * various layers of the network stack. After enabling the estimator, 850 * various layers of the network stack. After enabling the estimator,
809 * listeners of RTT and throughput can be added with 851 * listeners of RTT and throughput can be added with
810 * {@link #addRttListener} and {@link #addThroughputListener} and 852 * {@link #addRttListener} and {@link #addThroughputListener} and
811 * removed with {@link #removeRttListener} and 853 * removed with {@link #removeRttListener} and
812 * {@link #removeThroughputListener}. The estimator uses memory and CPU 854 * {@link #removeThroughputListener}. The estimator uses memory and CPU
813 * only when enabled. 855 * only when enabled.
814 * @param executor an executor that will be used to notified all 856 * @param executor an executor that will be used to notified all
815 * added RTT and throughput listeners. 857 * added RTT and throughput listeners.
858 * TODO(tbansal): http://crbug.com/618034 Remove this API.
816 * @hide as it's a prototype. 859 * @hide as it's a prototype.
817 */ 860 */
818 public abstract void enableNetworkQualityEstimator(Executor executor); 861 public abstract void enableNetworkQualityEstimator(Executor executor);
819 862
820 /** 863 /**
821 * Enables the network quality estimator for testing. This must be called 864 * Configures the network quality estimator for testing. This must be called
822 * before round trip time and throughput listeners are added. Set both 865 * before round trip time and throughput listeners are added, and after the
823 * boolean parameters to false for default behavior. 866 * network quality estimator has been enabled.
824 * @param useLocalHostRequests include requests to localhost in estimates. 867 * @param useLocalHostRequests include requests to localhost in estimates.
825 * @param useSmallerResponses include small responses in throughput estimate s. 868 * @param useSmallerResponses include small responses in throughput
826 * @param executor an {@link java.util.concurrent.Executor} on which all 869 * estimates.
827 * listeners will be called.
828 * @hide as it's a prototype. 870 * @hide as it's a prototype.
829 */ 871 */
830 abstract void enableNetworkQualityEstimatorForTesting( 872 abstract void configureNetworkQualityEstimatorForTesting(
831 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); 873 boolean useLocalHostRequests, boolean useSmallerResponses);
832 874
833 /** 875 /**
834 * Registers a listener that gets called whenever the network quality 876 * Registers a listener that gets called whenever the network quality
835 * estimator witnesses a sample round trip time. This must be called 877 * estimator witnesses a sample round trip time. This must be called
836 * after {@link #enableNetworkQualityEstimator}, and with throw an 878 * after {@link #enableNetworkQualityEstimator}, and with throw an
837 * exception otherwise. Round trip times may be recorded at various layers 879 * exception otherwise. Round trip times may be recorded at various layers
838 * of the network stack, including TCP, QUIC, and at the URL request layer. 880 * of the network stack, including TCP, QUIC, and at the URL request layer.
839 * The listener is called on the {@link java.util.concurrent.Executor} that 881 * The listener is called on the {@link java.util.concurrent.Executor} that
840 * is passed to {@link #enableNetworkQualityEstimator}. 882 * is passed to {@link #enableNetworkQualityEstimator}.
841 * @param listener the listener of round trip times. 883 * @param listener the listener of round trip times.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 * Registers a listener that gets called after the end of each request with the request info. 1002 * Registers a listener that gets called after the end of each request with the request info.
961 * 1003 *
962 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an 1004 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an
963 * exception otherwise. 1005 * exception otherwise.
964 * 1006 *
965 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at 1007 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at
966 * is passed to {@link #enableNetworkQualityEstimator}. 1008 * is passed to {@link #enableNetworkQualityEstimator}.
967 * 1009 *
968 * @param listener the listener for finished requests. 1010 * @param listener the listener for finished requests.
969 * 1011 *
1012 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1013 * using a request finished listener that provides its own executor.
970 * @hide as it's a prototype. 1014 * @hide as it's a prototype.
971 */ 1015 */
972 public abstract void addRequestFinishedListener(RequestFinishedListener list ener); 1016 public abstract void addRequestFinishedListener(RequestFinishedListener list ener);
973 1017
974 /** 1018 /**
975 * Removes a finished request listener. 1019 * Removes a finished request listener.
976 * 1020 *
977 * @param listener the listener to remove. 1021 * @param listener the listener to remove.
978 * 1022 *
1023 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1024 * using a request finished listener that provides its own executor.
979 * @hide it's a prototype. 1025 * @hide it's a prototype.
980 */ 1026 */
981 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener); 1027 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener);
982 1028
983 /** 1029 /**
984 * Information about a finished request. Passed to {@link RequestFinishedLis tener}. 1030 * Information about a finished request. Passed to {@link RequestFinishedLis tener}.
985 * 1031 *
986 * @hide as it's a prototype. 1032 * @hide as it's a prototype.
987 */ 1033 */
988 public static final class UrlRequestInfo { 1034 public static final class UrlRequestInfo {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 */ 1135 */
1090 @Nullable 1136 @Nullable
1091 public Long getReceivedBytesCount() { 1137 public Long getReceivedBytesCount() {
1092 return mReceivedBytesCount; 1138 return mReceivedBytesCount;
1093 } 1139 }
1094 } 1140 }
1095 1141
1096 /** 1142 /**
1097 * Interface to listen for finished requests that were created via this Cron etEngine instance. 1143 * Interface to listen for finished requests that were created via this Cron etEngine instance.
1098 * 1144 *
1145 * TODO(tbansal): http://crbug.com/618034 Remove this API, and replace it w ith a listener
1146 * whose executor is bound to the lifetime of the listener.
1099 * @hide as it's a prototype. 1147 * @hide as it's a prototype.
1100 */ 1148 */
1101 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1149 public interface RequestFinishedListener {
1102 /** 1150 /**
1103 * Invoked with request info. 1151 * Invoked with request info.
1104 * @param requestInfo {@link UrlRequestInfo} for finished request. 1152 * @param requestInfo {@link UrlRequestInfo} for finished request.
1105 */ 1153 */
1106 void onRequestFinished(UrlRequestInfo requestInfo); 1154 void onRequestFinished(UrlRequestInfo requestInfo);
1107 } 1155 }
1108 } 1156 }
OLDNEW
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | components/cronet/android/api/src/org/chromium/net/JavaCronetEngine.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698