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

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: 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
123 private Executor mNetworkQualityExecutor;
122 124
123 /** 125 /**
124 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 126 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
125 * @param context Android {@link Context} for engine to use. 127 * @param context Android {@link Context} for engine to use.
126 */ 128 */
127 public Builder(Context context) { 129 public Builder(Context context) {
128 mContext = context; 130 mContext = context;
129 setLibraryName("cronet"); 131 setLibraryName("cronet");
130 enableLegacyMode(false); 132 enableLegacyMode(false);
131 enableQUIC(false); 133 enableQUIC(false);
132 enableHTTP2(true); 134 enableHTTP2(true);
133 enableSDCH(false); 135 enableSDCH(false);
134 enableHttpCache(HTTP_CACHE_DISABLED, 0); 136 enableHttpCache(HTTP_CACHE_DISABLED, 0);
137 enableNetworkQualityEstimator(false, null);
135 } 138 }
136 139
137 /** 140 /**
138 * Constructs a User-Agent string including application name and version , 141 * Constructs a User-Agent string including application name and version ,
139 * system build version, model and id, and Cronet version. 142 * system build version, model and id, and Cronet version.
140 * 143 *
141 * @return User-Agent string. 144 * @return User-Agent string.
142 */ 145 */
143 public String getDefaultUserAgent() { 146 public String getDefaultUserAgent() {
144 return UserAgent.from(mContext); 147 return UserAgent.from(mContext);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 Builder setMockCertVerifierForTesting(long mockCertVerifier) { 597 Builder setMockCertVerifierForTesting(long mockCertVerifier) {
595 mMockCertVerifier = mockCertVerifier; 598 mMockCertVerifier = mockCertVerifier;
596 return this; 599 return this;
597 } 600 }
598 601
599 long mockCertVerifier() { 602 long mockCertVerifier() {
600 return mMockCertVerifier; 603 return mMockCertVerifier;
601 } 604 }
602 605
603 /** 606 /**
607 * Enables the network quality estimator, which collects and reports
608 * measurements of round trip time (RTT) and downstream throughput at
609 * various layers of the network stack. After enabling the estimator,
610 * listeners of RTT and throughput can be added with
611 * {@link #addRttListener} and {@link #addThroughputListener} and
612 * removed with {@link #removeRttListener} and
613 * {@link #removeThroughputListener}. The estimator uses memory and CPU
614 * only when enabled.
615 * @param value {@code true} to enable network quality estimator,
616 * {@code false} to disable.
617 * @param executor an executor that will be used to notified all
bengr 2016/06/07 20:53:16 nit: notified -> notify
tbansal1 2016/06/07 21:37:16 Done.
618 * added RTT and throughput listeners.
619 * @hide as it's a prototype.
620 * @return the builder to facilitate chaining.
621 */
622 public Builder enableNetworkQualityEstimator(boolean value, Executor exe cutor) {
bengr 2016/06/07 20:53:16 Why do consumers need to call this when they don't
tbansal1 2016/06/07 21:37:16 I kept it consistent with other CronetEngine.Build
bengr 2016/06/07 22:55:12 This seems like a really bad way to do things. Ple
tbansal1 2016/06/08 01:10:33 Sure, but I think this is sensible. e.g., in futur
623 mNetworkQualityEstimatorEnabled = value;
624 mNetworkQualityExecutor = executor;
625 if (mNetworkQualityEstimatorEnabled && mNetworkQualityExecutor == nu ll) {
bengr 2016/06/07 20:53:16 With the new prototype, the first condition here s
tbansal1 2016/06/07 21:37:16 I did not switch to the new prototype, so this is
626 throw new IllegalStateException("Network quality executor must n ot be NULL");
627 }
628 return this;
629 }
630
631 /**
632 * Returns if network quality estimator has been enabled for this builde r.
bengr 2016/06/07 20:53:16 Returns if -> Returns true if the
tbansal1 2016/06/07 21:37:16 Done.
633 * @hide as it's a prototype.
634 */
635 boolean networkQualityEstimatorEnabled() {
636 return mNetworkQualityEstimatorEnabled;
637 }
638
639 /**
640 * Returns the executor for the network quality estimator for this build er.
641 * @hide as it's a prototype.
642 */
643 Executor networkQualityEstimatorExecutor() {
644 return mNetworkQualityExecutor;
645 }
646
647 /**
604 * Returns {@link Context} for builder. 648 * Returns {@link Context} for builder.
605 * 649 *
606 * @return {@link Context} for builder. 650 * @return {@link Context} for builder.
607 */ 651 */
608 Context getContext() { 652 Context getContext() {
609 return mContext; 653 return mContext;
610 } 654 }
611 655
612 /** 656 /**
613 * Build a {@link CronetEngine} using this builder's configuration. 657 * Build a {@link CronetEngine} using this builder's configuration.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 * @return differences in metrics collected by Cronet, since the last call 829 * @return differences in metrics collected by Cronet, since the last call
786 * to {@code getGlobalMetricsDeltas()}, serialized as a 830 * to {@code getGlobalMetricsDeltas()}, serialized as a
787 * <a href=https://developers.google.com/protocol-buffers>protobuf 831 * <a href=https://developers.google.com/protocol-buffers>protobuf
788 * </a>. 832 * </a>.
789 */ 833 */
790 public abstract byte[] getGlobalMetricsDeltas(); 834 public abstract byte[] getGlobalMetricsDeltas();
791 835
792 /** 836 /**
793 * Enables the network quality estimator, which collects and reports 837 * Enables the network quality estimator, which collects and reports
794 * measurements of round trip time (RTT) and downstream throughput at 838 * measurements of round trip time (RTT) and downstream throughput at
795 * various layers of the network stack. After enabling the estimator, 839 * various layers of the network stack. This API has been deprecated in
796 * listeners of RTT and throughput can be added with 840 * favor of CronetEngineBuilder.enableNetworkQualityEstimator.
841 * After enabling the estimator, listeners of RTT and throughput can be
842 * added with
797 * {@link #addRttListener} and {@link #addThroughputListener} and 843 * {@link #addRttListener} and {@link #addThroughputListener} and
798 * removed with {@link #removeRttListener} and 844 * removed with {@link #removeRttListener} and
799 * {@link #removeThroughputListener}. The estimator uses memory and CPU 845 * {@link #removeThroughputListener}. The estimator uses memory and CPU
800 * only when enabled. 846 * only when enabled.
801 * @param executor an executor that will be used to notified all 847 * @param executor an executor that will be used to notified all
802 * added RTT and throughput listeners. 848 * added RTT and throughput listeners.
803 * @hide as it's a prototype. 849 * @hide as it's a prototype.
850 * @hide TODO(tbansal): http://crbug.com/618034 Remove this API once all
851 * consumers have switched to using
852 * CronetEngineBuilder.enableNetworkQualityEstimator.
804 */ 853 */
805 public abstract void enableNetworkQualityEstimator(Executor executor); 854 public abstract void enableNetworkQualityEstimator(Executor executor);
806 855
807 /** 856 /**
808 * Enables the network quality estimator for testing. This must be called 857 * Configures the network quality estimator for testing. This must be called
809 * before round trip time and throughput listeners are added. Set both 858 * before round trip time and throughput listeners are added, and after the
810 * boolean parameters to false for default behavior. 859 * network quality estimator has been enabled.
811 * @param useLocalHostRequests include requests to localhost in estimates. 860 * @param useLocalHostRequests include requests to localhost in estimates.
812 * @param useSmallerResponses include small responses in throughput estimate s. 861 * @param useSmallerResponses include small responses in throughput
813 * @param executor an {@link java.util.concurrent.Executor} on which all 862 * estimates.
814 * listeners will be called.
815 * @hide as it's a prototype. 863 * @hide as it's a prototype.
816 */ 864 */
817 abstract void enableNetworkQualityEstimatorForTesting( 865 abstract void configureNetworkQualityEstimatorForTesting(
818 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); 866 boolean useLocalHostRequests, boolean useSmallerResponses);
819 867
820 /** 868 /**
821 * Registers a listener that gets called whenever the network quality 869 * Registers a listener that gets called whenever the network quality
822 * estimator witnesses a sample round trip time. This must be called 870 * estimator witnesses a sample round trip time. This must be called
823 * after {@link #enableNetworkQualityEstimator}, and with throw an 871 * after {@link #enableNetworkQualityEstimator}, and with throw an
824 * exception otherwise. Round trip times may be recorded at various layers 872 * 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. 873 * 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 874 * The listener is called on the {@link java.util.concurrent.Executor} that
827 * is passed to {@link #enableNetworkQualityEstimator}. 875 * is passed to {@link #enableNetworkQualityEstimator}.
828 * @param listener the listener of round trip times. 876 * @param listener the listener of round trip times.
829 * @hide as it's a prototype. 877 * @hide as it's a prototype.
830 */ 878 */
831 public abstract void addRttListener(NetworkQualityRttListener listener); 879 public abstract void addRttListener(NetworkQualityRttListener listener);
832 880
833 /** 881 /**
834 * Removes a listener of round trip times if previously registered with 882 * Removes a listener of round trip times if previously registered with
835 * {@link #addRttListener}. This should be called after a 883 * {@link #addRttListener}. This should be called after a
836 * {@link NetworkQualityRttListener} is added in order to stop receiving 884 * {@link NetworkQualityRttListener} is added in order to stop receiving
837 * observations. 885 * observations.
838 * @param listener the listener of round trip times. 886 * @param listener the listener of round trip times.
839 * @hide as it's a prototype. 887 * @hide as it's a prototype.
840 */ 888 */
841 public abstract void removeRttListener(NetworkQualityRttListener listener); 889 public abstract void removeRttListener(NetworkQualityRttListener listener);
842 890
843 /** 891 /**
844 * Registers a listener that gets called whenever the network quality 892 * Registers a listener that gets called whenever the network quality
845 * estimator witnesses a sample throughput measurement. This must be called 893 * estimator witnesses a sample throughput measurement. This must be called
846 * after {@link #enableNetworkQualityEstimator}. Throughput observations 894 * after network quality estimator has been enabled. Throughput observations
bengr 2016/06/07 20:53:16 network -> the network
tbansal1 2016/06/07 21:37:16 Done.
847 * are computed by measuring bytes read over the active network interface 895 * are computed by measuring bytes read over the active network interface
848 * at times when at least one URL response is being received. The listener 896 * at times when at least one URL response is being received. The listener
849 * is called on the {@link java.util.concurrent.Executor} that is passed to 897 * is called on the {@link java.util.concurrent.Executor} that is passed to
850 * {@link #enableNetworkQualityEstimator}. 898 * {@link #enableNetworkQualityEstimator}.
851 * @param listener the listener of throughput. 899 * @param listener the listener of throughput.
852 * @hide as it's a prototype. 900 * @hide as it's a prototype.
853 */ 901 */
854 public abstract void addThroughputListener(NetworkQualityThroughputListener listener); 902 public abstract void addThroughputListener(NetworkQualityThroughputListener listener);
855 903
856 /** 904 /**
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 // Leave as null. 1011 // Leave as null.
964 } catch (Exception e) { 1012 } catch (Exception e) {
965 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); 1013 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e);
966 } 1014 }
967 return cronetEngine; 1015 return cronetEngine;
968 } 1016 }
969 1017
970 /** 1018 /**
971 * Registers a listener that gets called after the end of each request with the request info. 1019 * Registers a listener that gets called after the end of each request with the request info.
972 * 1020 *
973 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an 1021 * <p>This must be called after network quality estimator has been enabled.
bengr 2016/06/07 20:53:16 after -> after the
tbansal1 2016/06/07 21:37:16 Done.
974 * exception otherwise.
975 * 1022 *
976 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at 1023 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at
977 * is passed to {@link #enableNetworkQualityEstimator}. 1024 * is passed to {@link #enableNetworkQualityEstimator}.
978 * 1025 *
979 * @param listener the listener for finished requests. 1026 * @param listener the listener for finished requests.
980 * 1027 *
981 * @hide as it's a prototype. 1028 * @hide as it's a prototype.
982 */ 1029 */
983 public abstract void addRequestFinishedListener(RequestFinishedListener list ener); 1030 public abstract void addRequestFinishedListener(RequestFinishedListener list ener);
bengr 2016/06/07 20:53:16 This should throw an exception if nqe is not enabl
tbansal1 2016/06/07 21:37:16 It does. Now, added the comment to make it clearer
984 1031
985 /** 1032 /**
986 * Removes a finished request listener. 1033 * Removes a finished request listener.
987 * 1034 *
988 * @param listener the listener to remove. 1035 * @param listener the listener to remove.
989 * 1036 *
990 * @hide it's a prototype. 1037 * @hide it's a prototype.
991 */ 1038 */
992 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener); 1039 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener);
993 1040
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 * @hide as it's a prototype. 1157 * @hide as it's a prototype.
1111 */ 1158 */
1112 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1159 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class.
1113 /** 1160 /**
1114 * Invoked with request info. 1161 * Invoked with request info.
1115 * @param requestInfo {@link UrlRequestInfo} for finished request. 1162 * @param requestInfo {@link UrlRequestInfo} for finished request.
1116 */ 1163 */
1117 void onRequestFinished(UrlRequestInfo requestInfo); 1164 void onRequestFinished(UrlRequestInfo requestInfo);
1118 } 1165 }
1119 } 1166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698