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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Rebased onto Charles change + Paul's Comments Created 4 years, 3 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 package org.chromium.net;
5
6 import android.content.Context;
7
8 import java.io.IOException;
9 import java.net.Proxy;
10 import java.net.URL;
11 import java.net.URLConnection;
12 import java.util.concurrent.Executor;
13
14 /**
15 * {@link CronetEngine} that exposes experimental features. Use {@link Builder} to build an
16 * instance of this class.
pauljensen 2016/09/26 14:51:21 should we mention that every instance of a CronetE
kapishnikov 2016/09/27 18:38:25 In case of ExperimentalCronetEngine, we can change
pauljensen 2016/09/27 19:08:09 I think it couldn't hurt to mention...esp consider
kapishnikov 2016/09/28 00:20:49 Done.
17 * {@hide} since this class exposes experimental features that should be hidden.
18 */
19 public abstract class ExperimentalCronetEngine extends CronetEngine {
20 /**
21 * Builder for building {@link ExperimentalCronetEngine}.
22 * {@hide} since this class exposes experimental features that should be hid den.
23 */
24 public static class Builder extends CronetEngine.Builder {
25 /**
26 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
27 *
28 * @param context Android {@link Context} for engine to use.
29 */
30 public Builder(Context context) {
31 super(context);
32 }
33
34 /**
35 * Enables the network quality estimator, which collects and reports
36 * measurements of round trip time (RTT) and downstream throughput at
37 * various layers of the network stack. After enabling the estimator,
38 * listeners of RTT and throughput can be added with
39 * {@link #addRttListener} and {@link #addThroughputListener} and
40 * removed with {@link #removeRttListener} and
41 * {@link #removeThroughputListener}. The estimator uses memory and CPU
42 * only when enabled.
43 * @param value {@code true} to enable network quality estimator,
44 * {@code false} to disable.
45 * @return the builder to facilitate chaining.
46 */
47 public Builder enableNetworkQualityEstimator(boolean value) {
48 mBuilderDelegate.enableNetworkQualityEstimator(value);
49 return this;
50 }
51
52 /**
53 * Initializes CachingCertVerifier's cache with certVerifierData which h as
54 * the results of certificate verification.
55 * @param certVerifierData a serialized representation of certificate
56 * verification results.
57 * @return the builder to facilitate chaining.
58 */
59 public Builder setCertVerifierData(String certVerifierData) {
60 mBuilderDelegate.setCertVerifierData(certVerifierData);
61 return this;
62 }
63
64 public Builder setDataReductionProxyOptions(
65 String primaryProxy, String fallbackProxy, String secureProxyChe ckUrl) {
66 mBuilderDelegate.setDataReductionProxyOptions(
67 primaryProxy, fallbackProxy, secureProxyCheckUrl);
68 return this;
69 }
70
71 /**
72 * Build an instance of {@link ExperimentalCronetEngine}
73 *
74 * @return the constructed experimental engine.
75 */
76 public ExperimentalCronetEngine build() {
77 return (ExperimentalCronetEngine) mBuilderDelegate.build();
78 }
79 }
80
81 /**
82 * Creates a builder for {@link BidirectionalStream} objects. All callbacks for
83 * generated {@code BidirectionalStream} objects will be invoked on
84 * {@code executor}. {@code executor} must not run tasks on the
85 * current thread, otherwise the networking operations may block and excepti ons
86 * may be thrown at shutdown time.
87 *
88 * @param url the URL for the generated stream.
89 * @param callback the {@link BidirectionalStream.Callback} object that gets invoked upon
90 * different events occurring.
91 * @param executor the {@link Executor} on which {@code callback} methods wi ll be invoked.
92 *
93 * @return the created builder.
94 */
95 public abstract ExperimentalBidirectionalStream.Builder newBidirectionalStre amBuilder(
96 String url, BidirectionalStream.Callback callback, Executor executor );
97
98 /**
99 * Starts NetLog logging to a specified directory with a bounded size. The N etLog will contain
100 * events emitted by all live CronetEngines. The NetLog is useful for debugg ing.
101 * The log can be viewed by stitching the files using net/log/stitch_net_log _files.py and
102 * using a Chrome browser navigated to chrome://net-internals/#import
103 * @param dirPath the directory where the log files will be created. It must already exist.
104 * NetLog files must not already exist in the directory. If activ ely logging,
105 * this method is ignored.
106 * @param logAll {@code true} to include basic events, user cookies,
107 * credentials and all transferred bytes in the log. This option presents a
108 * privacy risk, since it exposes the user's credentials, and sho uld only be
109 * used with the user's consent and in situations where the log w on't be public.
110 * {@code false} to just include basic events.
111 * @param maxSize the maximum total disk space in bytes that should be used by NetLog. Actual
112 * disk space usage may exceed this limit slightly.
113 */
114 public abstract void startNetLogToDisk(String dirPath, boolean logAll, int m axSize);
115
116 /**
117 * Returns the effective connection type computed by the network quality
118 * estimator.
119 */
120 public abstract int getEffectiveConnectionType();
121
122 /**
123 * Configures the network quality estimator for testing. This must be called
124 * before round trip time and throughput listeners are added, and after the
125 * network quality estimator has been enabled.
126 * @param useLocalHostRequests include requests to localhost in estimates.
127 * @param useSmallerResponses include small responses in throughput
128 * estimates.
129 */
130 public abstract void configureNetworkQualityEstimatorForTesting(
131 boolean useLocalHostRequests, boolean useSmallerResponses);
132
133 /**
134 * Registers a listener that gets called whenever the network quality
135 * estimator witnesses a sample round trip time. This must be called
136 * after {@link Builder#enableNetworkQualityEstimator}, and with throw an
137 * exception otherwise. Round trip times may be recorded at various layers
138 * of the network stack, including TCP, QUIC, and at the URL request layer.
139 * The listener is called on the {@link java.util.concurrent.Executor} that
140 * is passed to {@link Builder#enableNetworkQualityEstimator}.
141 * @param listener the listener of round trip times.
142 */
143 public abstract void addRttListener(NetworkQualityRttListener listener);
144
145 /**
146 * Removes a listener of round trip times if previously registered with
147 * {@link #addRttListener}. This should be called after a
148 * {@link NetworkQualityRttListener} is added in order to stop receiving
149 * observations.
150 * @param listener the listener of round trip times.
151 */
152 public abstract void removeRttListener(NetworkQualityRttListener listener);
153
154 /**
155 * Registers a listener that gets called whenever the network quality
156 * estimator witnesses a sample throughput measurement. This must be called
157 * after {@link Builder#enableNetworkQualityEstimator}. Throughput observati ons
158 * are computed by measuring bytes read over the active network interface
159 * at times when at least one URL response is being received. The listener
160 * is called on the {@link java.util.concurrent.Executor} that is passed to
161 * {@link Builder#enableNetworkQualityEstimator}.
162 * @param listener the listener of throughput.
163 */
164 public abstract void addThroughputListener(NetworkQualityThroughputListener listener);
165
166 /**
167 * Removes a listener of throughput. This should be called after a
168 * {@link NetworkQualityThroughputListener} is added with
169 * {@link #addThroughputListener} in order to stop receiving observations.
170 * @param listener the listener of throughput.
171 */
172 public abstract void removeThroughputListener(NetworkQualityThroughputListen er listener);
173
174 /**
175 * Establishes a new connection to the resource specified by the {@link URL} {@code url}
176 * using the given proxy.
177 * <p>
178 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain
179 * limitations, see {@link #createURLStreamHandlerFactory} for details.
180 *
181 * @param url URL of resource to connect to.
182 * @param proxy proxy to use when establishing connection.
183 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine.
184 * @throws IOException if an error occurs while opening the connection.
185 */
186 // TODO(pauljensen): Expose once implemented, http://crbug.com/418111
187 public abstract URLConnection openConnection(URL url, Proxy proxy) throws IO Exception;
188
189 /**
190 * Registers a listener that gets called after the end of each request with the request info.
191 *
192 * <p>This must be called after {@link Builder#enableNetworkQualityEstimator } and will throw an
193 * exception otherwise.
194 *
195 * <p>The listener is called on the {@link java.util.concurrent.Executor} th at
196 * is passed to {@link Builder#enableNetworkQualityEstimator}.
197 *
198 * @param listener the listener for finished requests.
199 */
200
201 public abstract void addRequestFinishedListener(RequestFinishedInfo.Listener listener);
202
203 /**
204 * Removes a finished request listener.
205 *
206 * @param listener the listener to remove.
207 */
208 public abstract void removeRequestFinishedListener(RequestFinishedInfo.Liste ner listener);
209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698