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