Index: chrome/android/java/src/org/chromium/chrome/browser/Tab.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java |
index 210119e5b7e51c010a19befbdfc93746d3929bde..f759426a11af568cfec60cac1fdeabcde75c0e15 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java |
@@ -27,6 +27,7 @@ import org.chromium.base.VisibleForTesting; |
import org.chromium.base.metrics.RecordHistogram; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.TabState.WebContentsState; |
+import org.chromium.chrome.browser.TabUma.TabCreationState; |
import org.chromium.chrome.browser.banners.AppBannerManager; |
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate; |
@@ -46,6 +47,7 @@ import org.chromium.chrome.browser.tab.SadTabViewFactory; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
import org.chromium.chrome.browser.tabmodel.TabModelBase; |
+import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
import org.chromium.chrome.browser.toolbar.ToolbarModel; |
import org.chromium.chrome.browser.ui.toolbar.ToolbarModelSecurityLevel; |
import org.chromium.components.navigation_interception.InterceptNavigationDelegate; |
@@ -297,6 +299,12 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
private int mFullscreenHungRendererToken = FullscreenManager.INVALID_TOKEN; |
/** |
+ * The UMA object used to report stats for this tab. Note that this may be null under certain |
+ * conditions, such as incognito mode. |
+ */ |
+ private TabUma mTabUma; |
+ |
+ /** |
* Reference to the current sadTabView if one is defined. |
*/ |
private View mSadTabView; |
@@ -727,6 +735,14 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
} |
/** |
+ * Sets the mTabUma object for stats reporting. |
+ * @param tabUma TabUma object to use to report UMA stats. |
+ */ |
+ protected void setTabUma(TabUma tabUma) { |
+ mTabUma = tabUma; |
+ } |
+ |
+ /** |
* Restores member fields from the given TabState. |
* @param state TabState containing information about this Tab. |
*/ |
@@ -1206,6 +1222,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
if (mContentViewCore != null) mContentViewCore.onShow(); |
+ if (mTabUma != null) mTabUma.onShow(type, getTimestampMillis()); |
+ |
showInternal(type); |
// If the page is still loading, update the progress bar (otherwise it would not show |
@@ -1459,6 +1477,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
"Navigation.IsMobileOptimized", mContentViewCore.getIsMobileOptimizedHint()); |
} |
+ if (mTabUma != null) mTabUma.onLoadFinished(); |
+ |
for (TabObserver observer : mObservers) observer.onPageLoadFinished(this); |
} |
@@ -1469,6 +1489,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
protected void didFailPageLoad(int errorCode) { |
mIsLoading = false; |
mIsBeingRestored = false; |
+ if (mTabUma != null) mTabUma.onLoadFailed(errorCode); |
for (TabObserver observer : mObservers) observer.onPageLoadFailed(this, errorCode); |
} |
@@ -1838,6 +1859,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
*/ |
protected void restoreIfNeededInternal() { |
mIsBeingRestored = true; |
+ if (mTabUma != null) mTabUma.onRestoreStarted(); |
} |
/** |
@@ -2395,6 +2417,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
* Performs any subclass-specific tasks when the Tab crashes. |
*/ |
protected void handleTabCrash() { |
+ if (mTabUma != null) mTabUma.onRendererCrashed(); |
} |
/** |
@@ -2634,6 +2657,50 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, |
sIdCounter.addAndGet(diff); |
} |
+ /** |
+ * @return the UMA object for the tab. Note that this may be null in some |
+ * cases. |
+ */ |
+ public TabUma getTabUma() { |
+ return mTabUma; |
+ } |
+ |
+ /** |
+ * Creates a new tab to be loaded lazily. This can be used for tabs opened in the background |
+ * that should be loaded when switched to. initialize() needs to be called afterwards to |
+ * complete the second level initialization. |
+ */ |
+ @VisibleForTesting |
+ static Tab createTabForLazyLoad(Context context, boolean incognito, WindowAndroid nativeWindow, |
+ TabLaunchType type, int parentId, LoadUrlParams loadUrlParams, |
+ TabModelSelector tabModelSelector) { |
+ Tab tab = new Tab(INVALID_TAB_ID, parentId, incognito, context, nativeWindow, type, null); |
+ if (context != null) { |
+ tab.setTabUma(new TabUma(tab, TabCreationState.FROZEN_FOR_LAZY_LOAD, |
+ tabModelSelector.getModel(incognito))); |
+ } |
+ tab.setPendingLoadParams(loadUrlParams); |
+ return tab; |
+ } |
+ |
+ /** |
+ * Creates a fresh tab. initialize() needs to be called afterwards to complete the second level |
+ * initialization. |
+ * @param initiallyHidden true iff the tab being created is initially in background |
+ */ |
+ @VisibleForTesting |
+ static Tab createLiveTab(int id, Context context, boolean incognito, WindowAndroid nativeWindow, |
+ TabLaunchType type, int parentId, boolean initiallyHidden, |
+ TabModelSelector tabModelSelector) { |
+ Tab tab = new Tab(id, parentId, incognito, context, nativeWindow, type, null); |
+ if (context != null) { |
+ tab.setTabUma(new TabUma(tab, initiallyHidden ? TabCreationState.LIVE_IN_BACKGROUND |
+ : TabCreationState.LIVE_IN_FOREGROUND, |
+ tabModelSelector.getModel(incognito))); |
+ } |
+ return tab; |
+ } |
+ |
private native void nativeInit(); |
private native void nativeDestroy(long nativeTabAndroid); |
private native void nativeInitWebContents(long nativeTabAndroid, boolean incognito, |