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

Side by Side Diff: components/cronet/android/test/javaperftests/src/org/chromium/net/CronetPerfTestActivity.java

Issue 1383023003: [Cronet] Expose HttpURLConnection API from CronetEngine, not classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@builder2
Patch Set: address nits Created 5 years, 2 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
« no previous file with comments | « components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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;
11 import android.os.Bundle; 11 import android.os.Bundle;
12 import android.os.Debug; 12 import android.os.Debug;
13 13
14 import org.chromium.net.urlconnection.CronetHttpURLStreamHandler;
15 import org.json.JSONException; 14 import org.json.JSONException;
16 import org.json.JSONObject; 15 import org.json.JSONObject;
17 16
18 import java.io.File; 17 import java.io.File;
19 import java.io.FileOutputStream; 18 import java.io.FileOutputStream;
20 import java.io.IOException; 19 import java.io.IOException;
21 import java.io.InputStream; 20 import java.io.InputStream;
22 import java.io.OutputStream; 21 import java.io.OutputStream;
23 import java.net.HttpURLConnection; 22 import java.net.HttpURLConnection;
24 import java.net.MalformedURLException; 23 import java.net.MalformedURLException;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } catch (IOException e) { 284 } catch (IOException e) {
286 System.out.println("System HttpURLConnection failed with " + e); 285 System.out.println("System HttpURLConnection failed with " + e);
287 return false; 286 return false;
288 } 287 }
289 } 288 }
290 } 289 }
291 290
292 // GET or POST to one particular URL using Cronet HttpURLConnection API 291 // GET or POST to one particular URL using Cronet HttpURLConnection API
293 private class CronetHttpURLConnectionFetchTask implements Callable<Boole an> { 292 private class CronetHttpURLConnectionFetchTask implements Callable<Boole an> {
294 private final byte[] mBuffer = new byte[mBufferSize]; 293 private final byte[] mBuffer = new byte[mBufferSize];
295 private final CronetHttpURLStreamHandler mStreamHandler;
296
297 public CronetHttpURLConnectionFetchTask(
298 CronetHttpURLStreamHandler cronetStreamHandler) {
299 mStreamHandler = cronetStreamHandler;
300 }
301 294
302 @Override 295 @Override
303 public Boolean call() { 296 public Boolean call() {
304 try { 297 try {
305 return exerciseHttpURLConnection(mStreamHandler.openConnecti on(mUrl), mBuffer); 298 return exerciseHttpURLConnection(mCronetEngine.openConnectio n(mUrl), mBuffer);
306 } catch (IOException e) { 299 } catch (IOException e) {
307 System.out.println("Cronet HttpURLConnection failed with " + e); 300 System.out.println("Cronet HttpURLConnection failed with " + e);
308 return false; 301 return false;
309 } 302 }
310 } 303 }
311 } 304 }
312 305
313 // GET or POST to one particular URL using Cronet's asynchronous API 306 // GET or POST to one particular URL using Cronet's asynchronous API
314 private class CronetAsyncFetchTask implements Callable<Boolean> { 307 private class CronetAsyncFetchTask implements Callable<Boolean> {
315 // A message-queue for asynchronous tasks to post back to. 308 // A message-queue for asynchronous tasks to post back to.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 final List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean >>(mIterations); 466 final List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean >>(mIterations);
474 startLogging(); 467 startLogging();
475 // Prepare list of tasks to run. 468 // Prepare list of tasks to run.
476 switch (mMode) { 469 switch (mMode) {
477 case SYSTEM_HUC: 470 case SYSTEM_HUC:
478 for (int i = 0; i < mIterations; i++) { 471 for (int i = 0; i < mIterations; i++) {
479 tasks.add(new SystemHttpURLConnectionFetchTask()); 472 tasks.add(new SystemHttpURLConnectionFetchTask());
480 } 473 }
481 break; 474 break;
482 case CRONET_HUC: { 475 case CRONET_HUC: {
483 final CronetHttpURLStreamHandler cronetStreamHandler =
484 new CronetHttpURLStreamHandler(mCronetEngine);
485 for (int i = 0; i < mIterations; i++) { 476 for (int i = 0; i < mIterations; i++) {
486 tasks.add(new CronetHttpURLConnectionFetchTask(cronetStr eamHandler)); 477 tasks.add(new CronetHttpURLConnectionFetchTask());
487 } 478 }
488 break; 479 break;
489 } 480 }
490 case CRONET_ASYNC: 481 case CRONET_ASYNC:
491 tasks.add(new CronetAsyncFetchTask()); 482 tasks.add(new CronetAsyncFetchTask());
492 break; 483 break;
493 default: 484 default:
494 throw new IllegalArgumentException("Unknown mode: " + mMode) ; 485 throw new IllegalArgumentException("Unknown mode: " + mMode) ;
495 } 486 }
496 // Execute tasks. 487 // Execute tasks.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 579 }
589 580
590 @Override 581 @Override
591 public void onCreate(Bundle savedInstanceState) { 582 public void onCreate(Bundle savedInstanceState) {
592 super.onCreate(savedInstanceState); 583 super.onCreate(savedInstanceState);
593 mConfig = getIntent().getData(); 584 mConfig = getIntent().getData();
594 // Execute benchmarks on another thread to avoid networking on main thre ad. 585 // Execute benchmarks on another thread to avoid networking on main thre ad.
595 new BenchmarkTask().execute(); 586 new BenchmarkTask().execute();
596 } 587 }
597 } 588 }
OLDNEW
« no previous file with comments | « components/cronet/android/java/src/org/chromium/net/urlconnection/CronetURLStreamHandlerFactory.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698