| 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.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; |
| 11 import org.chromium.base.annotations.NativeClassQualifiedName; | 11 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 12 import org.chromium.net.BidirectionalStream; |
| 13 import org.chromium.net.CronetException; |
| 14 import org.chromium.net.Preconditions; |
| 15 import org.chromium.net.QuicException; |
| 16 import org.chromium.net.RequestPriority; |
| 17 import org.chromium.net.UrlRequestException; |
| 18 import org.chromium.net.UrlResponseInfo; |
| 12 | 19 |
| 13 import java.nio.ByteBuffer; | 20 import java.nio.ByteBuffer; |
| 14 import java.util.AbstractMap; | 21 import java.util.AbstractMap; |
| 15 import java.util.ArrayList; | 22 import java.util.ArrayList; |
| 16 import java.util.Arrays; | 23 import java.util.Arrays; |
| 17 import java.util.LinkedList; | 24 import java.util.LinkedList; |
| 18 import java.util.List; | 25 import java.util.List; |
| 19 import java.util.Map; | 26 import java.util.Map; |
| 20 import java.util.concurrent.Executor; | 27 import java.util.concurrent.Executor; |
| 21 import java.util.concurrent.RejectedExecutionException; | 28 import java.util.concurrent.RejectedExecutionException; |
| 22 | 29 |
| 23 import javax.annotation.concurrent.GuardedBy; | 30 import javax.annotation.concurrent.GuardedBy; |
| 24 | 31 |
| 25 /** | 32 /** |
| 26 * {@link BidirectionalStream} implementation using Chromium network stack. | 33 * {@link BidirectionalStream} implementation using Chromium network stack. |
| 27 * All @CalledByNative methods are called on the native network thread | 34 * All @CalledByNative methods are called on the native network thread |
| 28 * and post tasks with callback calls onto Executor. Upon returning from callbac
k, the native | 35 * and post tasks with callback calls onto Executor. Upon returning from callbac
k, the native |
| 29 * stream is called on Executor thread and posts native tasks to the native netw
ork thread. | 36 * stream is called on Executor thread and posts native tasks to the native netw
ork thread. |
| 30 */ | 37 */ |
| 31 @JNINamespace("cronet") | 38 @JNINamespace("cronet") |
| 32 class CronetBidirectionalStream extends BidirectionalStream { | 39 @VisibleForTesting |
| 40 public class CronetBidirectionalStream extends BidirectionalStream { |
| 33 /** | 41 /** |
| 34 * States of BidirectionalStream are tracked in mReadState and mWriteState. | 42 * States of BidirectionalStream are tracked in mReadState and mWriteState. |
| 35 * The write state is separated out as it changes independently of the read
state. | 43 * The write state is separated out as it changes independently of the read
state. |
| 36 * There is one initial state: State.NOT_STARTED. There is one normal final
state: | 44 * There is one initial state: State.NOT_STARTED. There is one normal final
state: |
| 37 * State.SUCCESS, reached after State.READING_DONE and State.WRITING_DONE. T
here are two | 45 * State.SUCCESS, reached after State.READING_DONE and State.WRITING_DONE. T
here are two |
| 38 * exceptional final states: State.CANCELED and State.ERROR, which can be re
ached from | 46 * exceptional final states: State.CANCELED and State.ERROR, which can be re
ached from |
| 39 * any other non-final state. | 47 * any other non-final state. |
| 40 */ | 48 */ |
| 41 private enum State { | 49 private enum State { |
| 42 /* Initial state, stream not started. */ | 50 /* Initial state, stream not started. */ |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 private native boolean nativeReadData( | 766 private native boolean nativeReadData( |
| 759 long nativePtr, ByteBuffer byteBuffer, int position, int limit); | 767 long nativePtr, ByteBuffer byteBuffer, int position, int limit); |
| 760 | 768 |
| 761 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 769 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 762 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers
, int[] positions, | 770 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers
, int[] positions, |
| 763 int[] limits, boolean endOfStream); | 771 int[] limits, boolean endOfStream); |
| 764 | 772 |
| 765 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 773 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 766 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 774 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 767 } | 775 } |
| OLD | NEW |