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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java

Issue 2422993004: Implement finished reason and exception for BidirectionalStream (Closed)
Patch Set: Created 4 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 | « no previous file | components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequest.java » ('j') | 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.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
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
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 int finishedReason;
643 final RequestFinishedInfo requestFinishedInfo = 644 if (mReadState == State.SUCCESS && mWriteState == State.SUCCESS) {
644 new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mM etrics, 645 finishedReason = RequestFinishedInfo.SUCCEEDED;
645 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null); 646 } else if (mReadState == State.ERROR && mWriteState == State.ERROR) {
647 finishedReason = RequestFinishedInfo.FAILED;
648 } else if (mReadState == State.CANCELED && mWriteState == State.CANC ELED) {
649 finishedReason = RequestFinishedInfo.CANCELED;
650 } else {
651 throw new IllegalStateException("Unexpected state when collectin g metrics.");
xunjieli 2016/10/17 21:33:43 Instead of doing a runtime exception that can't be
mgersh 2016/10/17 22:20:45 Done.
652 }
653 final RequestFinishedInfo requestFinishedInfo = new RequestFinishedI nfo(mInitialUrl,
654 mRequestAnnotations, mMetrics, finishedReason, mResponseInfo , mException);
646 mRequestContext.reportFinished(requestFinishedInfo); 655 mRequestContext.reportFinished(requestFinishedInfo);
647 } 656 }
648 } 657 }
649 658
650 @VisibleForTesting 659 @VisibleForTesting
651 public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackFor Testing) { 660 public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackFor Testing) {
652 mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting; 661 mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting;
653 } 662 }
654 663
655 private static boolean doesMethodAllowWriteData(String methodName) { 664 private static boolean doesMethodAllowWriteData(String methodName) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 mNativeStream = 0; 740 mNativeStream = 0;
732 if (mOnDestroyedCallbackForTesting != null) { 741 if (mOnDestroyedCallbackForTesting != null) {
733 mOnDestroyedCallbackForTesting.run(); 742 mOnDestroyedCallbackForTesting.run();
734 } 743 }
735 } 744 }
736 745
737 /** 746 /**
738 * Fails the stream with an exception. Only called on the Executor. 747 * Fails the stream with an exception. Only called on the Executor.
739 */ 748 */
740 private void failWithExceptionOnExecutor(CronetException e) { 749 private void failWithExceptionOnExecutor(CronetException e) {
750 mException = e;
741 // Do not call into mCallback if request is complete. 751 // Do not call into mCallback if request is complete.
742 synchronized (mNativeStreamLock) { 752 synchronized (mNativeStreamLock) {
743 if (isDoneLocked()) { 753 if (isDoneLocked()) {
744 return; 754 return;
745 } 755 }
746 mReadState = mWriteState = State.ERROR; 756 mReadState = mWriteState = State.ERROR;
747 destroyNativeStreamLocked(false); 757 destroyNativeStreamLocked(false);
748 } 758 }
749 try { 759 try {
750 mCallback.onFailed(this, mResponseInfo, e); 760 mCallback.onFailed(this, mResponseInfo, e);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 private native boolean nativeReadData( 802 private native boolean nativeReadData(
793 long nativePtr, ByteBuffer byteBuffer, int position, int limit); 803 long nativePtr, ByteBuffer byteBuffer, int position, int limit);
794 804
795 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") 805 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter")
796 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions, 806 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions,
797 int[] limits, boolean endOfStream); 807 int[] limits, boolean endOfStream);
798 808
799 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") 809 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter")
800 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); 810 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled);
801 } 811 }
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698