Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 11 import android.support.annotation.Nullable; | |
| 12 import android.support.annotation.VisibleForTesting; | 11 import android.support.annotation.VisibleForTesting; |
| 13 import android.util.Log; | 12 import android.util.Log; |
| 14 | 13 |
| 15 import java.io.File; | 14 import java.io.File; |
| 16 import java.io.IOException; | 15 import java.io.IOException; |
| 17 import java.lang.annotation.Retention; | 16 import java.lang.annotation.Retention; |
| 18 import java.lang.annotation.RetentionPolicy; | 17 import java.lang.annotation.RetentionPolicy; |
| 19 import java.lang.reflect.Constructor; | 18 import java.lang.reflect.Constructor; |
| 20 import java.net.IDN; | 19 import java.net.IDN; |
| 21 import java.net.Proxy; | 20 import java.net.Proxy; |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 * be called on {@code executor}'s thread. {@code executor} must not run | 830 * be called on {@code executor}'s thread. {@code executor} must not run |
| 832 * tasks on the current thread to prevent blocking networking operations | 831 * tasks on the current thread to prevent blocking networking operations |
| 833 * and causing exceptions during shutdown. | 832 * and causing exceptions during shutdown. |
| 834 * | 833 * |
| 835 * @param url {@link URL} for the request. | 834 * @param url {@link URL} for the request. |
| 836 * @param callback callback object that gets invoked on different events. | 835 * @param callback callback object that gets invoked on different events. |
| 837 * @param executor {@link Executor} on which all callbacks will be invoked. | 836 * @param executor {@link Executor} on which all callbacks will be invoked. |
| 838 * @param priority priority of the request which should be one of the | 837 * @param priority priority of the request which should be one of the |
| 839 * {@link UrlRequest.Builder#REQUEST_PRIORITY_IDLE REQUEST_PRIORITY_ *} | 838 * {@link UrlRequest.Builder#REQUEST_PRIORITY_IDLE REQUEST_PRIORITY_ *} |
| 840 * values. | 839 * values. |
| 841 * @param requestAnnotations Objects to pass on to {@link RequestFinishedLis tener}. | 840 * @param requestAnnotations Objects to pass on to {@link RequestFinishedInf o#Listener}. |
|
xunjieli
2016/08/01 22:14:11
A period should be used instead of a hashtag in fr
mgersh
2016/08/01 22:33:45
Done.
| |
| 842 * @param disableCache disables cache for the request. | 841 * @param disableCache disables cache for the request. |
| 843 * If context is not set up to use cache this param has no effect. | 842 * If context is not set up to use cache this param has no effect. |
| 844 * @param disableConnectionMigration disables connection migration for this | 843 * @param disableConnectionMigration disables connection migration for this |
| 845 * request if it is enabled for the session. | 844 * request if it is enabled for the session. |
| 846 * @return new request. | 845 * @return new request. |
| 847 * @deprecated Use {@link UrlRequest.Builder#build}. | 846 * @deprecated Use {@link UrlRequest.Builder#build}. |
| 848 * @hide as it references hidden RequestFinishedListener | 847 * @hide as it references hidden RequestFinishedInfo.Listener |
| 849 */ | 848 */ |
| 850 @Deprecated | 849 @Deprecated |
| 851 protected abstract UrlRequest createRequest(String url, UrlRequest.Callback callback, | 850 protected abstract UrlRequest createRequest(String url, UrlRequest.Callback callback, |
| 852 Executor executor, int priority, Collection<Object> requestAnnotatio ns, | 851 Executor executor, int priority, Collection<Object> requestAnnotatio ns, |
| 853 boolean disableCache, boolean disableConnectionMigration); | 852 boolean disableCache, boolean disableConnectionMigration); |
| 854 | 853 |
| 855 /** | 854 /** |
| 856 * Creates a {@link BidirectionalStream} object. {@code callback} methods wi ll | 855 * Creates a {@link BidirectionalStream} object. {@code callback} methods wi ll |
| 857 * be invoked on {@code executor}. {@code executor} must not run | 856 * be invoked on {@code executor}. {@code executor} must not run |
| 858 * tasks on the current thread to prevent blocking networking operations | 857 * tasks on the current thread to prevent blocking networking operations |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an | 1102 * <p>This must be called after {@link #enableNetworkQualityEstimator} and w ill throw an |
| 1104 * exception otherwise. | 1103 * exception otherwise. |
| 1105 * | 1104 * |
| 1106 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at | 1105 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at |
| 1107 * is passed to {@link #enableNetworkQualityEstimator}. | 1106 * is passed to {@link #enableNetworkQualityEstimator}. |
| 1108 * | 1107 * |
| 1109 * @param listener the listener for finished requests. | 1108 * @param listener the listener for finished requests. |
| 1110 * | 1109 * |
| 1111 * @hide as it's a prototype. | 1110 * @hide as it's a prototype. |
| 1112 */ | 1111 */ |
| 1113 public abstract void addRequestFinishedListener(RequestFinishedListener list ener); | 1112 public abstract void addRequestFinishedListener(RequestFinishedInfo.Listener listener); |
| 1114 | 1113 |
| 1115 /** | 1114 /** |
| 1116 * Removes a finished request listener. | 1115 * Removes a finished request listener. |
| 1117 * | 1116 * |
| 1118 * @param listener the listener to remove. | 1117 * @param listener the listener to remove. |
| 1119 * | 1118 * |
| 1120 * @hide it's a prototype. | 1119 * @hide it's a prototype. |
| 1121 */ | 1120 */ |
| 1122 public abstract void removeRequestFinishedListener(RequestFinishedListener l istener); | 1121 public abstract void removeRequestFinishedListener(RequestFinishedInfo.Liste ner listener); |
| 1123 | |
| 1124 /** | |
| 1125 * Information about a finished request. Passed to {@link RequestFinishedLis tener}. | |
| 1126 * | |
| 1127 * @hide as it's a prototype. | |
| 1128 */ | |
| 1129 public static final class UrlRequestInfo { | |
| 1130 private final String mUrl; | |
| 1131 private final Collection<Object> mAnnotations; | |
| 1132 private final UrlRequestMetrics mMetrics; | |
| 1133 @Nullable private final UrlResponseInfo mResponseInfo; | |
| 1134 | |
| 1135 /** | |
| 1136 * @hide only used by internal implementation. | |
| 1137 */ | |
| 1138 public UrlRequestInfo(String url, Collection<Object> annotations, UrlReq uestMetrics metrics, | |
| 1139 @Nullable UrlResponseInfo responseInfo) { | |
| 1140 mUrl = url; | |
| 1141 mAnnotations = annotations; | |
| 1142 mMetrics = metrics; | |
| 1143 mResponseInfo = responseInfo; | |
| 1144 } | |
| 1145 | |
| 1146 /** Returns the request's original URL. */ | |
| 1147 public String getUrl() { | |
| 1148 return mUrl; | |
| 1149 } | |
| 1150 | |
| 1151 /** Returns the objects that the caller has supplied when initiating the request. */ | |
| 1152 public Collection<Object> getAnnotations() { | |
| 1153 return mAnnotations; | |
| 1154 } | |
| 1155 | |
| 1156 // TODO(klm): Collect and return a chain of Metrics objects for redirect responses. | |
| 1157 /** | |
| 1158 * Returns metrics collected for this request. | |
| 1159 * | |
| 1160 * <p>The reported times and bytes account for all redirects, i.e. | |
| 1161 * the TTFB is from the start of the original request to the ultimate re sponse headers, | |
| 1162 * the TTLB is from the start of the original request to the end of the ultimate response, | |
| 1163 * the received byte count is for all redirects and the ultimate respons e combined. | |
| 1164 * These cumulative metric definitions are debatable, but are chosen to make sense | |
| 1165 * for user-facing latency analysis. | |
| 1166 * | |
| 1167 * <p>Must call {@link #enableNetworkQualityEstimator} to enable request metrics collection. | |
| 1168 * @return metrics collected for this request. | |
| 1169 */ | |
| 1170 public UrlRequestMetrics getMetrics() { | |
| 1171 return mMetrics; | |
| 1172 } | |
| 1173 | |
| 1174 /** | |
| 1175 * Returns a {@link UrlResponseInfo} for the request, if its response ha d started. | |
| 1176 * @return {@link UrlResponseInfo} for the request, if its response had started. | |
| 1177 */ | |
| 1178 @Nullable | |
| 1179 public UrlResponseInfo getResponseInfo() { | |
| 1180 return mResponseInfo; | |
| 1181 } | |
| 1182 } | |
| 1183 | |
| 1184 /** | |
| 1185 * Metrics collected for a single request. | |
| 1186 * | |
| 1187 * <p>Must call {@link #enableNetworkQualityEstimator} to enable request met rics collection. | |
| 1188 * | |
| 1189 * @hide as it's a prototype. | |
| 1190 */ | |
| 1191 public static final class UrlRequestMetrics { | |
| 1192 @Nullable private final Long mTtfbMs; | |
| 1193 @Nullable private final Long mTotalTimeMs; | |
| 1194 @Nullable private final Long mSentBytesCount; | |
| 1195 @Nullable private final Long mReceivedBytesCount; | |
| 1196 | |
| 1197 public UrlRequestMetrics(@Nullable Long ttfbMs, @Nullable Long totalTime Ms, | |
| 1198 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount ) { | |
| 1199 mTtfbMs = ttfbMs; | |
| 1200 mTotalTimeMs = totalTimeMs; | |
| 1201 mSentBytesCount = sentBytesCount; | |
| 1202 mReceivedBytesCount = receivedBytesCount; | |
| 1203 } | |
| 1204 | |
| 1205 /** | |
| 1206 * Returns milliseconds between request initiation and first byte of res ponse headers, | |
| 1207 * or null if not collected. | |
| 1208 */ | |
| 1209 @Nullable | |
| 1210 public Long getTtfbMs() { | |
| 1211 return mTtfbMs; | |
| 1212 } | |
| 1213 | |
| 1214 /** | |
| 1215 * Returns milliseconds between request initiation and finish, | |
| 1216 * including a failure or cancellation, or null if not collected. | |
| 1217 */ | |
| 1218 @Nullable | |
| 1219 public Long getTotalTimeMs() { | |
| 1220 return mTotalTimeMs; | |
| 1221 } | |
| 1222 | |
| 1223 /** | |
| 1224 * Returns total bytes sent over the network transport layer, or null if not collected. | |
| 1225 */ | |
| 1226 @Nullable | |
| 1227 public Long getSentBytesCount() { | |
| 1228 return mSentBytesCount; | |
| 1229 } | |
| 1230 | |
| 1231 /** | |
| 1232 * Returns total bytes received over the network transport layer, or nul l if not collected. | |
| 1233 */ | |
| 1234 @Nullable | |
| 1235 public Long getReceivedBytesCount() { | |
| 1236 return mReceivedBytesCount; | |
| 1237 } | |
| 1238 } | |
| 1239 } | 1122 } |
| OLD | NEW |