Commit b76b8a7c authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Remove logic/class for obsolete UMA histograms for Tab

This CL removes logic/class that handles following obsolete histograms:

Tabs.FirstSwitchedToForegroundCreation*Rank: expires after M77
Tab.BackgroundLoadStatus: expires after M77
Tabs.StateTransfer.Time*: expires after 2017-05-08
Tab.SwitchedToForegroundMRURank: expires after 2014-04-14

Bug: 925242
Change-Id: Ic605626cfe375d1a83938f1e3d1a9cc3b4b26d89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094848Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748939}
parent 20610f18
......@@ -1565,7 +1565,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/sync/ui/PassphraseTypeDialogFragment.java",
"java/src/org/chromium/chrome/browser/tab/AccessibilityVisibilityHandler.java",
"java/src/org/chromium/chrome/browser/tab/AuthenticatorNavigationInterceptor.java",
"java/src/org/chromium/chrome/browser/tab/ChildBackgroundTabShowObserver.java",
"java/src/org/chromium/chrome/browser/tab/EmptyTabObserver.java",
"java/src/org/chromium/chrome/browser/tab/InterceptNavigationDelegateImpl.java",
"java/src/org/chromium/chrome/browser/tab/SadTab.java",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.tab;
import org.chromium.base.metrics.RecordHistogram;
import java.util.ArrayList;
/**
* Observes background tabs opened from the tab with {@link #mParentId}. Records to UMA which of the
* background tabs the user switches to first.
*/
class ChildBackgroundTabShowObserver extends EmptyTabObserver {
/**
* The ID of the parent tab of the background tabs.
*/
private int mParentTabId;
/**
* List of tabs opened from {@link #mParentId} sorted according to their
* creation order. The oldest tab is at index 0.
*/
private final ArrayList<Tab> mTabCreationOrder = new ArrayList<Tab>();
/**
* Creates an instance of {@link ChildBackgroundTabShowObserver}.
* @param parentTabId The id of the parent tab of the background tabs.
*/
public ChildBackgroundTabShowObserver(int parentTabId) {
mParentTabId = parentTabId;
}
/**
* Called when a background tab is opened from {@link #mParentId}.
* @param tab The background tab which was opened.
*/
public void onBackgroundTabOpened(Tab tab) {
assert mParentTabId == tab.getParentId();
mTabCreationOrder.add(tab);
tab.addObserver(this);
}
@Override
public void onShown(Tab tab, @TabSelectionType int type) {
int rank = mTabCreationOrder.indexOf(tab);
int reverseRank = mTabCreationOrder.size() - rank - 1;
// Record which tab the user switches to first by recording the creation order of the tab
// that the user switches to. Record both the "Creation Rank" and the
// "Reverse Creation Rank" because we want to know whether most users switch to the
// newest background tab or oldest background tab first.
RecordHistogram.recordCount100Histogram("Tabs.FirstSwitchedToForegroundCreationRank", rank);
RecordHistogram.recordCount100Histogram(
"Tabs.FirstSwitchedToForegroundCreationReverseRank", reverseRank);
for (Tab stopObservingTab : mTabCreationOrder) {
stopObservingTab.removeObserver(this);
}
mTabCreationOrder.clear();
}
@Override
public void onDestroyed(Tab tab) {
mTabCreationOrder.remove(tab);
}
}
......@@ -10,7 +10,6 @@ import android.text.format.DateUtils;
import org.chromium.base.UserData;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.net.NetError;
......@@ -32,12 +31,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
static final int TAB_STATUS_LAZY_LOAD_FOR_BG_TAB = 8;
static final int TAB_STATUS_LIM = 9;
// TabBackgroundLoadStatus defined in tools/metrics/histograms/histograms.xml.
static final int TAB_BACKGROUND_LOAD_SHOWN = 0;
static final int TAB_BACKGROUND_LOAD_LOST = 1;
static final int TAB_BACKGROUND_LOAD_SKIPPED = 2;
static final int TAB_BACKGROUND_LOAD_LIM = 3;
// The enum values for the Tab.RestoreResult histogram. The unusual order is to
// keep compatibility with the previous instance of the histogram that was using
// a boolean.
......@@ -75,23 +68,15 @@ public class TabUma extends EmptyTabObserver implements UserData {
// "Open in a new tab" from the context menu.
private int mNumBackgroundTabsOpened;
// Records histogram about which background tab opened from this tab the user switches to
// first.
private ChildBackgroundTabShowObserver mChildBackgroundTabShowObserver;
private TabModelSelectorObserver mNewTabObserver;
static TabUma create(Tab tab, @TabCreationState int creationState) {
TabUma tabUma = get(tab);
TabUma tabUma = tab.getUserDataHost().getUserData(USER_DATA_KEY);
if (tabUma != null) tabUma.removeObservers(tab);
return tab.getUserDataHost().setUserData(USER_DATA_KEY, new TabUma(tab, creationState));
}
private static TabUma get(Tab tab) {
return tab.getUserDataHost().getUserData(USER_DATA_KEY);
}
/**
* Constructs a new UMA tracker for a specific tab.
* @param Tab The Tab being monitored for stats.
......@@ -155,14 +140,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
* @param delta Time elapsed from the last state transition in milliseconds.
*/
private void recordTabStateTransition(int prevState, int newState, long delta) {
if (prevState == TAB_STATE_ACTIVE && newState == TAB_STATE_INACTIVE) {
RecordHistogram.recordLongTimesHistogram100(
"Tabs.StateTransfer.Time_Active_Inactive", delta);
} else if (prevState == TAB_STATE_ACTIVE && newState == TAB_STATE_CLOSED) {
RecordHistogram.recordLongTimesHistogram100(
"Tabs.StateTransfer.Time_Active_Closed", delta);
}
if (prevState == TAB_STATE_INITIAL) {
RecordHistogram.recordEnumeratedHistogram("Tabs.StateTransfer.Target_Initial", newState,
TAB_STATE_MAX);
......@@ -185,7 +162,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
"Tab.BackgroundTabsOpenedViaContextMenuCount", mNumBackgroundTabsOpened);
}
mNumBackgroundTabsOpened = 0;
mChildBackgroundTabShowObserver = null;
}
/**
......@@ -202,25 +178,8 @@ public class TabUma extends EmptyTabObserver implements UserData {
mLastTabState = newState;
}
/**
* @return The most recently used rank for this tab in the given TabModel.
*/
private static int computeMRURank(Tab tab, TabModel model) {
final long tabLastShow = get(tab).getLastShownTimestamp();
int mruRank = 0;
for (int i = 0; i < model.getCount(); i++) {
Tab otherTab = model.getTabAt(i);
if (otherTab != tab && TabUma.get(otherTab) != null
&& TabUma.get(otherTab).getLastShownTimestamp() > tabLastShow) {
mruRank++;
}
}
return mruRank;
}
@Override
public void onShown(Tab tab, @TabSelectionType int selectionType) {
int rank = computeMRURank(tab, TabModelSelector.from(tab).getModel(tab.isIncognito()));
long previousTimestampMillis = tab.getTimestampMillis();
long now = SystemClock.elapsedRealtime();
......@@ -230,7 +189,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
if (mLastShownTimestamp != -1 && selectionType == TabSelectionType.FROM_USER) {
long age = now - mLastShownTimestamp;
RecordHistogram.recordCountHistogram("Tab.SwitchedToForegroundAge", (int) age);
RecordHistogram.recordCountHistogram("Tab.SwitchedToForegroundMRURank", rank);
}
increaseTabShowCount();
......@@ -269,27 +227,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
}
if (mLastShownTimestamp == -1) {
// Record Tab.BackgroundLoadStatus.
if (mTabCreationState == TabCreationState.LIVE_IN_BACKGROUND) {
if (mRestoreStartedAtMillis == -1) {
RecordHistogram.recordEnumeratedHistogram("Tab.BackgroundLoadStatus",
TAB_BACKGROUND_LOAD_SHOWN, TAB_BACKGROUND_LOAD_LIM);
} else {
RecordHistogram.recordEnumeratedHistogram("Tab.BackgroundLoadStatus",
TAB_BACKGROUND_LOAD_LOST, TAB_BACKGROUND_LOAD_LIM);
if (previousTimestampMillis > 0) {
RecordHistogram.recordMediumTimesHistogram(
"Tab.LostTabAgeWhenSwitchedToForeground",
System.currentTimeMillis() - previousTimestampMillis);
}
}
} else if (mTabCreationState == TabCreationState.FROZEN_FOR_LAZY_LOAD) {
assert mRestoreStartedAtMillis == -1;
RecordHistogram.recordEnumeratedHistogram("Tab.BackgroundLoadStatus",
TAB_BACKGROUND_LOAD_SKIPPED, TAB_BACKGROUND_LOAD_LIM);
}
// Register the observer for context menu-triggering event here to avoid the case
// where this is created too early and we start missing out on metrics suddenly.
mNewTabObserver = new EmptyTabModelSelectorObserver() {
......@@ -297,7 +234,7 @@ public class TabUma extends EmptyTabObserver implements UserData {
public void onNewTabCreated(Tab newTab, @TabCreationState int creationState) {
if (newTab.getParentId() == tab.getId()
&& newTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND) {
onBackgroundTabOpenedFromContextMenu(newTab);
++mNumBackgroundTabsOpened;
}
}
};
......@@ -307,14 +244,18 @@ public class TabUma extends EmptyTabObserver implements UserData {
// Record "tab age upon first display" metrics. previousTimestampMillis is persisted through
// cold starts.
if (mLastShownTimestamp == -1 && previousTimestampMillis > 0) {
long duration = System.currentTimeMillis() - previousTimestampMillis;
if (mTabCreationState == TabCreationState.LIVE_IN_BACKGROUND
&& mRestoreStartedAtMillis != -1) {
RecordHistogram.recordMediumTimesHistogram(
"Tab.LostTabAgeWhenSwitchedToForeground", duration);
}
if (isOnBrowserStartup) {
RecordHistogram.recordCountHistogram("Tabs.ForegroundTabAgeAtStartup",
(int) ((System.currentTimeMillis() - previousTimestampMillis)
/ DateUtils.MINUTE_IN_MILLIS));
(int) (duration / DateUtils.MINUTE_IN_MILLIS));
} else if (selectionType == TabSelectionType.FROM_USER) {
RecordHistogram.recordCountHistogram("Tab.AgeUponRestoreFromColdStart",
(int) ((System.currentTimeMillis() - previousTimestampMillis)
/ DateUtils.MINUTE_IN_MILLIS));
(int) (duration / DateUtils.MINUTE_IN_MILLIS));
}
}
......@@ -399,28 +340,6 @@ public class TabUma extends EmptyTabObserver implements UserData {
}
}
/**
* Called when a user opens a background tab by long pressing and selecting "Open in a new tab"
* from the context menu.
* @param backgroundTab The background tab.
*/
private void onBackgroundTabOpenedFromContextMenu(Tab backgroundTab) {
++mNumBackgroundTabsOpened;
if (mChildBackgroundTabShowObserver == null) {
mChildBackgroundTabShowObserver =
new ChildBackgroundTabShowObserver(backgroundTab.getParentId());
}
mChildBackgroundTabShowObserver.onBackgroundTabOpened(backgroundTab);
}
/**
* @return The timestamp for when this tab was last shown.
*/
private long getLastShownTimestamp() {
return mLastShownTimestamp;
}
private static void increaseTabShowCount() {
sAllTabsShowCount++;
}
......
......@@ -25,7 +25,6 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.components.browser_ui.util.BrowserControlsVisibilityDelegate;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -103,92 +102,4 @@ public class TabUmaTest {
TestThreadUtils.runOnUiThreadBlocking(() -> { tab.show(TabSelectionType.FROM_USER); });
Assert.assertEquals(1, lazyLoadCount.getDelta());
}
/**
* Verify that Tab.BackgroundLoadStatus is correctly recorded.
*/
@Test
@MediumTest
@Feature({"Uma"})
public void testTabBackgroundLoadStatus() throws ExecutionException {
String histogram = "Tab.BackgroundLoadStatus";
HistogramDelta shownLoadCount =
new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_SHOWN);
HistogramDelta lostLoadCount =
new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_LOST);
HistogramDelta skippedLoadCount =
new HistogramDelta(histogram, TabUma.TAB_BACKGROUND_LOAD_SKIPPED);
Assert.assertEquals(0, shownLoadCount.getDelta());
Assert.assertEquals(0, lostLoadCount.getDelta());
Assert.assertEquals(0, skippedLoadCount.getDelta());
// Test a live tab created in background and shown.
final Tab liveBgTab = TestThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() {
@Override
public Tab call() {
Tab bgTab = TabBuilder.createLiveTab(true)
.setWindow(mActivityTestRule.getActivity().getWindowAndroid())
.setLaunchType(TabLaunchType.FROM_LONGPRESS_BACKGROUND)
.setDelegateFactory(createTabDelegateFactory())
.setInitiallyHidden(true)
.build();
bgTab.loadUrl(new LoadUrlParams(mTestUrl));
bgTab.show(TabSelectionType.FROM_USER);
return bgTab;
}
});
Assert.assertEquals(1, shownLoadCount.getDelta());
Assert.assertEquals(0, lostLoadCount.getDelta());
Assert.assertEquals(0, skippedLoadCount.getDelta());
// Test a live tab killed in background before shown.
final Tab killedBgTab = TestThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() {
@Override
public Tab call() {
Tab bgTab = TabBuilder.createLiveTab(true)
.setWindow(mActivityTestRule.getActivity().getWindowAndroid())
.setLaunchType(TabLaunchType.FROM_LONGPRESS_BACKGROUND)
.setDelegateFactory(createTabDelegateFactory())
.setInitiallyHidden(true)
.build();
bgTab.loadUrl(new LoadUrlParams(mTestUrl));
// Simulate the renderer being killed by the OS.
ChromeTabUtils.simulateRendererKilledForTesting(bgTab, false);
bgTab.show(TabSelectionType.FROM_USER);
return bgTab;
}
});
Assert.assertEquals(1, shownLoadCount.getDelta());
Assert.assertEquals(1, lostLoadCount.getDelta());
Assert.assertEquals(0, skippedLoadCount.getDelta());
// Test a tab created in background but not loaded eagerly.
final Tab frozenBgTab = TestThreadUtils.runOnUiThreadBlocking(new Callable<Tab>() {
@Override
public Tab call() {
Tab bgTab = TabBuilder.createForLazyLoad(new LoadUrlParams(mTestUrl))
.setWindow(mActivityTestRule.getActivity().getWindowAndroid())
.setLaunchType(TabLaunchType.FROM_LONGPRESS_BACKGROUND)
.setDelegateFactory(createTabDelegateFactory())
.setInitiallyHidden(true)
.build();
bgTab.show(TabSelectionType.FROM_USER);
return bgTab;
}
});
Assert.assertEquals(1, shownLoadCount.getDelta());
Assert.assertEquals(1, lostLoadCount.getDelta());
Assert.assertEquals(1, skippedLoadCount.getDelta());
// Show every tab again and make sure we didn't record more samples - this metric should be
// recorded only on first display.
TestThreadUtils.runOnUiThreadBlocking(() -> {
liveBgTab.show(TabSelectionType.FROM_USER);
killedBgTab.show(TabSelectionType.FROM_USER);
frozenBgTab.show(TabSelectionType.FROM_USER);
});
Assert.assertEquals(1, shownLoadCount.getDelta());
Assert.assertEquals(1, lostLoadCount.getDelta());
Assert.assertEquals(1, skippedLoadCount.getDelta());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment