| 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.impl; | 5 package org.chromium.net.impl; |
| 6 | 6 |
| 7 import org.chromium.base.Log; | 7 import org.chromium.base.Log; |
| 8 import org.chromium.base.VisibleForTesting; | 8 import org.chromium.base.VisibleForTesting; |
| 9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
| 10 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 private final CronetUrlRequestContext mRequestContext; | 80 private final CronetUrlRequestContext mRequestContext; |
| 81 private final Executor mExecutor; | 81 private final Executor mExecutor; |
| 82 private final Callback mCallback; | 82 private final Callback mCallback; |
| 83 private final String mInitialUrl; | 83 private final String mInitialUrl; |
| 84 private final int mInitialPriority; | 84 private final int mInitialPriority; |
| 85 private final String mInitialMethod; | 85 private final String mInitialMethod; |
| 86 private final String mRequestHeaders[]; | 86 private final String mRequestHeaders[]; |
| 87 private final boolean mDelayRequestHeadersUntilFirstFlush; | 87 private final boolean mDelayRequestHeadersUntilFirstFlush; |
| 88 private final Collection<Object> mRequestAnnotations; | 88 private final Collection<Object> mRequestAnnotations; |
| 89 private UrlRequestException mException; |
| 89 | 90 |
| 90 /* | 91 /* |
| 91 * Synchronizes access to mNativeStream, mReadState and mWriteState. | 92 * Synchronizes access to mNativeStream, mReadState and mWriteState. |
| 92 */ | 93 */ |
| 93 private final Object mNativeStreamLock = new Object(); | 94 private final Object mNativeStreamLock = new Object(); |
| 94 | 95 |
| 95 @GuardedBy("mNativeStreamLock") | 96 @GuardedBy("mNativeStreamLock") |
| 96 // Pending write data. | 97 // Pending write data. |
| 97 private LinkedList<ByteBuffer> mPendingData; | 98 private LinkedList<ByteBuffer> mPendingData; |
| 98 | 99 |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 long responseStartMs, long requestEndMs, boolean socketReused, long
sentBytesCount, | 633 long responseStartMs, long requestEndMs, boolean socketReused, long
sentBytesCount, |
| 633 long receivedBytesCount) { | 634 long receivedBytesCount) { |
| 634 synchronized (mNativeStreamLock) { | 635 synchronized (mNativeStreamLock) { |
| 635 if (mMetrics != null) { | 636 if (mMetrics != null) { |
| 636 throw new IllegalStateException("Metrics collection should only
happen once."); | 637 throw new IllegalStateException("Metrics collection should only
happen once."); |
| 637 } | 638 } |
| 638 mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, c
onnectStartMs, | 639 mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, c
onnectStartMs, |
| 639 connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingE
ndMs, pushStartMs, | 640 connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingE
ndMs, pushStartMs, |
| 640 pushEndMs, responseStartMs, requestEndMs, socketReused, sent
BytesCount, | 641 pushEndMs, responseStartMs, requestEndMs, socketReused, sent
BytesCount, |
| 641 receivedBytesCount); | 642 receivedBytesCount); |
| 642 // TODO(xunjieli): Fill this with real values. | 643 assert mReadState == mWriteState; |
| 643 final RequestFinishedInfo requestFinishedInfo = | 644 assert (mReadState == State.SUCCESS) || (mReadState == State.ERROR) |
| 644 new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mM
etrics, | 645 || (mReadState == State.CANCELED); |
| 645 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null); | 646 int finishedReason; |
| 647 if (mReadState == State.SUCCESS) { |
| 648 finishedReason = RequestFinishedInfo.SUCCEEDED; |
| 649 } else if (mReadState == State.CANCELED) { |
| 650 finishedReason = RequestFinishedInfo.CANCELED; |
| 651 } else { |
| 652 finishedReason = RequestFinishedInfo.FAILED; |
| 653 } |
| 654 final RequestFinishedInfo requestFinishedInfo = new RequestFinishedI
nfo(mInitialUrl, |
| 655 mRequestAnnotations, mMetrics, finishedReason, mResponseInfo
, mException); |
| 646 mRequestContext.reportFinished(requestFinishedInfo); | 656 mRequestContext.reportFinished(requestFinishedInfo); |
| 647 } | 657 } |
| 648 } | 658 } |
| 649 | 659 |
| 650 @VisibleForTesting | 660 @VisibleForTesting |
| 651 public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackFor
Testing) { | 661 public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackFor
Testing) { |
| 652 mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting; | 662 mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting; |
| 653 } | 663 } |
| 654 | 664 |
| 655 private static boolean doesMethodAllowWriteData(String methodName) { | 665 private static boolean doesMethodAllowWriteData(String methodName) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 mNativeStream = 0; | 741 mNativeStream = 0; |
| 732 if (mOnDestroyedCallbackForTesting != null) { | 742 if (mOnDestroyedCallbackForTesting != null) { |
| 733 mOnDestroyedCallbackForTesting.run(); | 743 mOnDestroyedCallbackForTesting.run(); |
| 734 } | 744 } |
| 735 } | 745 } |
| 736 | 746 |
| 737 /** | 747 /** |
| 738 * Fails the stream with an exception. Only called on the Executor. | 748 * Fails the stream with an exception. Only called on the Executor. |
| 739 */ | 749 */ |
| 740 private void failWithExceptionOnExecutor(CronetException e) { | 750 private void failWithExceptionOnExecutor(CronetException e) { |
| 751 mException = e; |
| 741 // Do not call into mCallback if request is complete. | 752 // Do not call into mCallback if request is complete. |
| 742 synchronized (mNativeStreamLock) { | 753 synchronized (mNativeStreamLock) { |
| 743 if (isDoneLocked()) { | 754 if (isDoneLocked()) { |
| 744 return; | 755 return; |
| 745 } | 756 } |
| 746 mReadState = mWriteState = State.ERROR; | 757 mReadState = mWriteState = State.ERROR; |
| 747 destroyNativeStreamLocked(false); | 758 destroyNativeStreamLocked(false); |
| 748 } | 759 } |
| 749 try { | 760 try { |
| 750 mCallback.onFailed(this, mResponseInfo, e); | 761 mCallback.onFailed(this, mResponseInfo, e); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 private native boolean nativeReadData( | 803 private native boolean nativeReadData( |
| 793 long nativePtr, ByteBuffer byteBuffer, int position, int limit); | 804 long nativePtr, ByteBuffer byteBuffer, int position, int limit); |
| 794 | 805 |
| 795 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 806 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 796 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers
, int[] positions, | 807 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers
, int[] positions, |
| 797 int[] limits, boolean endOfStream); | 808 int[] limits, boolean endOfStream); |
| 798 | 809 |
| 799 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 810 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 800 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 811 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 801 } | 812 } |
| OLD | NEW |