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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 private class Listener extends UrlRequestListener { | 390 private class Listener extends UrlRequestListener { |
391 private final ByteBuffer mBuffer; | 391 private final ByteBuffer mBuffer; |
392 private final Runnable mCompletionCallback; | 392 private final Runnable mCompletionCallback; |
393 | 393 |
394 Listener(ByteBuffer buffer, Runnable completionCallback) { | 394 Listener(ByteBuffer buffer, Runnable completionCallback) { |
395 mBuffer = buffer; | 395 mBuffer = buffer; |
396 mCompletionCallback = completionCallback; | 396 mCompletionCallback = completionCallback; |
397 } | 397 } |
398 | 398 |
399 @Override | 399 @Override |
400 public void onResponseStarted(UrlRequest request, ResponseInfo i
nfo) { | 400 public void onResponseStarted(UrlRequest request, UrlResponseInf
o info) { |
401 mBuffer.clear(); | 401 mBuffer.clear(); |
402 request.readNew(mBuffer); | 402 request.readNew(mBuffer); |
403 } | 403 } |
404 | 404 |
405 @Override | 405 @Override |
406 public void onReceivedRedirect( | 406 public void onReceivedRedirect( |
407 UrlRequest request, ResponseInfo info, String newLocatio
nUrl) { | 407 UrlRequest request, UrlResponseInfo info, String newLoca
tionUrl) { |
408 request.followRedirect(); | 408 request.followRedirect(); |
409 } | 409 } |
410 | 410 |
411 @Override | 411 @Override |
412 public void onReadCompleted( | 412 public void onReadCompleted( |
413 UrlRequest request, ResponseInfo info, ByteBuffer byteBu
ffer) { | 413 UrlRequest request, UrlResponseInfo info, ByteBuffer byt
eBuffer) { |
414 mBuffer.clear(); | 414 mBuffer.clear(); |
415 request.readNew(mBuffer); | 415 request.readNew(mBuffer); |
416 } | 416 } |
417 | 417 |
418 @Override | 418 @Override |
419 public void onSucceeded(UrlRequest request, ExtendedResponseInfo
info) { | 419 public void onSucceeded(UrlRequest request, UrlResponseInfo info
) { |
420 mCompletionCallback.run(); | 420 mCompletionCallback.run(); |
421 } | 421 } |
422 | 422 |
423 @Override | 423 @Override |
424 public void onFailed(UrlRequest request, ResponseInfo info, UrlR
equestException e) { | 424 public void onFailed( |
| 425 UrlRequest request, UrlResponseInfo info, UrlRequestExce
ption e) { |
425 System.out.println("Async request failed with " + e); | 426 System.out.println("Async request failed with " + e); |
426 mFailed = true; | 427 mFailed = true; |
427 } | 428 } |
428 } | 429 } |
429 | 430 |
430 private void postToWorkQueue(Runnable task) { | 431 private void postToWorkQueue(Runnable task) { |
431 try { | 432 try { |
432 mWorkQueue.put(task); | 433 mWorkQueue.put(task); |
433 } catch (InterruptedException e) { | 434 } catch (InterruptedException e) { |
434 mFailed = true; | 435 mFailed = true; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 589 } |
589 | 590 |
590 @Override | 591 @Override |
591 public void onCreate(Bundle savedInstanceState) { | 592 public void onCreate(Bundle savedInstanceState) { |
592 super.onCreate(savedInstanceState); | 593 super.onCreate(savedInstanceState); |
593 mConfig = getIntent().getData(); | 594 mConfig = getIntent().getData(); |
594 // Execute benchmarks on another thread to avoid networking on main thre
ad. | 595 // Execute benchmarks on another thread to avoid networking on main thre
ad. |
595 new BenchmarkTask().execute(); | 596 new BenchmarkTask().execute(); |
596 } | 597 } |
597 } | 598 } |
OLD | NEW |