diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java index 6e00e54bf4841..02c6cd3d4b0e7 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java @@ -814,6 +814,15 @@ public void onTabCreated(long time, int tabId, int tabIndex, int sourceTabId, } } + /** + * Called when the TabModelSelector has been initialized with an accurate tab count. + */ + public void onTabStateInitialized() { + for (int i = 0; i < mSceneOverlays.size(); i++) { + mSceneOverlays.get(i).tabStateInitialized(); + } + } + /** * Called when the current tabModel switched (e.g. standard -> incognito). * diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java index c37a9d9038f19..7885266fb69d5 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java @@ -7,6 +7,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; +import android.os.Handler; import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; @@ -30,6 +31,7 @@ import org.chromium.chrome.browser.dom_distiller.ReaderModeManagerDelegate; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.FullscreenManager; +import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.content.browser.SPenSupport; @@ -245,6 +247,8 @@ public void init(TabModelSelector selector, TabCreatorManager creator, mContentContainer = androidContentContainer; if (mNextActiveLayout != null) startShowing(mNextActiveLayout, true); + + updateLayoutForTabModelSelector(); } /** @@ -525,4 +529,30 @@ private int getOrientation() { return Orientation.PORTRAIT; } } + + /** + * Updates the Layout for the state of the {@link TabModelSelector} after initialization. + * If the TabModelSelector is not yet initialized when this function is called, a + * {@link TabModelSelectorObserver} is created to listen for when it is ready. + */ + private void updateLayoutForTabModelSelector() { + if (mTabModelSelector.isTabStateInitialized() && getActiveLayout() != null) { + getActiveLayout().onTabStateInitialized(); + } else { + mTabModelSelector.addObserver(new EmptyTabModelSelectorObserver() { + @Override + public void onTabStateInitialized() { + if (getActiveLayout() != null) getActiveLayout().onTabStateInitialized(); + + final EmptyTabModelSelectorObserver observer = this; + new Handler().post(new Runnable() { + @Override + public void run() { + mTabModelSelector.removeObserver(observer); + } + }); + } + }); + } + } } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java index e1538bfef5487..4054eb1795e1d 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java @@ -64,6 +64,11 @@ SceneOverlayLayer getUpdatedSceneOverlayTree(LayerTitleCache layerTitleCache, */ void tabTitleChanged(int tabId, String title); + /** + * Called when the TabModelSelector has been initialized with an accurate tab count. + */ + void tabStateInitialized(); + /** * Called when the active {@link TabModel} switched (e.g. standard -> incognito). * @param incognito Whether or not the new active model is incognito. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java index 4586b755bf85e..b2f8d46387f72 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java @@ -234,6 +234,11 @@ public boolean updateOverlay(long time, long dt) { return getActiveStripLayoutHelper().updateLayout(time, dt); } + @Override + public void tabStateInitialized() { + updateModelSwitcherButton(); + } + @Override public void tabModelSwitched(boolean incognito) { if (incognito == mIsIncognito) return;