| 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 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.JNIAdditionalImport; | 10 import org.chromium.base.annotations.JNIAdditionalImport; |
| 11 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.base.annotations.NativeClassQualifiedName; | 12 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 13 import org.chromium.net.InlineExecutionProhibitedException; | 13 import org.chromium.net.InlineExecutionProhibitedException; |
| 14 import org.chromium.net.QuicException; | 14 import org.chromium.net.QuicException; |
| 15 import org.chromium.net.RequestFinishedInfo; | 15 import org.chromium.net.RequestFinishedInfo; |
| 16 import org.chromium.net.RequestPriority; | 16 import org.chromium.net.RequestPriority; |
| 17 import org.chromium.net.UploadDataProvider; | 17 import org.chromium.net.UploadDataProvider; |
| 18 import org.chromium.net.UrlRequest; | 18 import org.chromium.net.UrlRequest; |
| 19 import org.chromium.net.UrlRequestException; | 19 import org.chromium.net.UrlRequestException; |
| 20 // JNI generator requires this; unfortunately CL upload checks disallow it so th
ey must be bypassed. |
| 21 import org.chromium.net.impl.VersionSafeCallbacks; |
| 20 | 22 |
| 21 import java.nio.ByteBuffer; | 23 import java.nio.ByteBuffer; |
| 22 import java.util.AbstractMap; | 24 import java.util.AbstractMap; |
| 23 import java.util.ArrayList; | 25 import java.util.ArrayList; |
| 24 import java.util.Collection; | 26 import java.util.Collection; |
| 25 import java.util.List; | 27 import java.util.List; |
| 26 import java.util.Map; | 28 import java.util.Map; |
| 27 import java.util.concurrent.Executor; | 29 import java.util.concurrent.Executor; |
| 28 import java.util.concurrent.RejectedExecutionException; | 30 import java.util.concurrent.RejectedExecutionException; |
| 29 | 31 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 private final Executor mExecutor; | 69 private final Executor mExecutor; |
| 68 | 70 |
| 69 /* | 71 /* |
| 70 * URL chain contains the URL currently being requested, and | 72 * URL chain contains the URL currently being requested, and |
| 71 * all URLs previously requested. New URLs are added before | 73 * all URLs previously requested. New URLs are added before |
| 72 * mCallback.onRedirectReceived is called. | 74 * mCallback.onRedirectReceived is called. |
| 73 */ | 75 */ |
| 74 private final List<String> mUrlChain = new ArrayList<String>(); | 76 private final List<String> mUrlChain = new ArrayList<String>(); |
| 75 private long mReceivedBytesCountFromRedirects; | 77 private long mReceivedBytesCountFromRedirects; |
| 76 | 78 |
| 77 private final UrlRequest.Callback mCallback; | 79 private final VersionSafeCallbacks.UrlRequestCallback mCallback; |
| 78 private final String mInitialUrl; | 80 private final String mInitialUrl; |
| 79 private final int mPriority; | 81 private final int mPriority; |
| 80 private String mInitialMethod; | 82 private String mInitialMethod; |
| 81 private final HeadersList mRequestHeaders = new HeadersList(); | 83 private final HeadersList mRequestHeaders = new HeadersList(); |
| 82 private final Collection<Object> mRequestAnnotations; | 84 private final Collection<Object> mRequestAnnotations; |
| 83 @RequestFinishedInfoImpl.FinishedReason | 85 @RequestFinishedInfoImpl.FinishedReason |
| 84 private int mFinishedReason; | 86 private int mFinishedReason; |
| 85 private UrlRequestException mException; | 87 private UrlRequestException mException; |
| 86 private final boolean mDisableCache; | 88 private final boolean mDisableCache; |
| 87 private final boolean mDisableConnectionMigration; | 89 private final boolean mDisableConnectionMigration; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 138 } |
| 137 if (executor == null) { | 139 if (executor == null) { |
| 138 throw new NullPointerException("Executor is required"); | 140 throw new NullPointerException("Executor is required"); |
| 139 } | 141 } |
| 140 | 142 |
| 141 mAllowDirectExecutor = allowDirectExecutor; | 143 mAllowDirectExecutor = allowDirectExecutor; |
| 142 mRequestContext = requestContext; | 144 mRequestContext = requestContext; |
| 143 mInitialUrl = url; | 145 mInitialUrl = url; |
| 144 mUrlChain.add(url); | 146 mUrlChain.add(url); |
| 145 mPriority = convertRequestPriority(priority); | 147 mPriority = convertRequestPriority(priority); |
| 146 mCallback = callback; | 148 mCallback = new VersionSafeCallbacks.UrlRequestCallback(callback); |
| 147 mExecutor = executor; | 149 mExecutor = executor; |
| 148 mRequestAnnotations = requestAnnotations; | 150 mRequestAnnotations = requestAnnotations; |
| 149 mDisableCache = disableCache; | 151 mDisableCache = disableCache; |
| 150 mDisableConnectionMigration = disableConnectionMigration; | 152 mDisableConnectionMigration = disableConnectionMigration; |
| 151 } | 153 } |
| 152 | 154 |
| 153 @Override | 155 @Override |
| 154 public void setHttpMethod(String method) { | 156 public void setHttpMethod(String method) { |
| 155 checkNotStarted(); | 157 checkNotStarted(); |
| 156 if (method == null) { | 158 if (method == null) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return isDoneLocked(); | 309 return isDoneLocked(); |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 | 312 |
| 311 @GuardedBy("mUrlRequestAdapterLock") | 313 @GuardedBy("mUrlRequestAdapterLock") |
| 312 private boolean isDoneLocked() { | 314 private boolean isDoneLocked() { |
| 313 return mStarted && mUrlRequestAdapter == 0; | 315 return mStarted && mUrlRequestAdapter == 0; |
| 314 } | 316 } |
| 315 | 317 |
| 316 @Override | 318 @Override |
| 317 public void getStatus(final UrlRequest.StatusListener listener) { | 319 public void getStatus(UrlRequest.StatusListener unsafeListener) { |
| 320 final VersionSafeCallbacks.UrlRequestStatusListener listener = |
| 321 new VersionSafeCallbacks.UrlRequestStatusListener(unsafeListener
); |
| 318 synchronized (mUrlRequestAdapterLock) { | 322 synchronized (mUrlRequestAdapterLock) { |
| 319 if (mUrlRequestAdapter != 0) { | 323 if (mUrlRequestAdapter != 0) { |
| 320 nativeGetStatus(mUrlRequestAdapter, listener); | 324 nativeGetStatus(mUrlRequestAdapter, listener); |
| 321 return; | 325 return; |
| 322 } | 326 } |
| 323 } | 327 } |
| 324 Runnable task = new Runnable() { | 328 Runnable task = new Runnable() { |
| 325 @Override | 329 @Override |
| 326 public void run() { | 330 public void run() { |
| 327 listener.onStatus(UrlRequest.Status.INVALID); | 331 listener.onStatus(UrlRequest.Status.INVALID); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 }; | 672 }; |
| 669 postTaskToExecutor(task); | 673 postTaskToExecutor(task); |
| 670 } | 674 } |
| 671 | 675 |
| 672 /** | 676 /** |
| 673 * Called by the native code when request status is fetched from the | 677 * Called by the native code when request status is fetched from the |
| 674 * native stack. | 678 * native stack. |
| 675 */ | 679 */ |
| 676 @SuppressWarnings("unused") | 680 @SuppressWarnings("unused") |
| 677 @CalledByNative | 681 @CalledByNative |
| 678 private void onStatus(final UrlRequest.StatusListener listener, final int lo
adState) { | 682 private void onStatus( |
| 683 final VersionSafeCallbacks.UrlRequestStatusListener listener, final
int loadState) { |
| 679 Runnable task = new Runnable() { | 684 Runnable task = new Runnable() { |
| 680 @Override | 685 @Override |
| 681 public void run() { | 686 public void run() { |
| 682 listener.onStatus(convertLoadState(loadState)); | 687 listener.onStatus(convertLoadState(loadState)); |
| 683 } | 688 } |
| 684 }; | 689 }; |
| 685 postTaskToExecutor(task); | 690 postTaskToExecutor(task); |
| 686 } | 691 } |
| 687 | 692 |
| 688 /** | 693 /** |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 private native void nativeFollowDeferredRedirect(long nativePtr); | 775 private native void nativeFollowDeferredRedirect(long nativePtr); |
| 771 | 776 |
| 772 @NativeClassQualifiedName("CronetURLRequestAdapter") | 777 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 773 private native boolean nativeReadData( | 778 private native boolean nativeReadData( |
| 774 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); | 779 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); |
| 775 | 780 |
| 776 @NativeClassQualifiedName("CronetURLRequestAdapter") | 781 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 777 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 782 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 778 | 783 |
| 779 @NativeClassQualifiedName("CronetURLRequestAdapter") | 784 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 780 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); | 785 private native void nativeGetStatus( |
| 786 long nativePtr, VersionSafeCallbacks.UrlRequestStatusListener listen
er); |
| 781 } | 787 } |
| OLD | NEW |