Chromium Code Reviews| Index: blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java |
| diff --git a/blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java b/blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java |
| index d16cbc2703d2178dfc79b1e6ca870fb61721f499..e5c17656459fe9e2210c0d4e84f847bd1958497b 100644 |
| --- a/blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java |
| +++ b/blimp/client/app/android/java/src/org/chromium/blimp/session/BlimpClientSession.java |
| @@ -47,12 +47,29 @@ public class BlimpClientSession { |
| * and their explanations. |
| */ |
| void onDisconnected(String reason); |
| + |
| + /** |
| + * Called to update the debug UI about network statistics for the current web page. |
| + * @param received Number of bytes received. |
| + * @param sent Number of bytes sent. |
| + * @param commit Number of commits completed. |
| + */ |
| + void updateDebugInfo(int received, int sent, int commits); |
| } |
| private final String mAssignerUrl; |
| private final List<ConnectionObserver> mObservers; |
| private long mNativeBlimpClientSessionAndroidPtr; |
| + // Flag indicating whether debug metrics are currently being displayed. |
| + private boolean mStatisticsEnabled = false; |
| + private int mSentOffset; |
| + private int mReceivedOffset; |
|
Kevin M
2016/05/20 01:02:02
Offset => Base?
shaktisahu
2016/05/22 22:36:55
Done.
|
| + private int mCommitsOffset; |
| + private int mSent; |
| + private int mReceived; |
| + private int mCommits; |
| + |
| public BlimpClientSession(String assignerUrl) { |
| mAssignerUrl = assignerUrl; |
| mObservers = new ArrayList<ConnectionObserver>(); |
| @@ -162,7 +179,58 @@ public class BlimpClientSession { |
| return mNativeBlimpClientSessionAndroidPtr; |
| } |
| + /** |
| + * Makes a JNI call to pull the debug metrics which are asynchronously returned on callback |
| + * function updateDebugStats. |
| + */ |
| + public void getDebugStats() { |
| + if (mNativeBlimpClientSessionAndroidPtr == 0) return; |
| + nativeGetDebugInfo(mNativeBlimpClientSessionAndroidPtr); |
| + } |
| + |
| + /** |
| + * Updates the debug metrics on the UI. Since metrics can be turned on/off any time from the UI, |
| + * a snapshot of the metrics is kept the first time it is enabled and on subsequent calls this |
| + * offset is subtracted from the new values to show only the difference. |
| + * @param received Bytes received. |
| + * @param sent Bytes sent. |
| + * @param commits Commits completed. |
| + */ |
| + @CalledByNative |
| + private void updateDebugStats(int received, int sent, int commits) { |
| + mReceived = received; |
| + mSent = sent; |
| + mCommits = commits; |
| + if (!mStatisticsEnabled) { |
| + mReceivedOffset = received; |
|
Kevin M
2016/05/20 01:02:02
We should probably push the offset and resetting f
shaktisahu
2016/05/22 22:36:55
Yes, I am moving it to BlimpRendererActivity to be
|
| + mSentOffset = sent; |
| + mCommitsOffset = commits; |
| + mStatisticsEnabled = true; |
| + } |
| + for (ConnectionObserver observer : mObservers) { |
| + observer.updateDebugInfo( |
| + mReceived - mReceivedOffset, mSent - mSentOffset, mCommits - mCommitsOffset); |
| + } |
| + } |
| + |
| + /** |
| + * Resets the metrics. Currently used for displaying per navigation metrics. |
| + */ |
| + public void resetDebugStats() { |
| + mReceivedOffset = mReceived; |
| + mSentOffset = mSent; |
| + mCommitsOffset = mCommits; |
| + } |
| + |
| + /** |
| + * Indicates that debug UI showing stats is not visible anymore. |
| + */ |
| + public void disableDebugStats() { |
| + mStatisticsEnabled = false; |
|
Kevin M
2016/05/20 01:02:02
What's the use case for statisticsEnabled? If we a
shaktisahu
2016/05/22 22:36:55
Actually this is a flag to the base value of the m
|
| + } |
| + |
| private native long nativeInit(String assignerUrl); |
| private native void nativeConnect(long nativeBlimpClientSessionAndroid, String token); |
| private native void nativeDestroy(long nativeBlimpClientSessionAndroid); |
| + private native void nativeGetDebugInfo(long nativeBlimpClientSessionAndroid); |
| } |