Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.net.impl; | |
| 6 | |
| 7 import android.support.annotation.Nullable; | |
| 8 | |
| 9 import org.chromium.base.VisibleForTesting; | |
| 10 import org.chromium.net.RequestFinishedInfo; | |
| 11 | |
| 12 import java.util.Date; | |
| 13 | |
| 14 /** | |
| 15 * Implementation of RequestFinishedInfo.Metrics | |
|
xunjieli
2016/09/05 23:24:17
nit: Add a {@link} and a period at the end of the
mgersh
2016/09/07 22:09:58
Done.
| |
| 16 */ | |
| 17 @VisibleForTesting | |
| 18 public final class CronetMetrics extends RequestFinishedInfo.Metrics { | |
| 19 private final long mRequestStartMs; | |
| 20 private final long mDnsStartMs; | |
| 21 private final long mDnsEndMs; | |
| 22 private final long mConnectStartMs; | |
| 23 private final long mConnectEndMs; | |
| 24 private final long mSslStartMs; | |
| 25 private final long mSslEndMs; | |
| 26 private final long mSendingStartMs; | |
| 27 private final long mSendingEndMs; | |
| 28 private final long mPushStartMs; | |
| 29 private final long mPushEndMs; | |
| 30 private final long mResponseStartMs; | |
| 31 private final long mResponseEndMs; | |
| 32 private final boolean mSocketReused; | |
| 33 | |
| 34 // TODO(mgersh): Delete once we switch to the new API http://crbug.com/62919 4 | |
|
mef
2016/09/07 21:10:50
nit: s/once we/after/g
mgersh
2016/09/07 22:09:58
Done, but could you explain why? Is first person d
| |
| 35 @Nullable | |
| 36 private final Long mTtfbMs; | |
| 37 // TODO(mgersh): Delete once we switch to the new API http://crbug.com/62919 4 | |
| 38 @Nullable | |
| 39 private final Long mTotalTimeMs; | |
| 40 @Nullable | |
| 41 private final Long mSentBytesCount; | |
| 42 @Nullable | |
| 43 private final Long mReceivedBytesCount; | |
| 44 | |
| 45 @Nullable | |
| 46 private static Date toDate(long timestamp) { | |
| 47 if (timestamp != 0) { | |
| 48 return new Date(timestamp); | |
| 49 } | |
| 50 return null; | |
| 51 } | |
| 52 | |
| 53 /** | |
| 54 * Old-style constructor | |
| 55 * TODO(mgersh): Delete once we switch to the new API http://crbug.com/62919 4 | |
| 56 */ | |
| 57 public CronetMetrics(@Nullable Long ttfbMs, @Nullable Long totalTimeMs, | |
| 58 @Nullable Long sentBytesCount, @Nullable Long receivedBytesCount) { | |
| 59 mTtfbMs = ttfbMs; | |
| 60 mTotalTimeMs = totalTimeMs; | |
| 61 mSentBytesCount = sentBytesCount; | |
| 62 mReceivedBytesCount = receivedBytesCount; | |
| 63 | |
| 64 // Everything else is 0 for now | |
|
xunjieli
2016/09/05 23:24:17
Should the null case be -1 instead of 0? See my ot
mgersh
2016/09/07 22:09:58
Done.
| |
| 65 mRequestStartMs = 0; | |
| 66 mDnsStartMs = 0; | |
| 67 mDnsEndMs = 0; | |
| 68 mConnectStartMs = 0; | |
| 69 mConnectEndMs = 0; | |
| 70 mSslStartMs = 0; | |
| 71 mSslEndMs = 0; | |
| 72 mSendingStartMs = 0; | |
| 73 mSendingEndMs = 0; | |
| 74 mPushStartMs = 0; | |
| 75 mPushEndMs = 0; | |
| 76 mResponseStartMs = 0; | |
| 77 mResponseEndMs = 0; | |
| 78 mSocketReused = false; | |
| 79 } | |
| 80 | |
| 81 /** | |
| 82 * New-style constructor | |
| 83 */ | |
| 84 public CronetMetrics(long requestStartMs, long dnsStartMs, long dnsEndMs, lo ng connectStartMs, | |
| 85 long connectEndMs, long sslStartMs, long sslEndMs, long sendingStart Ms, | |
| 86 long sendingEndMs, long pushStartMs, long pushEndMs, long responseSt artMs, | |
| 87 long responseEndMs, boolean socketReused, long sentBytesCount, | |
| 88 long receivedBytesCount) { | |
| 89 // Check that no end times are before corresponding start times | |
| 90 // Case where end time is 0 is needed in case request fails/errors befor e end | |
| 91 assert dnsEndMs >= dnsStartMs || dnsEndMs == 0; | |
| 92 assert connectEndMs >= connectStartMs || connectEndMs == 0; | |
| 93 assert sslEndMs >= sslStartMs || sslEndMs == 0; | |
| 94 assert sendingEndMs >= sendingStartMs || sendingEndMs == 0; | |
| 95 assert pushEndMs >= pushStartMs || pushEndMs == 0; | |
| 96 assert responseEndMs >= responseStartMs || responseEndMs == 0; | |
| 97 // Spot-check some of the other orderings | |
| 98 assert dnsStartMs >= requestStartMs || dnsStartMs == 0; | |
| 99 assert sendingStartMs >= requestStartMs || sendingStartMs == 0; | |
| 100 assert sslStartMs >= connectStartMs || sslStartMs == 0; | |
| 101 assert connectEndMs >= sslEndMs || connectEndMs == 0; | |
| 102 assert sendingStartMs >= connectEndMs || sendingStartMs == 0; | |
| 103 assert responseStartMs >= sendingStartMs || responseStartMs == 0; | |
| 104 mRequestStartMs = requestStartMs; | |
| 105 mDnsStartMs = dnsStartMs; | |
| 106 mDnsEndMs = dnsEndMs; | |
| 107 mConnectStartMs = connectStartMs; | |
| 108 mConnectEndMs = connectEndMs; | |
| 109 mSslStartMs = sslStartMs; | |
| 110 mSslEndMs = sslEndMs; | |
| 111 mSendingStartMs = sendingStartMs; | |
| 112 mSendingEndMs = sendingEndMs; | |
| 113 mPushStartMs = pushStartMs; | |
| 114 mPushEndMs = pushEndMs; | |
| 115 mResponseStartMs = responseStartMs; | |
| 116 mResponseEndMs = responseEndMs; | |
| 117 mSocketReused = socketReused; | |
| 118 mSentBytesCount = sentBytesCount; | |
| 119 mReceivedBytesCount = receivedBytesCount; | |
| 120 | |
| 121 // Don't care about these anymore | |
| 122 mTtfbMs = null; | |
| 123 mTotalTimeMs = null; | |
| 124 } | |
| 125 | |
| 126 @Nullable | |
| 127 public Date getRequestStart() { | |
| 128 return toDate(mRequestStartMs); | |
| 129 } | |
| 130 | |
| 131 @Nullable | |
| 132 public Date getDnsStart() { | |
| 133 return toDate(mDnsStartMs); | |
| 134 } | |
| 135 | |
| 136 @Nullable | |
| 137 public Date getDnsEnd() { | |
| 138 return toDate(mDnsEndMs); | |
| 139 } | |
| 140 | |
| 141 @Nullable | |
| 142 public Date getConnectStart() { | |
| 143 return toDate(mConnectStartMs); | |
| 144 } | |
| 145 | |
| 146 @Nullable | |
| 147 public Date getConnectEnd() { | |
| 148 return toDate(mConnectEndMs); | |
| 149 } | |
| 150 | |
| 151 @Nullable | |
| 152 public Date getSslStart() { | |
| 153 return toDate(mSslStartMs); | |
| 154 } | |
| 155 | |
| 156 @Nullable | |
| 157 public Date getSslEnd() { | |
| 158 return toDate(mSslEndMs); | |
| 159 } | |
| 160 | |
| 161 @Nullable | |
| 162 public Date getSendingStart() { | |
| 163 return toDate(mSendingStartMs); | |
| 164 } | |
| 165 | |
| 166 @Nullable | |
| 167 public Date getSendingEnd() { | |
| 168 return toDate(mSendingEndMs); | |
| 169 } | |
| 170 | |
| 171 @Nullable | |
| 172 public Date getPushStart() { | |
| 173 return toDate(mPushStartMs); | |
| 174 } | |
| 175 | |
| 176 @Nullable | |
| 177 public Date getPushEnd() { | |
| 178 return toDate(mPushEndMs); | |
| 179 } | |
| 180 | |
| 181 @Nullable | |
| 182 public Date getResponseStart() { | |
| 183 return toDate(mResponseStartMs); | |
| 184 } | |
| 185 | |
| 186 @Nullable | |
| 187 public Date getResponseEnd() { | |
| 188 return toDate(mResponseEndMs); | |
| 189 } | |
| 190 | |
| 191 @Nullable | |
| 192 public boolean getSocketReused() { | |
| 193 return mSocketReused; | |
| 194 } | |
| 195 | |
| 196 @Nullable | |
| 197 public Long getTtfbMs() { | |
| 198 return mTtfbMs; | |
| 199 } | |
| 200 | |
| 201 @Nullable | |
| 202 public Long getTotalTimeMs() { | |
| 203 return mTotalTimeMs; | |
| 204 } | |
| 205 | |
| 206 @Nullable | |
| 207 public Long getSentBytesCount() { | |
| 208 return mSentBytesCount; | |
| 209 } | |
| 210 | |
| 211 @Nullable | |
| 212 public Long getReceivedBytesCount() { | |
| 213 return mReceivedBytesCount; | |
| 214 } | |
| 215 } | |
| OLD | NEW |