| 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 android.os.SystemClock; | 7 import android.os.SystemClock; |
| 8 import android.support.annotation.Nullable; | 8 import android.support.annotation.Nullable; |
| 9 import android.util.Log; | 9 import android.util.Log; |
| 10 | 10 |
| 11 import org.chromium.base.VisibleForTesting; | 11 import org.chromium.base.VisibleForTesting; |
| 12 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 13 import org.chromium.base.annotations.JNIAdditionalImport; | 13 import org.chromium.base.annotations.JNIAdditionalImport; |
| 14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.base.annotations.NativeClassQualifiedName; | 15 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 16 import org.chromium.net.InlineExecutionProhibitedException; | 16 import org.chromium.net.InlineExecutionProhibitedException; |
| 17 import org.chromium.net.Preconditions; | |
| 18 import org.chromium.net.QuicException; | 17 import org.chromium.net.QuicException; |
| 19 import org.chromium.net.RequestFinishedInfo; | 18 import org.chromium.net.RequestFinishedInfo; |
| 20 import org.chromium.net.RequestPriority; | 19 import org.chromium.net.RequestPriority; |
| 21 import org.chromium.net.UploadDataProvider; | 20 import org.chromium.net.UploadDataProvider; |
| 22 import org.chromium.net.UrlRequest; | 21 import org.chromium.net.UrlRequest; |
| 23 import org.chromium.net.UrlRequestException; | 22 import org.chromium.net.UrlRequestException; |
| 24 import org.chromium.net.UrlResponseInfo; | 23 import org.chromium.net.UrlResponseInfo; |
| 25 | 24 |
| 26 import java.nio.ByteBuffer; | 25 import java.nio.ByteBuffer; |
| 27 import java.util.AbstractMap; | 26 import java.util.AbstractMap; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 * All @CallByNative methods are called on native network thread | 39 * All @CallByNative methods are called on native network thread |
| 41 * and post tasks with listener calls onto Executor. Upon return from listener | 40 * and post tasks with listener calls onto Executor. Upon return from listener |
| 42 * callback native request adapter is called on executive thread and posts | 41 * callback native request adapter is called on executive thread and posts |
| 43 * native tasks to native network thread. Because Cancel could be called from | 42 * native tasks to native network thread. Because Cancel could be called from |
| 44 * any thread it is protected by mUrlRequestAdapterLock. | 43 * any thread it is protected by mUrlRequestAdapterLock. |
| 45 */ | 44 */ |
| 46 @JNINamespace("cronet") | 45 @JNINamespace("cronet") |
| 47 // Qualifies UrlRequest.StatusListener which is used in onStatus, a JNI method. | 46 // Qualifies UrlRequest.StatusListener which is used in onStatus, a JNI method. |
| 48 @JNIAdditionalImport(UrlRequest.class) | 47 @JNIAdditionalImport(UrlRequest.class) |
| 49 @VisibleForTesting | 48 @VisibleForTesting |
| 50 public final class CronetUrlRequest implements UrlRequest { | 49 public final class CronetUrlRequest extends UrlRequestBase { |
| 51 private static final RequestFinishedInfo.Metrics EMPTY_METRICS = | 50 private static final RequestFinishedInfo.Metrics EMPTY_METRICS = |
| 52 new RequestFinishedInfo.Metrics(null, null, null, null); | 51 new RequestFinishedInfo.Metrics(null, null, null, null); |
| 53 private final boolean mAllowDirectExecutor; | 52 private final boolean mAllowDirectExecutor; |
| 54 | 53 |
| 55 /* Native adapter object, owned by UrlRequest. */ | 54 /* Native adapter object, owned by UrlRequest. */ |
| 56 @GuardedBy("mUrlRequestAdapterLock") | 55 @GuardedBy("mUrlRequestAdapterLock") |
| 57 private long mUrlRequestAdapter; | 56 private long mUrlRequestAdapter; |
| 58 | 57 |
| 59 @GuardedBy("mUrlRequestAdapterLock") | 58 @GuardedBy("mUrlRequestAdapterLock") |
| 60 private boolean mStarted = false; | 59 private boolean mStarted = false; |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 /** | 685 /** |
| 687 * Called by the native code when request status is fetched from the | 686 * Called by the native code when request status is fetched from the |
| 688 * native stack. | 687 * native stack. |
| 689 */ | 688 */ |
| 690 @SuppressWarnings("unused") | 689 @SuppressWarnings("unused") |
| 691 @CalledByNative | 690 @CalledByNative |
| 692 private void onStatus(final UrlRequest.StatusListener listener, final int lo
adState) { | 691 private void onStatus(final UrlRequest.StatusListener listener, final int lo
adState) { |
| 693 Runnable task = new Runnable() { | 692 Runnable task = new Runnable() { |
| 694 @Override | 693 @Override |
| 695 public void run() { | 694 public void run() { |
| 696 listener.onStatus(UrlRequest.Status.convertLoadState(loadState))
; | 695 listener.onStatus(UrlRequestBase.Status.convertLoadState(loadSta
te)); |
| 697 } | 696 } |
| 698 }; | 697 }; |
| 699 postTaskToExecutor(task); | 698 postTaskToExecutor(task); |
| 700 } | 699 } |
| 701 | 700 |
| 702 RequestFinishedInfo getRequestFinishedInfo() { | 701 RequestFinishedInfo getRequestFinishedInfo() { |
| 703 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, | 702 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, |
| 704 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator
.getRequestMetrics() | 703 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator
.getRequestMetrics() |
| 705 : EMPTY_METRICS), | 704 : EMPTY_METRICS), |
| 706 mResponseInfo); | 705 mResponseInfo); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 @NativeClassQualifiedName("CronetURLRequestAdapter") | 766 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 768 private native boolean nativeReadData( | 767 private native boolean nativeReadData( |
| 769 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); | 768 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); |
| 770 | 769 |
| 771 @NativeClassQualifiedName("CronetURLRequestAdapter") | 770 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 772 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 771 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 773 | 772 |
| 774 @NativeClassQualifiedName("CronetURLRequestAdapter") | 773 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 775 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); | 774 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); |
| 776 } | 775 } |
| OLD | NEW |