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