Chromium Code Reviews| 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.CronetEngine.UrlRequestInfo; | |
| 17 import org.chromium.net.CronetEngine.UrlRequestMetrics; | |
| 18 import org.chromium.net.Preconditions; | 16 import org.chromium.net.Preconditions; |
| 19 import org.chromium.net.QuicException; | 17 import org.chromium.net.QuicException; |
| 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; |
| 28 import java.util.ArrayList; | 27 import java.util.ArrayList; |
| 29 import java.util.Collection; | 28 import java.util.Collection; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 implements UrlRequest { |
| 51 private static final UrlRequestMetrics EMPTY_METRICS = | 50 private static final RequestFinishedInfo.Metrics EMPTY_METRICS = |
| 52 new UrlRequestMetrics(null, null, null, null); | 51 new RequestFinishedInfo.Metrics(null, null, null, null); |
| 53 | 52 |
| 54 /* Native adapter object, owned by UrlRequest. */ | 53 /* Native adapter object, owned by UrlRequest. */ |
| 55 @GuardedBy("mUrlRequestAdapterLock") | 54 @GuardedBy("mUrlRequestAdapterLock") |
| 56 private long mUrlRequestAdapter; | 55 private long mUrlRequestAdapter; |
| 57 | 56 |
| 58 @GuardedBy("mUrlRequestAdapterLock") | 57 @GuardedBy("mUrlRequestAdapterLock") |
| 59 private boolean mStarted = false; | 58 private boolean mStarted = false; |
| 60 @GuardedBy("mUrlRequestAdapterLock") | 59 @GuardedBy("mUrlRequestAdapterLock") |
| 61 private boolean mWaitingOnRedirect = false; | 60 private boolean mWaitingOnRedirect = false; |
| 62 @GuardedBy("mUrlRequestAdapterLock") | 61 @GuardedBy("mUrlRequestAdapterLock") |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 private void onStatus(final UrlRequest.StatusListener listener, final int lo adState) { | 688 private void onStatus(final UrlRequest.StatusListener listener, final int lo adState) { |
| 690 Runnable task = new Runnable() { | 689 Runnable task = new Runnable() { |
| 691 @Override | 690 @Override |
| 692 public void run() { | 691 public void run() { |
| 693 listener.onStatus(UrlRequest.Status.convertLoadState(loadState)) ; | 692 listener.onStatus(UrlRequest.Status.convertLoadState(loadState)) ; |
| 694 } | 693 } |
| 695 }; | 694 }; |
| 696 postTaskToExecutor(task); | 695 postTaskToExecutor(task); |
| 697 } | 696 } |
| 698 | 697 |
| 699 UrlRequestInfo getRequestInfo() { | 698 RequestFinishedInfo getRequestInfo() { |
|
xunjieli
2016/08/01 22:14:11
getRequestInfo() -> getRequestFinishedInfo()?
mgersh
2016/08/01 22:33:45
Done.
| |
| 700 return new UrlRequestInfo(mInitialUrl, mRequestAnnotations, | 699 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, |
| 701 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator .getRequestMetrics() | 700 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator .getRequestMetrics() |
| 702 : EMPTY_METRICS), | 701 : EMPTY_METRICS), |
| 703 mResponseInfo); | 702 mResponseInfo); |
|
xunjieli
2016/08/01 22:14:11
not in this CL, but why do we make the RequestFini
mgersh
2016/08/01 22:33:45
It makes it easy to access the information in UrlR
xunjieli
2016/08/01 22:42:48
Acknowledged. You are right. I missed the fact tha
| |
| 704 } | 703 } |
| 705 | 704 |
| 706 private final class UrlRequestMetricsAccumulator { | 705 private final class UrlRequestMetricsAccumulator { |
| 707 @Nullable | 706 @Nullable |
| 708 private Long mRequestStartTime; | 707 private Long mRequestStartTime; |
| 709 @Nullable | 708 @Nullable |
| 710 private Long mTtfbMs; | 709 private Long mTtfbMs; |
| 711 @Nullable | 710 @Nullable |
| 712 private Long mTotalTimeMs; | 711 private Long mTotalTimeMs; |
| 713 | 712 |
| 714 private UrlRequestMetrics getRequestMetrics() { | 713 private RequestFinishedInfo.Metrics getRequestMetrics() { |
| 715 return new UrlRequestMetrics(mTtfbMs, mTotalTimeMs, | 714 return new RequestFinishedInfo.Metrics(mTtfbMs, mTotalTimeMs, |
| 716 null, // TODO(klm): Compute sentBytesCount. | 715 null, // TODO(klm): Compute sentBytesCount. |
| 717 (mResponseInfo != null ? mResponseInfo.getReceivedBytesCount () : 0)); | 716 (mResponseInfo != null ? mResponseInfo.getReceivedBytesCount () : 0)); |
| 718 } | 717 } |
| 719 | 718 |
| 720 private void onRequestStarted() { | 719 private void onRequestStarted() { |
| 721 if (mRequestStartTime != null) { | 720 if (mRequestStartTime != null) { |
| 722 throw new IllegalStateException("onRequestStarted called repeate dly"); | 721 throw new IllegalStateException("onRequestStarted called repeate dly"); |
| 723 } | 722 } |
| 724 mRequestStartTime = SystemClock.elapsedRealtime(); | 723 mRequestStartTime = SystemClock.elapsedRealtime(); |
| 725 } | 724 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 @NativeClassQualifiedName("CronetURLRequestAdapter") | 756 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 758 private native boolean nativeReadData( | 757 private native boolean nativeReadData( |
| 759 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); | 758 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); |
| 760 | 759 |
| 761 @NativeClassQualifiedName("CronetURLRequestAdapter") | 760 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 762 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 761 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 763 | 762 |
| 764 @NativeClassQualifiedName("CronetURLRequestAdapter") | 763 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 765 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); | 764 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene r listener); |
| 766 } | 765 } |
| OLD | NEW |