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.app.Activity; | 8 import android.app.Activity; |
9 import android.net.Uri; | 9 import android.net.Uri; |
10 import android.os.AsyncTask; | 10 import android.os.AsyncTask; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 break; | 179 break; |
180 default: | 180 default: |
181 throw new IllegalArgumentException("Unknown protocol: " + pr
otocol); | 181 throw new IllegalArgumentException("Unknown protocol: " + pr
otocol); |
182 } | 182 } |
183 try { | 183 try { |
184 mUrl = new URL(scheme, host, port, resource); | 184 mUrl = new URL(scheme, host, port, resource); |
185 } catch (MalformedURLException e) { | 185 } catch (MalformedURLException e) { |
186 throw new IllegalArgumentException( | 186 throw new IllegalArgumentException( |
187 "Bad URL: " + host + ":" + port + "/" + resource); | 187 "Bad URL: " + host + ":" + port + "/" + resource); |
188 } | 188 } |
189 final CronetEngine.Builder cronetEngineBuilder = | 189 final ExperimentalCronetEngine.Builder cronetEngineBuilder = |
190 new CronetEngine.Builder(CronetPerfTestActivity.this); | 190 new ExperimentalCronetEngine.Builder(CronetPerfTestActivity.
this); |
191 cronetEngineBuilder.setLibraryName("cronet_tests"); | 191 CronetTestUtil.setLibraryName(cronetEngineBuilder, "cronet_tests"); |
192 if (mProtocol == Protocol.QUIC) { | 192 if (mProtocol == Protocol.QUIC) { |
193 cronetEngineBuilder.enableQuic(true); | 193 cronetEngineBuilder.enableQuic(true); |
194 cronetEngineBuilder.addQuicHint(host, port, port); | 194 cronetEngineBuilder.addQuicHint(host, port, port); |
195 cronetEngineBuilder.setMockCertVerifierForTesting( | 195 CronetTestUtil.setMockCertVerifierForTesting(cronetEngineBuilder
, |
196 MockCertVerifier.createMockCertVerifier( | 196 MockCertVerifier.createMockCertVerifier( |
197 new String[] {getConfigString("QUIC_CERT_FILE")}
, true)); | 197 new String[] {getConfigString("QUIC_CERT_FILE")}
, true)); |
198 } | 198 } |
199 | 199 |
200 try { | 200 try { |
201 JSONObject quicParams = new JSONObject().put("host_whitelist", h
ost); | 201 JSONObject quicParams = new JSONObject().put("host_whitelist", h
ost); |
202 JSONObject hostResolverParams = | 202 JSONObject hostResolverParams = |
203 CronetTestUtil.generateHostResolverRules(getConfigString
("HOST_IP")); | 203 CronetTestUtil.generateHostResolverRules(getConfigString
("HOST_IP")); |
204 JSONObject experimentalOptions = | 204 JSONObject experimentalOptions = |
205 new JSONObject() | 205 new JSONObject() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (getConfigBoolean("CAPTURE_NETLOG")) { | 256 if (getConfigBoolean("CAPTURE_NETLOG")) { |
257 mCronetEngine.stopNetLog(); | 257 mCronetEngine.stopNetLog(); |
258 } | 258 } |
259 if (getConfigBoolean("CAPTURE_TRACE") || getConfigBoolean("CAPTURE_S
AMPLED_TRACE")) { | 259 if (getConfigBoolean("CAPTURE_TRACE") || getConfigBoolean("CAPTURE_S
AMPLED_TRACE")) { |
260 Debug.stopMethodTracing(); | 260 Debug.stopMethodTracing(); |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 /** | 264 /** |
265 * Transfer {@code mLength} bytes through HttpURLConnection in {@code mD
irection} direction. | 265 * Transfer {@code mLength} bytes through HttpURLConnection in {@code mD
irection} direction. |
266 * @param connection The HttpURLConnection to use for transfer. | 266 * @param urlConnection The HttpURLConnection to use for transfer. |
267 * @param buffer A buffer of length |mBufferSize| to use for transfer. | 267 * @param buffer A buffer of length |mBufferSize| to use for transfer. |
268 * @return {@code true} if transfer completed successfully. | 268 * @return {@code true} if transfer completed successfully. |
269 */ | 269 */ |
270 private boolean exerciseHttpURLConnection(URLConnection urlConnection, b
yte[] buffer) | 270 private boolean exerciseHttpURLConnection(URLConnection urlConnection, b
yte[] buffer) |
271 throws IOException { | 271 throws IOException { |
272 final HttpURLConnection connection = (HttpURLConnection) urlConnecti
on; | 272 final HttpURLConnection connection = (HttpURLConnection) urlConnecti
on; |
273 try { | 273 try { |
274 int bytesTransfered = 0; | 274 int bytesTransfered = 0; |
275 if (mDirection == Direction.DOWN) { | 275 if (mDirection == Direction.DOWN) { |
276 final InputStream inputStream = connection.getInputStream(); | 276 final InputStream inputStream = connection.getInputStream(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 }); | 355 }); |
356 } | 356 } |
357 return; | 357 return; |
358 } | 358 } |
359 mRemainingRequests--; | 359 mRemainingRequests--; |
360 final Runnable completionCallback = new Runnable() { | 360 final Runnable completionCallback = new Runnable() { |
361 public void run() { | 361 public void run() { |
362 initiateRequest(buffer); | 362 initiateRequest(buffer); |
363 } | 363 } |
364 }; | 364 }; |
365 final UrlRequest.Builder builder = new UrlRequest.Builder(mUrl.t
oString(), | 365 final UrlRequest.Builder builder = |
366 new Callback(buffer, completionCallback), mWorkQueueExec
utor, | 366 mCronetEngine.newUrlRequestBuilder(mUrl.toString(), |
367 mCronetEngine); | 367 new Callback(buffer, completionCallback), mWorkQ
ueueExecutor); |
368 if (mDirection == Direction.UP) { | 368 if (mDirection == Direction.UP) { |
369 builder.setUploadDataProvider(new Uploader(buffer), mWorkQue
ueExecutor); | 369 builder.setUploadDataProvider(new Uploader(buffer), mWorkQue
ueExecutor); |
370 builder.addHeader("Content-Type", "application/octet-stream"
); | 370 builder.addHeader("Content-Type", "application/octet-stream"
); |
371 } | 371 } |
372 builder.build().start(); | 372 builder.build().start(); |
373 } | 373 } |
374 | 374 |
375 private class Uploader extends UploadDataProvider { | 375 private class Uploader extends UploadDataProvider { |
376 private final ByteBuffer mBuffer; | 376 private final ByteBuffer mBuffer; |
377 private int mRemainingBytes; | 377 private int mRemainingBytes; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 | 613 |
614 @Override | 614 @Override |
615 public void onCreate(Bundle savedInstanceState) { | 615 public void onCreate(Bundle savedInstanceState) { |
616 super.onCreate(savedInstanceState); | 616 super.onCreate(savedInstanceState); |
617 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, t
his); | 617 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, t
his); |
618 mConfig = getIntent().getData(); | 618 mConfig = getIntent().getData(); |
619 // Execute benchmarks on another thread to avoid networking on main thre
ad. | 619 // Execute benchmarks on another thread to avoid networking on main thre
ad. |
620 new BenchmarkTask().execute(); | 620 new BenchmarkTask().execute(); |
621 } | 621 } |
622 } | 622 } |
OLD | NEW |