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 { ...@@ -129,13 +129,6 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
*/ */
private final @Nullable @TabLaunchType Integer mLaunchType; 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; private @Nullable @TabCreationState Integer mCreationState;
/** /**
...@@ -406,11 +399,6 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer { ...@@ -406,11 +399,6 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
return mLaunchType; return mLaunchType;
} }
@Override
public @Nullable @TabLaunchType Integer getLaunchTypeAtInitialTabCreation() {
return mLaunchTypeAtCreation;
}
@Override @Override
public boolean isIncognito() { public boolean isIncognito() {
return mIncognito; return mIncognito;
...@@ -769,7 +757,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer { ...@@ -769,7 +757,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
try { try {
TraceEvent.begin("Tab.initialize"); TraceEvent.begin("Tab.initialize");
mLaunchTypeAtCreation = mLaunchType; CriticalPersistedTabData.from(this).setLaunchTypeAtCreation(mLaunchType);
mCreationState = creationState; mCreationState = creationState;
mPendingLoadParams = loadUrlParams; mPendingLoadParams = loadUrlParams;
if (loadUrlParams != null) mUrl = new GURL(loadUrlParams.getUrl()); if (loadUrlParams != null) mUrl = new GURL(loadUrlParams.getUrl());
...@@ -837,7 +825,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer { ...@@ -837,7 +825,7 @@ public class TabImpl implements Tab, TabObscuringHandler.Observer {
mUrl = new GURL(state.contentsState.getVirtualUrlFromState()); mUrl = new GURL(state.contentsState.getVirtualUrlFromState());
CriticalPersistedTabData.from(this).setTitle( CriticalPersistedTabData.from(this).setTitle(
state.contentsState.getDisplayTitleFromState()); state.contentsState.getDisplayTitleFromState());
mLaunchTypeAtCreation = state.tabLaunchTypeAtCreation; CriticalPersistedTabData.from(this).setLaunchTypeAtCreation(state.tabLaunchTypeAtCreation);
CriticalPersistedTabData.from(this).setRootId( CriticalPersistedTabData.from(this).setRootId(
state.rootId == Tab.INVALID_TAB_ID ? mId : state.rootId); state.rootId == Tab.INVALID_TAB_ID ? mId : state.rootId);
} }
......
...@@ -26,7 +26,8 @@ public class TabStateExtractor { ...@@ -26,7 +26,8 @@ public class TabStateExtractor {
tabState.openerAppId = TabAssociatedApp.getAppId(tab); tabState.openerAppId = TabAssociatedApp.getAppId(tab);
tabState.parentId = CriticalPersistedTabData.from(tab).getParentId(); tabState.parentId = CriticalPersistedTabData.from(tab).getParentId();
tabState.timestampMillis = CriticalPersistedTabData.from(tab).getTimestampMillis(); 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 // Don't save the actual default theme color because it could change on night mode state
// changed. // changed.
tabState.themeColor = TabThemeColorHelper.isUsingColorFromTabContents(tab) tabState.themeColor = TabThemeColorHelper.isUsingColorFromTabContents(tab)
......
...@@ -65,7 +65,8 @@ public class TasksUma { ...@@ -65,7 +65,8 @@ public class TasksUma {
if (totalTabCount == 0) return; if (totalTabCount == 0) return;
for (int i = 0; i < totalTabCount; i++) { for (int i = 0; i < totalTabCount; i++) {
Integer tabLaunchType = model.getTabAt(i).getLaunchTypeAtInitialTabCreation(); Integer tabLaunchType =
CriticalPersistedTabData.from(model.getTabAt(i)).getTabLaunchTypeAtCreation();
if (tabLaunchType == null) { if (tabLaunchType == null) {
// This should not happen. Because @{link Tab#TabLaunchType} is never null, except // This should not happen. Because @{link Tab#TabLaunchType} is never null, except
// for testing purpose or in the document-mode which it's deprecated. // for testing purpose or in the document-mode which it's deprecated.
......
...@@ -43,7 +43,7 @@ public class CriticalPersistedTabDataTest { ...@@ -43,7 +43,7 @@ public class CriticalPersistedTabDataTest {
private static final String APP_ID = "AppId"; private static final String APP_ID = "AppId";
private static final String OPENER_APP_ID = "OpenerAppId"; private static final String OPENER_APP_ID = "OpenerAppId";
private static final int THEME_COLOR = 5; 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 { static {
WEB_CONTENTS_STATE.buffer().put(WEB_CONTENTS_STATE_BYTES); WEB_CONTENTS_STATE.buffer().put(WEB_CONTENTS_STATE_BYTES);
......
...@@ -156,14 +156,6 @@ public interface Tab extends TabLifecycle { ...@@ -156,14 +156,6 @@ public interface Tab extends TabLifecycle {
@TabLaunchType @TabLaunchType
int getLaunchType(); 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. * @return {@code true} if the Tab is in incognito mode.
*/ */
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tab.state; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tab.state;
import android.graphics.Color; import android.graphics.Color;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
...@@ -50,7 +51,12 @@ public class CriticalPersistedTabData extends PersistedTabData { ...@@ -50,7 +51,12 @@ public class CriticalPersistedTabData extends PersistedTabData {
private int mContentStateVersion; private int mContentStateVersion;
private String mOpenerAppId; private String mOpenerAppId;
private int mThemeColor; 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 = private ObserverList<CriticalPersistedTabDataObserver> mObservers =
new ObserverList<CriticalPersistedTabDataObserver>(); new ObserverList<CriticalPersistedTabDataObserver>();
...@@ -79,7 +85,7 @@ public class CriticalPersistedTabData extends PersistedTabData { ...@@ -79,7 +85,7 @@ public class CriticalPersistedTabData extends PersistedTabData {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
CriticalPersistedTabData(Tab tab, int parentId, int rootId, long timestampMillis, CriticalPersistedTabData(Tab tab, int parentId, int rootId, long timestampMillis,
WebContentsState webContentsState, int contentStateVersion, String openerAppId, WebContentsState webContentsState, int contentStateVersion, String openerAppId,
int themeColor, int launchTypeAtCreation) { int themeColor, @Nullable @TabLaunchType Integer launchTypeAtCreation) {
this(tab); this(tab);
mParentId = parentId; mParentId = parentId;
mRootId = rootId; mRootId = rootId;
...@@ -142,10 +148,7 @@ public class CriticalPersistedTabData extends PersistedTabData { ...@@ -142,10 +148,7 @@ public class CriticalPersistedTabData extends PersistedTabData {
// CriticalPersistedTabData is initialized with default values // CriticalPersistedTabData is initialized with default values
CriticalPersistedTabData criticalPersistedTabData = CriticalPersistedTabData criticalPersistedTabData =
new CriticalPersistedTabData(tab, Tab.INVALID_TAB_ID, tab.getId(), new CriticalPersistedTabData(tab, Tab.INVALID_TAB_ID, tab.getId(),
INVALID_TIMESTAMP, null, -1, "", UNSPECIFIED_THEME_COLOR, INVALID_TIMESTAMP, null, -1, "", UNSPECIFIED_THEME_COLOR, null);
tab.getLaunchTypeAtInitialTabCreation() == null
? TabLaunchType.FROM_LINK
: tab.getLaunchTypeAtInitialTabCreation());
return criticalPersistedTabData; return criticalPersistedTabData;
} }
...@@ -405,10 +408,14 @@ public class CriticalPersistedTabData extends PersistedTabData { ...@@ -405,10 +408,14 @@ public class CriticalPersistedTabData extends PersistedTabData {
/** /**
* @return launch type at creation * @return launch type at creation
*/ */
public @TabLaunchType int getTabLaunchTypeAtCreation() { public @Nullable @TabLaunchType Integer getTabLaunchTypeAtCreation() {
return mTabLaunchTypeAtCreation; return mTabLaunchTypeAtCreation;
} }
public void setLaunchTypeAtCreation(@Nullable @TabLaunchType Integer launchTypeAtCreation) {
mTabLaunchTypeAtCreation = launchTypeAtCreation;
}
/** /**
* Add a {@link CriticalPersistedTabDataObserver} * Add a {@link CriticalPersistedTabDataObserver}
* @param criticalPersistedTabDataObserver the observer * @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