Commit 33594f79 authored by David Maunder's avatar David Maunder Committed by Commit Bot

Move launch type at creation to CriticalPersistedTabData

As part of the effort to move Tab attributes to UserData
objects so Tab doesn't become too big and unwieldy.

Bug: 1112171
Change-Id: I454c2acce385da7953c2f91bc5411a70cacc6dd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347958
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797528}
parent cb0e4af9
......@@ -129,13 +129,6 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
*/
private final @Nullable @TabLaunchType Integer mLaunchType;
/**
* Saves how this tab was initially launched so that we can record metrics on how the
* tab was created. This is different than {@code mLaunchType}, since {@code mLaunchType} will
* be overridden to "FROM_RESTORE" during tab restoration.
*/
private @Nullable @TabLaunchType Integer mLaunchTypeAtCreation;
private @Nullable @TabCreationState Integer mCreationState;
/**
......@@ -406,11 +399,6 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
return mLaunchType;
}
@Override
public @Nullable @TabLaunchType Integer getLaunchTypeAtInitialTabCreation() {
return mLaunchTypeAtCreation;
}
@Override
public boolean isIncognito() {
return mIncognito;
......@@ -769,7 +757,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
try {
TraceEvent.begin("Tab.initialize");
mLaunchTypeAtCreation = mLaunchType;
CriticalPersistedTabData.from(this).setLaunchTypeAtCreation(mLaunchType);
mCreationState = creationState;
mPendingLoadParams = loadUrlParams;
if (loadUrlParams != null) mUrl = new GURL(loadUrlParams.getUrl());
......@@ -837,7 +825,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
mUrl = new GURL(state.contentsState.getVirtualUrlFromState());
CriticalPersistedTabData.from(this).setTitle(
state.contentsState.getDisplayTitleFromState());
mLaunchTypeAtCreation = state.tabLaunchTypeAtCreation;
CriticalPersistedTabData.from(this).setLaunchTypeAtCreation(state.tabLaunchTypeAtCreation);
CriticalPersistedTabData.from(this).setRootId(
state.rootId == Tab.INVALID_TAB_ID ? mId : state.rootId);
}
......
......@@ -26,7 +26,8 @@ public class TabStateExtractor {
tabState.openerAppId = TabAssociatedApp.getAppId(tab);
tabState.parentId = CriticalPersistedTabData.from(tab).getParentId();
tabState.timestampMillis = CriticalPersistedTabData.from(tab).getTimestampMillis();
tabState.tabLaunchTypeAtCreation = tab.getLaunchTypeAtInitialTabCreation();
tabState.tabLaunchTypeAtCreation =
CriticalPersistedTabData.from(tab).getTabLaunchTypeAtCreation();
// Don't save the actual default theme color because it could change on night mode state
// changed.
tabState.themeColor = TabThemeColorHelper.isUsingColorFromTabContents(tab)
......
......@@ -65,7 +65,8 @@ public class TasksUma {
if (totalTabCount == 0) return;
for (int i = 0; i < totalTabCount; i++) {
Integer tabLaunchType = model.getTabAt(i).getLaunchTypeAtInitialTabCreation();
Integer tabLaunchType =
CriticalPersistedTabData.from(model.getTabAt(i)).getTabLaunchTypeAtCreation();
if (tabLaunchType == null) {
// This should not happen. Because @{link Tab#TabLaunchType} is never null, except
// for testing purpose or in the document-mode which it's deprecated.
......
......@@ -43,7 +43,7 @@ public class CriticalPersistedTabDataTest {
private static final String APP_ID = "AppId";
private static final String OPENER_APP_ID = "OpenerAppId";
private static final int THEME_COLOR = 5;
private static final int LAUNCH_TYPE_AT_CREATION = 3;
private static final Integer LAUNCH_TYPE_AT_CREATION = 3;
static {
WEB_CONTENTS_STATE.buffer().put(WEB_CONTENTS_STATE_BYTES);
......
......@@ -156,14 +156,6 @@ public interface Tab extends TabLifecycle {
@TabLaunchType
int getLaunchType();
/**
* @return The reason the Tab was launched. This remains unchanged, while {@link
* #getLaunchType()} can change over time.
*/
@Nullable
@TabLaunchType
Integer getLaunchTypeAtInitialTabCreation();
/**
* @return {@code true} if the Tab is in incognito mode.
*/
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tab.state;
import android.graphics.Color;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.protobuf.ByteString;
......@@ -50,7 +51,12 @@ public class CriticalPersistedTabData extends PersistedTabData {
private int mContentStateVersion;
private String mOpenerAppId;
private int mThemeColor;
private @TabLaunchType Integer mTabLaunchTypeAtCreation;
/**
* Saves how this tab was initially launched so that we can record metrics on how the
* tab was created. This is different than {@link Tab#getLaunchType()}, since {@link
* Tab#getLaunchType()} will be overridden to "FROM_RESTORE" during tab restoration.
*/
private @Nullable @TabLaunchType Integer mTabLaunchTypeAtCreation;
private ObserverList<CriticalPersistedTabDataObserver> mObservers =
new ObserverList<CriticalPersistedTabDataObserver>();
......@@ -79,7 +85,7 @@ public class CriticalPersistedTabData extends PersistedTabData {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
CriticalPersistedTabData(Tab tab, int parentId, int rootId, long timestampMillis,
WebContentsState webContentsState, int contentStateVersion, String openerAppId,
int themeColor, int launchTypeAtCreation) {
int themeColor, @Nullable @TabLaunchType Integer launchTypeAtCreation) {
this(tab);
mParentId = parentId;
mRootId = rootId;
......@@ -142,10 +148,7 @@ public class CriticalPersistedTabData extends PersistedTabData {
// CriticalPersistedTabData is initialized with default values
CriticalPersistedTabData criticalPersistedTabData =
new CriticalPersistedTabData(tab, Tab.INVALID_TAB_ID, tab.getId(),
INVALID_TIMESTAMP, null, -1, "", UNSPECIFIED_THEME_COLOR,
tab.getLaunchTypeAtInitialTabCreation() == null
? TabLaunchType.FROM_LINK
: tab.getLaunchTypeAtInitialTabCreation());
INVALID_TIMESTAMP, null, -1, "", UNSPECIFIED_THEME_COLOR, null);
return criticalPersistedTabData;
}
......@@ -405,10 +408,14 @@ public class CriticalPersistedTabData extends PersistedTabData {
/**
* @return launch type at creation
*/
public @TabLaunchType int getTabLaunchTypeAtCreation() {
public @Nullable @TabLaunchType Integer getTabLaunchTypeAtCreation() {
return mTabLaunchTypeAtCreation;
}
public void setLaunchTypeAtCreation(@Nullable @TabLaunchType Integer launchTypeAtCreation) {
mTabLaunchTypeAtCreation = launchTypeAtCreation;
}
/**
* Add a {@link CriticalPersistedTabDataObserver}
* @param criticalPersistedTabDataObserver the observer
......
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