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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java

Issue 1159023005: Log the amount of time that the RecentTabsPage is in the foreground to UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java
index 8eacd730292d755879e5674fd944fc655e258b44..decca493dd0a294fc2bcb188a49eeb58693968b0 100644
--- a/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/RecentTabsPage.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.ntp;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
+import android.os.SystemClock;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
@@ -16,20 +17,27 @@ import android.widget.ExpandableListView;
import com.google.android.apps.chrome.R;
+import org.chromium.base.ActivityState;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.NativePage;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareThumbnailProvider;
import org.chromium.chrome.browser.util.ViewUtils;
+import java.util.concurrent.TimeUnit;
+
/**
* The native recent tabs page. Lists recently closed tabs, open windows and tabs from the user's
* synced devices, and snapshot documents sent from Chrome to Mobile in an expandable list view.
*/
-public class RecentTabsPage implements NativePage,
- ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupCollapseListener,
- ExpandableListView.OnGroupExpandListener, RecentTabsManager.UpdatedCallback,
- View.OnCreateContextMenuListener, InvalidationAwareThumbnailProvider {
-
+public class RecentTabsPage
+ implements NativePage, ApplicationStatus.ActivityStateListener,
+ ExpandableListView.OnChildClickListener,
+ ExpandableListView.OnGroupCollapseListener,
+ ExpandableListView.OnGroupExpandListener, RecentTabsManager.UpdatedCallback,
+ View.OnAttachStateChangeListener, View.OnCreateContextMenuListener,
+ InvalidationAwareThumbnailProvider {
private final Activity mActivity;
private final ExpandableListView mListView;
private final String mTitle;
@@ -45,6 +53,18 @@ public class RecentTabsPage implements NativePage,
private int mSnapshotHeight;
/**
+ * Whether the page is in the foreground and is visible.
+ */
+ private boolean mInForeground;
+
+ /**
+ * The time, whichever is most recent, that the page:
+ * - Moved to the foreground
+ * - Became visible
+ */
+ private long mForegroundTimeMs;
+
+ /**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
@@ -67,6 +87,10 @@ public class RecentTabsPage implements NativePage,
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
+ mView.addOnAttachStateChangeListener(this);
+ ApplicationStatus.registerStateListenerForActivity(this, activity);
+ // {@link #mInForeground} will be updated once the view is attached to the window.
+
onUpdated();
}
@@ -75,6 +99,28 @@ public class RecentTabsPage implements NativePage,
return new RecentTabsRowAdapter(activity, recentTabsManager);
}
+ /**
+ * Updates whether the page is in the foreground based on whether the application is in the
+ * foreground and whether {@link #mView} is attached to the application window. If the page is
+ * no longer in the foreground, records the time that the page spent in the foreground to UMA.
+ * @param isAttachedToWindow whether {@link #mView} is attached to the application window.
+ */
+ private void updateForegroundState(boolean isAttachedToWindow) {
+ boolean inForeground = isAttachedToWindow
+ && ApplicationStatus.getStateForActivity(mActivity) == ActivityState.RESUMED;
+ if (mInForeground == inForeground) {
+ return;
+ }
+
+ mInForeground = inForeground;
+ if (mInForeground) {
+ mForegroundTimeMs = SystemClock.elapsedRealtime();
+ } else {
+ RecordHistogram.recordTimesHistogram("NewTabPage.RecentTabsPage.TimeVisibleAndroid",
+ SystemClock.elapsedRealtime() - mForegroundTimeMs, TimeUnit.MILLISECONDS);
+ }
+ }
+
// NativePage overrides
@Override
@@ -110,12 +156,40 @@ public class RecentTabsPage implements NativePage,
mAdapter.notifyDataSetInvalidated();
mAdapter = null;
mListView.setAdapter((RecentTabsRowAdapter) null);
+
+ mView.removeOnAttachStateChangeListener(this);
+ ApplicationStatus.unregisterActivityStateListener(this);
}
@Override
public void updateForUrl(String url) {
}
+ // ApplicationStatus.ActivityStateListener
+ @Override
+ public void onActivityStateChange(Activity activity, int state) {
+ // Called when the user locks the screen or moves Chrome to the background via the task
+ // switcher.
+ updateForegroundState(mView.isAttachedToWindow());
+ }
+
+ // View.OnAttachStateChangeListener
+ @Override
+ public void onViewAttachedToWindow(View view) {
+ // Called when the user opens the RecentTabsPage or switches back to the RecentTabsPage from
+ // another tab.
+ updateForegroundState(true);
+ }
+
+ @Override
+ public void onViewDetachedFromWindow(View view) {
+ // Called when the user navigates from the RecentTabsPage or switches to another tab.
+ // The value of {@link View#isAttachedToWindow()} changes after the
+ // {@link View.OnAttachStateChangeListener#onViewDetachedFromWindow()} listeners are
+ // notified.
+ updateForegroundState(false);
+ }
+
// ExpandableListView.OnChildClickedListener
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698