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

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: mef comments Created 4 years, 6 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 * useful data as no metrics have yet been collected. 816 * useful data as no metrics have yet been collected.
787 * 817 *
788 * @return differences in metrics collected by Cronet, since the last call 818 * @return differences in metrics collected by Cronet, since the last call
789 * to {@code getGlobalMetricsDeltas()}, serialized as a 819 * to {@code getGlobalMetricsDeltas()}, serialized as a
790 * <a href=https://developers.google.com/protocol-buffers>protobuf 820 * <a href=https://developers.google.com/protocol-buffers>protobuf
791 * </a>. 821 * </a>.
792 */ 822 */
793 public abstract byte[] getGlobalMetricsDeltas(); 823 public abstract byte[] getGlobalMetricsDeltas();
794 824
795 /** 825 /**
826 * Sets the executor which will be used to notify RequestFinished
827 * listeners, and to notify network quality RTT listeners
828 * that do not provide an executor.
829 * TODO(tbansal): http://crbug.com/618034 Remove this API. In short term,
830 * once all Cronet embedders supply a valid executor with
831 * NetworkQualityRTTListener, update the above comment to reflect that
832 * {@link executor} is only used to notify RequestFinishedListeners.
833 * @hide as it's a prototype.
834 */
835 public abstract void setRequestFinishedListenerExecutor(Executor executor);
836
837 /**
796 * Enables the network quality estimator, which collects and reports 838 * Enables the network quality estimator, which collects and reports
797 * measurements of round trip time (RTT) and downstream throughput at 839 * measurements of round trip time (RTT) and downstream throughput at
798 * various layers of the network stack. After enabling the estimator, 840 * various layers of the network stack. After enabling the estimator,
799 * listeners of RTT and throughput can be added with 841 * listeners of RTT and throughput can be added with
800 * {@link #addRttListener} and {@link #addThroughputListener} and 842 * {@link #addRttListener} and {@link #addThroughputListener} and
801 * removed with {@link #removeRttListener} and 843 * removed with {@link #removeRttListener} and
802 * {@link #removeThroughputListener}. The estimator uses memory and CPU 844 * {@link #removeThroughputListener}. The estimator uses memory and CPU
803 * only when enabled. 845 * only when enabled.
804 * @param executor an executor that will be used to notified all 846 * @param executor an executor that will be used to notified all
805 * added RTT and throughput listeners. 847 * added RTT and throughput listeners.
848 * TODO(tbansal): http://crbug.com/618034 Remove this API.
806 * @hide as it's a prototype. 849 * @hide as it's a prototype.
807 */ 850 */
808 public abstract void enableNetworkQualityEstimator(Executor executor); 851 public abstract void enableNetworkQualityEstimator(Executor executor);
809 852
810 /** 853 /**
811 * Enables the network quality estimator for testing. This must be called 854 * Configures the network quality estimator for testing. This must be called
812 * before round trip time and throughput listeners are added. Set both 855 * before round trip time and throughput listeners are added, and after the
813 * boolean parameters to false for default behavior. 856 * network quality estimator has been enabled.
814 * @param useLocalHostRequests include requests to localhost in estimates. 857 * @param useLocalHostRequests include requests to localhost in estimates.
815 * @param useSmallerResponses include small responses in throughput estimate s. 858 * @param useSmallerResponses include small responses in throughput
816 * @param executor an {@link java.util.concurrent.Executor} on which all 859 * estimates.
817 * listeners will be called.
818 * @hide as it's a prototype. 860 * @hide as it's a prototype.
819 */ 861 */
820 abstract void enableNetworkQualityEstimatorForTesting( 862 abstract void configureNetworkQualityEstimatorForTesting(
821 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); 863 boolean useLocalHostRequests, boolean useSmallerResponses);
822 864
823 /** 865 /**
824 * Registers a listener that gets called whenever the network quality 866 * Registers a listener that gets called whenever the network quality
825 * estimator witnesses a sample round trip time. This must be called 867 * estimator witnesses a sample round trip time. This must be called
826 * after {@link #enableNetworkQualityEstimator}, and with throw an 868 * after {@link #enableNetworkQualityEstimator}, and with throw an
827 * exception otherwise. Round trip times may be recorded at various layers 869 * exception otherwise. Round trip times may be recorded at various layers
828 * of the network stack, including TCP, QUIC, and at the URL request layer. 870 * of the network stack, including TCP, QUIC, and at the URL request layer.
829 * The listener is called on the {@link java.util.concurrent.Executor} that 871 * The listener is called on the {@link java.util.concurrent.Executor} that
830 * is passed to {@link #enableNetworkQualityEstimator}. 872 * is passed to {@link #enableNetworkQualityEstimator}.
831 * @param listener the listener of round trip times. 873 * @param listener the listener of round trip times.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 * Registers a listener that gets called after the end of each request with the request info. 1016 * Registers a listener that gets called after the end of each request with the request info.
975 * 1017 *
976 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an 1018 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an
977 * exception otherwise. 1019 * exception otherwise.
978 * 1020 *
979 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at 1021 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at
980 * is passed to {@link #enableNetworkQualityEstimator}. 1022 * is passed to {@link #enableNetworkQualityEstimator}.
981 * 1023 *
982 * @param listener the listener for finished requests. 1024 * @param listener the listener for finished requests.
983 * 1025 *
1026 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1027 * using a request finished listener that provides its own executor.
984 * @hide as it's a prototype. 1028 * @hide as it's a prototype.
985 */ 1029 */
986 public abstract void addRequestFinishedListener(RequestFinishedListener list ener); 1030 public abstract void addRequestFinishedListener(RequestFinishedListener list ener);
987 1031
988 /** 1032 /**
989 * Removes a finished request listener. 1033 * Removes a finished request listener.
990 * 1034 *
991 * @param listener the listener to remove. 1035 * @param listener the listener to remove.
992 * 1036 *
1037 * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedde rs have switched to
1038 * using a request finished listener that provides its own executor.
993 * @hide it's a prototype. 1039 * @hide it's a prototype.
994 */ 1040 */
995 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener); 1041 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener);
996 1042
997 /** 1043 /**
998 * Information about a finished request. Passed to {@link RequestFinishedLis tener}. 1044 * Information about a finished request. Passed to {@link RequestFinishedLis tener}.
999 * 1045 *
1000 * @hide as it's a prototype. 1046 * @hide as it's a prototype.
1001 */ 1047 */
1002 public static final class UrlRequestInfo { 1048 public static final class UrlRequestInfo {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 */ 1149 */
1104 @Nullable 1150 @Nullable
1105 public Long getReceivedBytesCount() { 1151 public Long getReceivedBytesCount() {
1106 return mReceivedBytesCount; 1152 return mReceivedBytesCount;
1107 } 1153 }
1108 } 1154 }
1109 1155
1110 /** 1156 /**
1111 * Interface to listen for finished requests that were created via this Cron etEngine instance. 1157 * Interface to listen for finished requests that were created via this Cron etEngine instance.
1112 * 1158 *
1159 * TODO(tbansal): http://crbug.com/618034 Remove this API, and replace it w ith a listener
1160 * whose executor is bound to the lifetime of the listener.
1113 * @hide as it's a prototype. 1161 * @hide as it's a prototype.
1114 */ 1162 */
1115 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1163 public interface RequestFinishedListener {
1116 /** 1164 /**
1117 * Invoked with request info. 1165 * Invoked with request info.
1118 * @param requestInfo {@link UrlRequestInfo} for finished request. 1166 * @param requestInfo {@link UrlRequestInfo} for finished request.
1119 */ 1167 */
1120 void onRequestFinished(UrlRequestInfo requestInfo); 1168 void onRequestFinished(UrlRequestInfo requestInfo);
1121 } 1169 }
1122 } 1170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698