| 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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 * callback native request adapter is called on executive thread and posts | 41 * callback native request adapter is called on executive thread and posts |
| 42 * 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 |
| 43 * any thread it is protected by mUrlRequestAdapterLock. | 43 * any thread it is protected by mUrlRequestAdapterLock. |
| 44 */ | 44 */ |
| 45 @JNINamespace("cronet") | 45 @JNINamespace("cronet") |
| 46 // Qualifies UrlRequest.StatusListener which is used in onStatus, a JNI method. | 46 // Qualifies UrlRequest.StatusListener which is used in onStatus, a JNI method. |
| 47 @JNIAdditionalImport(UrlRequest.class) | 47 @JNIAdditionalImport(UrlRequest.class) |
| 48 @VisibleForTesting | 48 @VisibleForTesting |
| 49 public final class CronetUrlRequest implements UrlRequest { | 49 public final class CronetUrlRequest implements UrlRequest { |
| 50 private static final RequestFinishedInfo.Metrics EMPTY_METRICS = | 50 private static final RequestFinishedInfo.Metrics EMPTY_METRICS = |
| 51 new RequestFinishedInfo.Metrics(null, null, null, null); | 51 new CronetMetrics(null, null, null, null); |
| 52 | 52 |
| 53 /* Native adapter object, owned by UrlRequest. */ | 53 /* Native adapter object, owned by UrlRequest. */ |
| 54 @GuardedBy("mUrlRequestAdapterLock") | 54 @GuardedBy("mUrlRequestAdapterLock") |
| 55 private long mUrlRequestAdapter; | 55 private long mUrlRequestAdapter; |
| 56 | 56 |
| 57 @GuardedBy("mUrlRequestAdapterLock") | 57 @GuardedBy("mUrlRequestAdapterLock") |
| 58 private boolean mStarted = false; | 58 private boolean mStarted = false; |
| 59 @GuardedBy("mUrlRequestAdapterLock") | 59 @GuardedBy("mUrlRequestAdapterLock") |
| 60 private boolean mWaitingOnRedirect = false; | 60 private boolean mWaitingOnRedirect = false; |
| 61 @GuardedBy("mUrlRequestAdapterLock") | 61 @GuardedBy("mUrlRequestAdapterLock") |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 Runnable task = new Runnable() { | 689 Runnable task = new Runnable() { |
| 690 @Override | 690 @Override |
| 691 public void run() { | 691 public void run() { |
| 692 listener.onStatus(UrlRequest.Status.convertLoadState(loadState))
; | 692 listener.onStatus(UrlRequest.Status.convertLoadState(loadState))
; |
| 693 } | 693 } |
| 694 }; | 694 }; |
| 695 postTaskToExecutor(task); | 695 postTaskToExecutor(task); |
| 696 } | 696 } |
| 697 | 697 |
| 698 RequestFinishedInfo getRequestFinishedInfo() { | 698 RequestFinishedInfo getRequestFinishedInfo() { |
| 699 // TODO(mgersh): fill in real values for finishedReason and exception |
| 699 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, | 700 return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, |
| 700 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator
.getRequestMetrics() | 701 (mRequestMetricsAccumulator != null ? mRequestMetricsAccumulator
.getRequestMetrics() |
| 701 : EMPTY_METRICS), | 702 : EMPTY_METRICS), |
| 702 mResponseInfo); | 703 RequestFinishedInfo.SUCCEEDED, mResponseInfo, null); |
| 703 } | 704 } |
| 704 | 705 |
| 705 private final class UrlRequestMetricsAccumulator { | 706 private final class UrlRequestMetricsAccumulator { |
| 706 @Nullable | 707 @Nullable |
| 707 private Long mRequestStartTime; | 708 private Long mRequestStartTime; |
| 708 @Nullable | 709 @Nullable |
| 709 private Long mTtfbMs; | 710 private Long mTtfbMs; |
| 710 @Nullable | 711 @Nullable |
| 711 private Long mTotalTimeMs; | 712 private Long mTotalTimeMs; |
| 712 | 713 |
| 713 private RequestFinishedInfo.Metrics getRequestMetrics() { | 714 private RequestFinishedInfo.Metrics getRequestMetrics() { |
| 714 return new RequestFinishedInfo.Metrics(mTtfbMs, mTotalTimeMs, | 715 return new CronetMetrics(mTtfbMs, mTotalTimeMs, |
| 715 null, // TODO(klm): Compute sentBytesCount. | 716 null, // TODO(klm): Compute sentBytesCount. |
| 716 (mResponseInfo != null ? mResponseInfo.getReceivedBytesCount
() : 0)); | 717 (mResponseInfo != null ? mResponseInfo.getReceivedBytesCount
() : 0)); |
| 717 } | 718 } |
| 718 | 719 |
| 719 private void onRequestStarted() { | 720 private void onRequestStarted() { |
| 720 if (mRequestStartTime != null) { | 721 if (mRequestStartTime != null) { |
| 721 throw new IllegalStateException("onRequestStarted called repeate
dly"); | 722 throw new IllegalStateException("onRequestStarted called repeate
dly"); |
| 722 } | 723 } |
| 723 mRequestStartTime = SystemClock.elapsedRealtime(); | 724 mRequestStartTime = SystemClock.elapsedRealtime(); |
| 724 } | 725 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 @NativeClassQualifiedName("CronetURLRequestAdapter") | 757 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 757 private native boolean nativeReadData( | 758 private native boolean nativeReadData( |
| 758 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); | 759 long nativePtr, ByteBuffer byteBuffer, int position, int capacity); |
| 759 | 760 |
| 760 @NativeClassQualifiedName("CronetURLRequestAdapter") | 761 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 761 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); | 762 private native void nativeDestroy(long nativePtr, boolean sendOnCanceled); |
| 762 | 763 |
| 763 @NativeClassQualifiedName("CronetURLRequestAdapter") | 764 @NativeClassQualifiedName("CronetURLRequestAdapter") |
| 764 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); | 765 private native void nativeGetStatus(long nativePtr, UrlRequest.StatusListene
r listener); |
| 765 } | 766 } |
| OLD | NEW |