Chromium Code Reviews

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: Rebased, Each Listener provides an executor Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 101 matching lines...)
112 private boolean mSdchEnabled; 112 private boolean mSdchEnabled;
113 private String mDataReductionProxyKey; 113 private String mDataReductionProxyKey;
114 private String mDataReductionProxyPrimaryProxy; 114 private String mDataReductionProxyPrimaryProxy;
115 private String mDataReductionProxyFallbackProxy; 115 private String mDataReductionProxyFallbackProxy;
116 private String mDataReductionProxySecureProxyCheckUrl; 116 private String mDataReductionProxySecureProxyCheckUrl;
117 private boolean mDisableCache; 117 private boolean mDisableCache;
118 private int mHttpCacheMode; 118 private int mHttpCacheMode;
119 private long mHttpCacheMaxSize; 119 private long mHttpCacheMaxSize;
120 private String mExperimentalOptions; 120 private String mExperimentalOptions;
121 private long mMockCertVerifier; 121 private long mMockCertVerifier;
122 private boolean mNetworkQualityEstimatorEnabled;
122 123
123 /** 124 /**
124 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 125 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
125 * @param context Android {@link Context} for engine to use. 126 * @param context Android {@link Context} for engine to use.
126 */ 127 */
127 public Builder(Context context) { 128 public Builder(Context context) {
128 mContext = context; 129 mContext = context;
129 setLibraryName("cronet"); 130 setLibraryName("cronet");
130 enableLegacyMode(false); 131 enableLegacyMode(false);
131 enableQUIC(false); 132 enableQUIC(false);
132 enableHTTP2(true); 133 enableHTTP2(true);
133 enableSDCH(false); 134 enableSDCH(false);
134 enableHttpCache(HTTP_CACHE_DISABLED, 0); 135 enableHttpCache(HTTP_CACHE_DISABLED, 0);
136 enableNetworkQualityEstimator(false);
135 } 137 }
136 138
137 /** 139 /**
138 * Constructs a User-Agent string including application name and version , 140 * Constructs a User-Agent string including application name and version ,
139 * system build version, model and id, and Cronet version. 141 * system build version, model and id, and Cronet version.
140 * 142 *
141 * @return User-Agent string. 143 * @return User-Agent string.
142 */ 144 */
143 public String getDefaultUserAgent() { 145 public String getDefaultUserAgent() {
144 return UserAgent.from(mContext); 146 return UserAgent.from(mContext);
(...skipping 449 matching lines...)
594 Builder setMockCertVerifierForTesting(long mockCertVerifier) { 596 Builder setMockCertVerifierForTesting(long mockCertVerifier) {
595 mMockCertVerifier = mockCertVerifier; 597 mMockCertVerifier = mockCertVerifier;
596 return this; 598 return this;
597 } 599 }
598 600
599 long mockCertVerifier() { 601 long mockCertVerifier() {
600 return mMockCertVerifier; 602 return mMockCertVerifier;
601 } 603 }
602 604
603 /** 605 /**
606 * Enables the network quality estimator, which collects and reports
607 * measurements of round trip time (RTT) and downstream throughput at
608 * various layers of the network stack. After enabling the estimator,
609 * listeners of RTT and throughput can be added with
610 * {@link #addRttListener} and {@link #addThroughputListener} and
611 * removed with {@link #removeRttListener} and
612 * {@link #removeThroughputListener}. The estimator uses memory and CPU
613 * only when enabled.
614 * @param value {@code true} to enable network quality estimator,
615 * {@code false} to disable.
616 * @hide as it's a prototype.
617 * @return the builder to facilitate chaining.
618 */
619 public Builder enableNetworkQualityEstimator(boolean value) {
620 if (!value) {
mef 2016/06/20 16:50:27 I think for Builder it is ok to be able to turn it
tbansal1 2016/06/20 20:06:57 Done.
621 return this;
622 }
623
624 if (mNetworkQualityEstimatorEnabled) {
625 throw new IllegalStateException("Network quality estimator is al ready initialized");
626 }
627 mNetworkQualityEstimatorEnabled = true;
628 return this;
629 }
630
631 /**
632 * @return true if the network quality estimator has been enabled for
633 * this builder.
634 * @hide as it's a prototype.
635 */
636 boolean networkQualityEstimatorEnabled() {
637 return mNetworkQualityEstimatorEnabled;
638 }
639
640 /**
604 * Returns {@link Context} for builder. 641 * Returns {@link Context} for builder.
605 * 642 *
606 * @return {@link Context} for builder. 643 * @return {@link Context} for builder.
607 */ 644 */
608 Context getContext() { 645 Context getContext() {
609 return mContext; 646 return mContext;
610 } 647 }
611 648
612 /** 649 /**
613 * Build a {@link CronetEngine} using this builder's configuration. 650 * Build a {@link CronetEngine} using this builder's configuration.
(...skipping 169 matching lines...)
783 * useful data as no metrics have yet been collected. 820 * useful data as no metrics have yet been collected.
784 * 821 *
785 * @return differences in metrics collected by Cronet, since the last call 822 * @return differences in metrics collected by Cronet, since the last call
786 * to {@code getGlobalMetricsDeltas()}, serialized as a 823 * to {@code getGlobalMetricsDeltas()}, serialized as a
787 * <a href=https://developers.google.com/protocol-buffers>protobuf 824 * <a href=https://developers.google.com/protocol-buffers>protobuf
788 * </a>. 825 * </a>.
789 */ 826 */
790 public abstract byte[] getGlobalMetricsDeltas(); 827 public abstract byte[] getGlobalMetricsDeltas();
791 828
792 /** 829 /**
830 * Sets the executor which will be used to notify RequestFinished
831 * listeners, and to notify network quality RTT listeners
832 * that do not provide an executor.
833 * TODO(tbansal): http://crbug.com/618034 Remove this API. In short term,
834 * once all Cronet embedders supply a valid executor with
835 * NetworkQualityRTTListener, update the above comment to reflect that
836 * {@link executor} is only used to notify RequestFinishedListeners.
837 * @hide as it's a prototype.
838 */
839 public abstract void setRequestFinishedListenerExecutor(Executor executor);
840
841 /**
793 * Enables the network quality estimator, which collects and reports 842 * Enables the network quality estimator, which collects and reports
794 * measurements of round trip time (RTT) and downstream throughput at 843 * measurements of round trip time (RTT) and downstream throughput at
795 * various layers of the network stack. After enabling the estimator, 844 * various layers of the network stack. After enabling the estimator,
796 * listeners of RTT and throughput can be added with 845 * listeners of RTT and throughput can be added with
797 * {@link #addRttListener} and {@link #addThroughputListener} and 846 * {@link #addRttListener} and {@link #addThroughputListener} and
798 * removed with {@link #removeRttListener} and 847 * removed with {@link #removeRttListener} and
799 * {@link #removeThroughputListener}. The estimator uses memory and CPU 848 * {@link #removeThroughputListener}. The estimator uses memory and CPU
800 * only when enabled. 849 * only when enabled.
801 * @param executor an executor that will be used to notified all 850 * @param executor an executor that will be used to notified all
802 * added RTT and throughput listeners. 851 * added RTT and throughput listeners.
852 * TODO(tbansal): http://crbug.com/618034 Remove this API.
803 * @hide as it's a prototype. 853 * @hide as it's a prototype.
804 */ 854 */
805 public abstract void enableNetworkQualityEstimator(Executor executor); 855 public abstract void enableNetworkQualityEstimator(Executor executor);
806 856
807 /** 857 /**
808 * Enables the network quality estimator for testing. This must be called 858 * Configures the network quality estimator for testing. This must be called
809 * before round trip time and throughput listeners are added. Set both 859 * before round trip time and throughput listeners are added, and after the
810 * boolean parameters to false for default behavior. 860 * network quality estimator has been enabled.
811 * @param useLocalHostRequests include requests to localhost in estimates. 861 * @param useLocalHostRequests include requests to localhost in estimates.
812 * @param useSmallerResponses include small responses in throughput estimate s. 862 * @param useSmallerResponses include small responses in throughput
813 * @param executor an {@link java.util.concurrent.Executor} on which all 863 * estimates.
814 * listeners will be called.
815 * @hide as it's a prototype. 864 * @hide as it's a prototype.
816 */ 865 */
817 abstract void enableNetworkQualityEstimatorForTesting( 866 abstract void configureNetworkQualityEstimatorForTesting(
818 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); 867 boolean useLocalHostRequests, boolean useSmallerResponses);
819 868
820 /** 869 /**
821 * Registers a listener that gets called whenever the network quality 870 * Registers a listener that gets called whenever the network quality
822 * estimator witnesses a sample round trip time. This must be called 871 * estimator witnesses a sample round trip time. This must be called
823 * after {@link #enableNetworkQualityEstimator}, and with throw an 872 * after {@link #enableNetworkQualityEstimator}, and with throw an
824 * exception otherwise. Round trip times may be recorded at various layers 873 * exception otherwise. Round trip times may be recorded at various layers
825 * of the network stack, including TCP, QUIC, and at the URL request layer. 874 * of the network stack, including TCP, QUIC, and at the URL request layer.
826 * The listener is called on the {@link java.util.concurrent.Executor} that 875 * The listener is called on the {@link java.util.concurrent.Executor} that
827 * is passed to {@link #enableNetworkQualityEstimator}. 876 * is passed to {@link #enableNetworkQualityEstimator}.
828 * @param listener the listener of round trip times. 877 * @param listener the listener of round trip times.
(...skipping 142 matching lines...)
971 * Registers a listener that gets called after the end of each request with the request info. 1020 * Registers a listener that gets called after the end of each request with the request info.
972 * 1021 *
973 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an 1022 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an
974 * exception otherwise. 1023 * exception otherwise.
975 * 1024 *
976 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at 1025 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at
977 * is passed to {@link #enableNetworkQualityEstimator}. 1026 * is passed to {@link #enableNetworkQualityEstimator}.
978 * 1027 *
979 * @param listener the listener for finished requests. 1028 * @param listener the listener for finished requests.
980 * 1029 *
1030 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1031 * using a request finished listener that provides its own executor.
981 * @hide as it's a prototype. 1032 * @hide as it's a prototype.
982 */ 1033 */
983 public abstract void addRequestFinishedListener(RequestFinishedListener list ener); 1034 public abstract void addRequestFinishedListener(RequestFinishedListener list ener);
984 1035
985 /** 1036 /**
986 * Removes a finished request listener. 1037 * Removes a finished request listener.
987 * 1038 *
988 * @param listener the listener to remove. 1039 * @param listener the listener to remove.
989 * 1040 *
1041 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1042 * using a request finished listener that provides its own executor.
990 * @hide it's a prototype. 1043 * @hide it's a prototype.
991 */ 1044 */
992 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener); 1045 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener);
993 1046
994 /** 1047 /**
995 * Information about a finished request. Passed to {@link RequestFinishedLis tener}. 1048 * Information about a finished request. Passed to {@link RequestFinishedLis tener}.
996 * 1049 *
997 * @hide as it's a prototype. 1050 * @hide as it's a prototype.
998 */ 1051 */
999 public static final class UrlRequestInfo { 1052 public static final class UrlRequestInfo {
(...skipping 100 matching lines...)
1100 */ 1153 */
1101 @Nullable 1154 @Nullable
1102 public Long getReceivedBytesCount() { 1155 public Long getReceivedBytesCount() {
1103 return mReceivedBytesCount; 1156 return mReceivedBytesCount;
1104 } 1157 }
1105 } 1158 }
1106 1159
1107 /** 1160 /**
1108 * Interface to listen for finished requests that were created via this Cron etEngine instance. 1161 * Interface to listen for finished requests that were created via this Cron etEngine instance.
1109 * 1162 *
1163 * TODO(tbansal): http://crbug.com/618034 Remove this API, and replace it w ith a listener
1164 * whose executor is bound to the lifetime of the listener.
1110 * @hide as it's a prototype. 1165 * @hide as it's a prototype.
1111 */ 1166 */
1112 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1167 public interface RequestFinishedListener {
1113 /** 1168 /**
1114 * Invoked with request info. 1169 * Invoked with request info.
1115 * @param requestInfo {@link UrlRequestInfo} for finished request. 1170 * @param requestInfo {@link UrlRequestInfo} for finished request.
1116 */ 1171 */
1117 void onRequestFinished(UrlRequestInfo requestInfo); 1172 void onRequestFinished(UrlRequestInfo requestInfo);
1118 } 1173 }
1119 } 1174 }
OLDNEW

Powered by Google App Engine