Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java |
| index eddf53906936b49f3d72276c9073ee662a86d691..cfa1c5bc895cb7e6beb8e7851aa1aa6f87c48b9f 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/AbstractMediaRouteController.java |
| @@ -8,6 +8,7 @@ import android.content.Context; |
| import android.graphics.Bitmap; |
| import android.net.Uri; |
| import android.os.Handler; |
| +import android.os.SystemClock; |
| import android.support.v7.media.MediaControlIntent; |
| import android.support.v7.media.MediaItemStatus; |
| import android.support.v7.media.MediaRouteSelector; |
| @@ -178,6 +179,9 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll |
| private final Set<UiListener> mUiListeners; |
| private boolean mWatchingRouteSelection = false; |
| + private long mMediaElementAttachedTimestampMs = 0; |
| + private long mMediaElementDetachedTimestampMs = 0; |
| + |
| protected AbstractMediaRouteController() { |
| mDebug = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_CAST_DEBUG_LOGS); |
| @@ -394,6 +398,29 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll |
| startWatchingRouteSelection(); |
| } |
| + @Override |
| + public void release() { |
| + long remotePlaybackStoppedTimestampMs = SystemClock.uptimeMillis(); |
| + |
| + // There was no media element ever... |
| + if (mMediaElementAttachedTimestampMs == 0) return; |
| + |
| + long remotePlaybackIntervalMs = |
| + remotePlaybackStoppedTimestampMs - mMediaElementAttachedTimestampMs; |
| + |
| + if (mMediaElementDetachedTimestampMs == 0) { |
| + mMediaElementDetachedTimestampMs = remotePlaybackStoppedTimestampMs; |
| + } |
| + |
| + int noElementRemotePlaybackTimePercentage = |
| + (int) ((remotePlaybackStoppedTimestampMs - mMediaElementDetachedTimestampMs) * 100 |
| + / remotePlaybackIntervalMs); |
| + RecordCastAction.recordRemotePlaybackTimeWithoutMediaElementPercentage( |
| + noElementRemotePlaybackTimePercentage); |
| + mMediaElementAttachedTimestampMs = 0; |
| + mMediaElementDetachedTimestampMs = 0; |
| + } |
| + |
| protected final void registerRoute(RouteInfo route) { |
| mCurrentRoute = route; |
| @@ -440,6 +467,12 @@ public abstract class AbstractMediaRouteController implements MediaRouteControll |
| @Override |
| public void setMediaStateListener(MediaStateListener mediaStateListener) { |
|
aberent
2016/02/04 16:44:25
I am not sure about the sequencing of setMediaStat
|
| + if (mMediaStateListener != null && mediaStateListener == null) { |
| + mMediaElementDetachedTimestampMs = SystemClock.uptimeMillis(); |
| + } else if (mMediaStateListener == null && mediaStateListener != null) { |
| + mMediaElementAttachedTimestampMs = SystemClock.uptimeMillis(); |
| + } |
| + |
| mMediaStateListener = mediaStateListener; |
| } |