Chromium Code Reviews| 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 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 } | 64 } |
| 65 | 65 |
| 66 private final CronetUrlRequestContext mRequestContext; | 66 private final CronetUrlRequestContext mRequestContext; |
| 67 private final Executor mExecutor; | 67 private final Executor mExecutor; |
| 68 private final Callback mCallback; | 68 private final Callback mCallback; |
| 69 private final String mInitialUrl; | 69 private final String mInitialUrl; |
| 70 private final int mInitialPriority; | 70 private final int mInitialPriority; |
| 71 private final String mInitialMethod; | 71 private final String mInitialMethod; |
| 72 private final String mRequestHeaders[]; | 72 private final String mRequestHeaders[]; |
| 73 private final boolean mDisableAutoFlush; | 73 private final boolean mDisableAutoFlush; |
| 74 private final boolean mDelayHeadersUntilNextWrite; | |
| 74 | 75 |
| 75 /* | 76 /* |
| 76 * Synchronizes access to mNativeStream, mReadState and mWriteState. | 77 * Synchronizes access to mNativeStream, mReadState and mWriteState. |
| 77 */ | 78 */ |
| 78 private final Object mNativeStreamLock = new Object(); | 79 private final Object mNativeStreamLock = new Object(); |
| 79 | 80 |
| 80 @GuardedBy("mNativeStreamLock") | 81 @GuardedBy("mNativeStreamLock") |
| 81 // Pending write data. | 82 // Pending write data. |
| 82 private LinkedList<ByteBuffer> mPendingData; | 83 private LinkedList<ByteBuffer> mPendingData; |
| 83 | 84 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 } | 196 } |
| 196 } catch (Exception e) { | 197 } catch (Exception e) { |
| 197 onCallbackException(e); | 198 onCallbackException(e); |
| 198 } | 199 } |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 | 202 |
| 202 CronetBidirectionalStream(CronetUrlRequestContext requestContext, String url , | 203 CronetBidirectionalStream(CronetUrlRequestContext requestContext, String url , |
| 203 @BidirectionalStream.Builder.StreamPriority int priority, Callback c allback, | 204 @BidirectionalStream.Builder.StreamPriority int priority, Callback c allback, |
| 204 Executor executor, String httpMethod, List<Map.Entry<String, String> > requestHeaders, | 205 Executor executor, String httpMethod, List<Map.Entry<String, String> > requestHeaders, |
| 205 boolean disableAutoFlush) { | 206 boolean disableAutoFlush, boolean delayHeadersUntilNextWrite) { |
| 206 mRequestContext = requestContext; | 207 mRequestContext = requestContext; |
| 207 mInitialUrl = url; | 208 mInitialUrl = url; |
| 208 mInitialPriority = convertStreamPriority(priority); | 209 mInitialPriority = convertStreamPriority(priority); |
| 209 mCallback = callback; | 210 mCallback = callback; |
| 210 mExecutor = executor; | 211 mExecutor = executor; |
| 211 mInitialMethod = httpMethod; | 212 mInitialMethod = httpMethod; |
| 212 mRequestHeaders = stringsFromHeaderList(requestHeaders); | 213 mRequestHeaders = stringsFromHeaderList(requestHeaders); |
| 213 mDisableAutoFlush = disableAutoFlush; | 214 mDisableAutoFlush = disableAutoFlush; |
| 215 mDelayHeadersUntilNextWrite = delayHeadersUntilNextWrite; | |
| 214 mPendingData = new LinkedList<>(); | 216 mPendingData = new LinkedList<>(); |
| 215 mFlushData = new LinkedList<>(); | 217 mFlushData = new LinkedList<>(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 @Override | 220 @Override |
| 219 public void start() { | 221 public void start() { |
| 220 synchronized (mNativeStreamLock) { | 222 synchronized (mNativeStreamLock) { |
| 221 if (mReadState != State.NOT_STARTED) { | 223 if (mReadState != State.NOT_STARTED) { |
| 222 throw new IllegalStateException("Stream is already started."); | 224 throw new IllegalStateException("Stream is already started."); |
| 223 } | 225 } |
| 224 try { | 226 try { |
| 225 mNativeStream = nativeCreateBidirectionalStream( | 227 mNativeStream = nativeCreateBidirectionalStream( |
| 226 mRequestContext.getUrlRequestContextAdapter(), mDisableA utoFlush); | 228 mRequestContext.getUrlRequestContextAdapter(), mDelayHea dersUntilNextWrite); |
|
mef
2016/05/23 14:57:26
Is mDisableAutoFlush not used now?
| |
| 227 mRequestContext.onRequestStarted(); | 229 mRequestContext.onRequestStarted(); |
| 228 // Non-zero startResult means an argument error. | 230 // Non-zero startResult means an argument error. |
| 229 int startResult = nativeStart(mNativeStream, mInitialUrl, mIniti alPriority, | 231 int startResult = nativeStart(mNativeStream, mInitialUrl, mIniti alPriority, |
| 230 mInitialMethod, mRequestHeaders, !doesMethodAllowWriteDa ta(mInitialMethod)); | 232 mInitialMethod, mRequestHeaders, !doesMethodAllowWriteDa ta(mInitialMethod)); |
| 231 if (startResult == -1) { | 233 if (startResult == -1) { |
| 232 throw new IllegalArgumentException("Invalid http method " + mInitialMethod); | 234 throw new IllegalArgumentException("Invalid http method " + mInitialMethod); |
| 233 } | 235 } |
| 234 if (startResult > 0) { | 236 if (startResult > 0) { |
| 235 int headerPos = startResult - 1; | 237 int headerPos = startResult - 1; |
| 236 throw new IllegalArgumentException("Invalid header " | 238 throw new IllegalArgumentException("Invalid header " |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 private void failWithException(final CronetException exception) { | 683 private void failWithException(final CronetException exception) { |
| 682 postTaskToExecutor(new Runnable() { | 684 postTaskToExecutor(new Runnable() { |
| 683 public void run() { | 685 public void run() { |
| 684 failWithExceptionOnExecutor(exception); | 686 failWithExceptionOnExecutor(exception); |
| 685 } | 687 } |
| 686 }); | 688 }); |
| 687 } | 689 } |
| 688 | 690 |
| 689 // Native methods are implemented in cronet_bidirectional_stream_adapter.cc. | 691 // Native methods are implemented in cronet_bidirectional_stream_adapter.cc. |
| 690 private native long nativeCreateBidirectionalStream( | 692 private native long nativeCreateBidirectionalStream( |
| 691 long urlRequestContextAdapter, boolean disableAutoFlush); | 693 long urlRequestContextAdapter, boolean delayHeadersUntilNextWrite); |
| 692 | 694 |
| 693 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 695 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 694 private native int nativeStart(long nativePtr, String url, int priority, Str ing method, | 696 private native int nativeStart(long nativePtr, String url, int priority, Str ing method, |
| 695 String[] headers, boolean endOfStream); | 697 String[] headers, boolean endOfStream); |
| 696 | 698 |
| 697 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 699 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 698 private native boolean nativeReadData( | 700 private native boolean nativeReadData( |
| 699 long nativePtr, ByteBuffer byteBuffer, int position, int limit); | 701 long nativePtr, ByteBuffer byteBuffer, int position, int limit); |
| 700 | 702 |
| 701 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 703 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 702 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions, | 704 private native boolean nativeWritevData(long nativePtr, ByteBuffer[] buffers , int[] positions, |
| 703 int[] limits, boolean endOfStream); | 705 int[] limits, boolean endOfStream); |
| 704 | 706 |
| 705 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") | 707 @NativeClassQualifiedName("CronetBidirectionalStreamAdapter") |
| 706 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 708 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 707 } | 709 } |
| OLD | NEW |