Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java

Issue 2360813003: [Cronet] Pass metrics information from C++ BidirectionalStream to Java (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | components/cronet/android/metrics_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java
diff --git a/components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java b/components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java
index 62a77ec92db4727b3676ea1be9a586fb7c21a6a4..a58774129a83861db5aef6041958b5187b7e74ff 100644
--- a/components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java
+++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetBidirectionalStream.java
@@ -86,6 +86,7 @@ public class CronetBidirectionalStream extends BidirectionalStream {
private final String mRequestHeaders[];
private final boolean mDelayRequestHeadersUntilFirstFlush;
private final Collection<Object> mRequestAnnotations;
+
/*
* Synchronizes access to mNativeStream, mReadState and mWriteState.
*/
@@ -247,7 +248,8 @@ public class CronetBidirectionalStream extends BidirectionalStream {
try {
mNativeStream = nativeCreateBidirectionalStream(
mRequestContext.getUrlRequestContextAdapter(),
- !mDelayRequestHeadersUntilFirstFlush);
+ !mDelayRequestHeadersUntilFirstFlush,
+ mRequestContext.hasRequestFinishedListener());
mRequestContext.onRequestStarted();
// Non-zero startResult means an argument error.
int startResult = nativeStart(mNativeStream, mInitialUrl, mInitialPriority,
@@ -619,6 +621,32 @@ public class CronetBidirectionalStream extends BidirectionalStream {
});
}
+ /**
+ * Called by the native code to report metrics just before the native adapter is destroyed.
+ */
+ @SuppressWarnings("unused")
+ @CalledByNative
+ private void onMetricsCollected(long requestStartMs, long dnsStartMs, long dnsEndMs,
+ long connectStartMs, long connectEndMs, long sslStartMs, long sslEndMs,
+ long sendingStartMs, long sendingEndMs, long pushStartMs, long pushEndMs,
+ long responseStartMs, long responseEndMs, boolean socketReused, long sentBytesCount,
+ long receivedBytesCount) {
+ synchronized (mNativeStreamLock) {
+ if (mMetrics != null) {
+ throw new IllegalStateException("Metrics collection should only happen once.");
+ }
+ mMetrics = new CronetMetrics(requestStartMs, dnsStartMs, dnsEndMs, connectStartMs,
+ connectEndMs, sslStartMs, sslEndMs, sendingStartMs, sendingEndMs, pushStartMs,
+ pushEndMs, responseStartMs, responseEndMs, socketReused, sentBytesCount,
+ receivedBytesCount);
+ // TODO(xunjieli): Fill this with real values.
+ final RequestFinishedInfo requestFinishedInfo =
+ new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mMetrics,
+ RequestFinishedInfo.SUCCEEDED, mResponseInfo, null);
+ mRequestContext.reportFinished(requestFinishedInfo);
+ }
+ }
+
@VisibleForTesting
public void setOnDestroyedCallbackForTesting(Runnable onDestroyedCallbackForTesting) {
mOnDestroyedCallbackForTesting = onDestroyedCallbackForTesting;
@@ -699,7 +727,6 @@ public class CronetBidirectionalStream extends BidirectionalStream {
return;
}
nativeDestroy(mNativeStream, sendOnCanceled);
- mRequestContext.reportFinished(getRequestFinishedInfo());
mRequestContext.onRequestDestroyed();
mNativeStream = 0;
if (mOnDestroyedCallbackForTesting != null) {
@@ -707,12 +734,6 @@ public class CronetBidirectionalStream extends BidirectionalStream {
}
}
- private RequestFinishedInfo getRequestFinishedInfo() {
- // TODO(xunjieli): Fill this with real values.
- return new RequestFinishedInfo(mInitialUrl, mRequestAnnotations, mMetrics,
- RequestFinishedInfo.SUCCEEDED, mResponseInfo, null);
- }
-
/**
* Fails the stream with an exception. Only called on the Executor.
*/
@@ -757,8 +778,8 @@ public class CronetBidirectionalStream extends BidirectionalStream {
}
// Native methods are implemented in cronet_bidirectional_stream_adapter.cc.
- private native long nativeCreateBidirectionalStream(
- long urlRequestContextAdapter, boolean sendRequestHeadersAutomatically);
+ private native long nativeCreateBidirectionalStream(long urlRequestContextAdapter,
+ boolean sendRequestHeadersAutomatically, boolean enableMetricsCollection);
@NativeClassQualifiedName("CronetBidirectionalStreamAdapter")
private native int nativeStart(long nativePtr, String url, int priority, String method,
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | components/cronet/android/metrics_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698