Commit 7810c370 authored by yusufo's avatar yusufo Committed by Commit bot

[CCT-Reparenting] Remove tab observer when the tab is removed from model

In tab reparenting, we never close but only remove the tab from the
model. During this process, both tab observer and also the metrics
observer was still kept, which leaked over some custom tab features into
the tab even after it was reparented. This removes the observers and
fixes the related issues.

TEST=CustomTabActivityTest#testTabReparentingBasic
BUG=669169

Review-Url: https://codereview.chromium.org/2539643002
Cr-Commit-Position: refs/heads/master@{#435028}
parent 22d06b0c
......@@ -176,6 +176,12 @@ public class CustomTabActivity extends ChromeActivity {
// Finish the activity after we intent out.
if (getTabModelSelector().getCurrentModel().getCount() == 0) finishAndClose(false);
}
@Override
public void tabRemoved(Tab tab) {
tab.removeObserver(mTabObserver);
PageLoadMetrics.removeObserver(mMetricsObserver);
}
};
/**
......
......@@ -41,6 +41,7 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import org.chromium.base.ObserverList.RewindableIterator;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
......@@ -65,6 +66,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabTestUtils;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
......@@ -1726,6 +1728,10 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
assertEquals("The tab should never be hidden during the reparenting process",
0, tabHiddenHelper.getCallCount());
tabToBeReparented.removeObserver(observer);
RewindableIterator<TabObserver> observers = TabTestUtils.getTabObservers(tabToBeReparented);
while (observers.hasNext()) {
assertFalse(observers.next() instanceof CustomTabObserver);
}
return newActivity;
}
......
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