| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.impl; | 5 package org.chromium.net.impl; |
| 6 | 6 |
| 7 import android.util.Log; | 7 import android.util.Log; |
| 8 | 8 |
| 9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 */ | 76 */ |
| 77 private final List<String> mUrlChain = new ArrayList<String>(); | 77 private final List<String> mUrlChain = new ArrayList<String>(); |
| 78 private long mReceivedBytesCountFromRedirects; | 78 private long mReceivedBytesCountFromRedirects; |
| 79 | 79 |
| 80 private final UrlRequest.Callback mCallback; | 80 private final UrlRequest.Callback mCallback; |
| 81 private final String mInitialUrl; | 81 private final String mInitialUrl; |
| 82 private final int mPriority; | 82 private final int mPriority; |
| 83 private String mInitialMethod; | 83 private String mInitialMethod; |
| 84 private final HeadersList mRequestHeaders = new HeadersList(); | 84 private final HeadersList mRequestHeaders = new HeadersList(); |
| 85 private final Collection<Object> mRequestAnnotations; | 85 private final Collection<Object> mRequestAnnotations; |
| 86 @RequestFinishedInfo.FinishedReason |
| 87 private int mFinishedReason; |
| 88 private UrlRequestException mException; |
| 86 private final boolean mDisableCache; | 89 private final boolean mDisableCache; |
| 87 private final boolean mDisableConnectionMigration; | 90 private final boolean mDisableConnectionMigration; |
| 88 | 91 |
| 89 private CronetUploadDataStream mUploadDataStream; | 92 private CronetUploadDataStream mUploadDataStream; |
| 90 | 93 |
| 91 private UrlResponseInfo mResponseInfo; | 94 private UrlResponseInfo mResponseInfo; |
| 92 | 95 |
| 93 /* | 96 /* |
| 94 * Listener callback is repeatedly invoked when each read is completed, so i
t | 97 * Listener callback is repeatedly invoked when each read is completed, so i
t |
| 95 * is cached as a member variable. | 98 * is cached as a member variable. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 UrlRequestException uploadError = | 446 UrlRequestException uploadError = |
| 444 new UrlRequestException("Exception received from UploadDataProvi
der", e); | 447 new UrlRequestException("Exception received from UploadDataProvi
der", e); |
| 445 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception in upload method", e); | 448 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception in upload method", e); |
| 446 failWithException(uploadError); | 449 failWithException(uploadError); |
| 447 } | 450 } |
| 448 | 451 |
| 449 /** | 452 /** |
| 450 * Fails the request with an exception. Can be called on any thread. | 453 * Fails the request with an exception. Can be called on any thread. |
| 451 */ | 454 */ |
| 452 private void failWithException(final UrlRequestException exception) { | 455 private void failWithException(final UrlRequestException exception) { |
| 456 mException = exception; |
| 453 synchronized (mUrlRequestAdapterLock) { | 457 synchronized (mUrlRequestAdapterLock) { |
| 454 if (isDoneLocked()) { | 458 if (isDoneLocked()) { |
| 455 return; | 459 return; |
| 456 } | 460 } |
| 457 destroyRequestAdapter(false); | 461 destroyRequestAdapter(false); |
| 458 } | 462 } |
| 459 Runnable task = new Runnable() { | 463 Runnable task = new Runnable() { |
| 460 @Override | 464 @Override |
| 461 public void run() { | 465 public void run() { |
| 462 try { | 466 try { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 596 |
| 593 /** | 597 /** |
| 594 * Called when request is completed successfully, no callbacks will be | 598 * Called when request is completed successfully, no callbacks will be |
| 595 * called afterwards. | 599 * called afterwards. |
| 596 * | 600 * |
| 597 * @param receivedBytesCount number of bytes received. | 601 * @param receivedBytesCount number of bytes received. |
| 598 */ | 602 */ |
| 599 @SuppressWarnings("unused") | 603 @SuppressWarnings("unused") |
| 600 @CalledByNative | 604 @CalledByNative |
| 601 private void onSucceeded(long receivedBytesCount) { | 605 private void onSucceeded(long receivedBytesCount) { |
| 606 mFinishedReason = RequestFinishedInfo.SUCCEEDED; |
| 602 mResponseInfo.setReceivedBytesCount(mReceivedBytesCountFromRedirects + r
eceivedBytesCount); | 607 mResponseInfo.setReceivedBytesCount(mReceivedBytesCountFromRedirects + r
eceivedBytesCount); |
| 603 Runnable task = new Runnable() { | 608 Runnable task = new Runnable() { |
| 604 @Override | 609 @Override |
| 605 public void run() { | 610 public void run() { |
| 606 synchronized (mUrlRequestAdapterLock) { | 611 synchronized (mUrlRequestAdapterLock) { |
| 607 if (isDoneLocked()) { | 612 if (isDoneLocked()) { |
| 608 return; | 613 return; |
| 609 } | 614 } |
| 610 // Destroy adapter first, so request context could be shut | 615 // Destroy adapter first, so request context could be shut |
| 611 // down from the listener. | 616 // down from the listener. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 627 * @param errorCode error code from {@link UrlRequestException.ERROR_LISTENE
R_EXCEPTION_THROWN | 632 * @param errorCode error code from {@link UrlRequestException.ERROR_LISTENE
R_EXCEPTION_THROWN |
| 628 * UrlRequestException.ERROR_*}. | 633 * UrlRequestException.ERROR_*}. |
| 629 * @param nativeError native net error code. | 634 * @param nativeError native net error code. |
| 630 * @param errorString textual representation of the error code. | 635 * @param errorString textual representation of the error code. |
| 631 * @param receivedBytesCount number of bytes received. | 636 * @param receivedBytesCount number of bytes received. |
| 632 */ | 637 */ |
| 633 @SuppressWarnings("unused") | 638 @SuppressWarnings("unused") |
| 634 @CalledByNative | 639 @CalledByNative |
| 635 private void onError(int errorCode, int nativeError, int nativeQuicError, St
ring errorString, | 640 private void onError(int errorCode, int nativeError, int nativeQuicError, St
ring errorString, |
| 636 long receivedBytesCount) { | 641 long receivedBytesCount) { |
| 642 mFinishedReason = RequestFinishedInfo.FAILED; |
| 637 if (mResponseInfo != null) { | 643 if (mResponseInfo != null) { |
| 638 mResponseInfo.setReceivedBytesCount( | 644 mResponseInfo.setReceivedBytesCount( |
| 639 mReceivedBytesCountFromRedirects + receivedBytesCount); | 645 mReceivedBytesCountFromRedirects + receivedBytesCount); |
| 640 } | 646 } |
| 641 if (errorCode == UrlRequestException.ERROR_QUIC_PROTOCOL_FAILED) { | 647 if (errorCode == UrlRequestException.ERROR_QUIC_PROTOCOL_FAILED) { |
| 642 failWithException(new QuicException( | 648 failWithException(new QuicException( |
| 643 "Exception in CronetUrlRequest: " + errorString, nativeError
, nativeQuicError)); | 649 "Exception in CronetUrlRequest: " + errorString, nativeError
, nativeQuicError)); |
| 644 } else { | 650 } else { |
| 645 failWithException(new UrlRequestException( | 651 failWithException(new UrlRequestException( |
| 646 "Exception in CronetUrlRequest: " + errorString, errorCode,
nativeError)); | 652 "Exception in CronetUrlRequest: " + errorString, errorCode,
nativeError)); |
| 647 } | 653 } |
| 648 } | 654 } |
| 649 | 655 |
| 650 /** | 656 /** |
| 651 * Called when request is canceled, no callbacks will be called afterwards. | 657 * Called when request is canceled, no callbacks will be called afterwards. |
| 652 */ | 658 */ |
| 653 @SuppressWarnings("unused") | 659 @SuppressWarnings("unused") |
| 654 @CalledByNative | 660 @CalledByNative |
| 655 private void onCanceled() { | 661 private void onCanceled() { |
| 662 mFinishedReason = RequestFinishedInfo.CANCELED; |
| 656 Runnable task = new Runnable() { | 663 Runnable task = new Runnable() { |
| 657 @Override | 664 @Override |
| 658 public void run() { | 665 public void run() { |
| 659 try { | 666 try { |
| 660 mCallback.onCanceled(CronetUrlRequest.this, mResponseInfo); | 667 mCallback.onCanceled(CronetUrlRequest.this, mResponseInfo); |
| 661 } catch (Exception e) { | 668 } catch (Exception e) { |
| 662 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception in onCance
led method", e); | 669 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception in onCance
led method", e); |
| 663 } | 670 } |
| 664 } | 671 } |
| 665 }; | 672 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, c
onnectStartMs, | 706 mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, c
onnectStartMs, |
| 700 connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingE
ndMs, pushStartMs, | 707 connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingE
ndMs, pushStartMs, |
| 701 pushEndMs, responseStartMs, responseEndMs, socketReused, sen
tBytesCount, | 708 pushEndMs, responseStartMs, responseEndMs, socketReused, sen
tBytesCount, |
| 702 receivedBytesCount); | 709 receivedBytesCount); |
| 703 } | 710 } |
| 704 mRequestContext.reportFinished(getRequestFinishedInfo()); | 711 mRequestContext.reportFinished(getRequestFinishedInfo()); |
| 705 } | 712 } |
| 706 | 713 |
| 707 private RequestFinishedInfo getRequestFinishedInfo() { | 714 private RequestFinishedInfo getRequestFinishedInfo() { |
| 708 // TODO(mgersh): fill in real values for finishedReason and exception | 715 // TODO(mgersh): fill in real values for finishedReason and exception |
| 709 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mMetric
s, | 716 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mMetric
s, mFinishedReason, |
| 710 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null); | 717 mResponseInfo, mException); |
| 711 } | 718 } |
| 712 | 719 |
| 713 /** Enforces prohibition of direct execution. */ | 720 /** Enforces prohibition of direct execution. */ |
| 714 void checkCallingThread() { | 721 void checkCallingThread() { |
| 715 if (!mAllowDirectExecutor && mRequestContext.isNetworkThread(Thread.curr
entThread())) { | 722 if (!mAllowDirectExecutor && mRequestContext.isNetworkThread(Thread.curr
entThread())) { |
| 716 throw new InlineExecutionProhibitedException(); | 723 throw new InlineExecutionProhibitedException(); |
| 717 } | 724 } |
| 718 } | 725 } |
| 719 | 726 |
| 720 // Native methods are implemented in cronet_url_request_adapter.cc. | 727 // Native methods are implemented in cronet_url_request_adapter.cc. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 738 @NativeClassQualifiedName("CronetURLRequestAdapter") | 745 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 739 private native boolean nativeReadData( | 746 private native boolean nativeReadData( |
| 740 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); | 747 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); |
| 741 | 748 |
| 742 @NativeClassQualifiedName("CronetURLRequestAdapter") | 749 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 743 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 750 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 744 | 751 |
| 745 @NativeClassQualifiedName("CronetURLRequestAdapter") | 752 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 746 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); | 753 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); |
| 747 } | 754 } |
| OLD | NEW |