Commit 55f2e3f1 authored by tedchoc's avatar tedchoc Committed by Commit bot

Add a destroy method to the TabModelSelector interface.

This will handle destroying the owned tab models, which will in turn
destroy the owned tabs.

BUG=473594

Review URL: https://codereview.chromium.org/1147153002

Cr-Commit-Position: refs/heads/master@{#330809}
parent 2bcaa68b
...@@ -73,7 +73,7 @@ public class SingleTabModel implements TabModel { ...@@ -73,7 +73,7 @@ public class SingleTabModel implements TabModel {
@Override @Override
public int index() { public int index() {
return 0; return mTab != null ? 0 : INVALID_TAB_INDEX;
} }
@Override @Override
...@@ -129,6 +129,12 @@ public class SingleTabModel implements TabModel { ...@@ -129,6 +129,12 @@ public class SingleTabModel implements TabModel {
assert false; assert false;
} }
@Override
public void destroy() {
if (mTab != null) mTab.destroy();
mTab = null;
}
@Override @Override
public Tab getNextTabIfClosed(int id) { public Tab getNextTabIfClosed(int id) {
return null; return null;
...@@ -175,11 +181,6 @@ public class SingleTabModel implements TabModel { ...@@ -175,11 +181,6 @@ public class SingleTabModel implements TabModel {
mObservers.removeObserver(observer); mObservers.removeObserver(observer);
} }
// Below are functions that are overridden but should be moved out of TabModel.
@Override
public void destroy() {
}
private static native void nativePermanentlyBlockAllNewWindows(Tab nativeTabAndroid); private static native void nativePermanentlyBlockAllNewWindows(Tab nativeTabAndroid);
} }
...@@ -140,6 +140,9 @@ public interface TabModel extends TabList { ...@@ -140,6 +140,9 @@ public interface TabModel extends TabList {
/** /**
* To be called when this model should be destroyed. The model should no longer be used after * To be called when this model should be destroyed. The model should no longer be used after
* this. * this.
*
* <p>
* As a result of this call, all {@link Tab}s owned by this model should be destroyed.
*/ */
public void destroy(); public void destroy();
......
...@@ -158,4 +158,9 @@ public interface TabModelSelector { ...@@ -158,4 +158,9 @@ public interface TabModelSelector {
* @return Whether the tab state for this {@link TabModelSelector} has been initialized. * @return Whether the tab state for this {@link TabModelSelector} has been initialized.
*/ */
boolean isTabStateInitialized(); boolean isTabStateInitialized();
/**
* Destroy all owned {@link TabModel}s and {@link Tab}s referenced by this selector.
*/
void destroy();
} }
...@@ -207,6 +207,11 @@ public abstract class TabModelSelectorBase implements TabModelSelector { ...@@ -207,6 +207,11 @@ public abstract class TabModelSelectorBase implements TabModelSelector {
return mTabStateInitialized; return mTabStateInitialized;
} }
@Override
public void destroy() {
for (int i = 0; i < getModels().size(); i++) getModelAt(i).destroy();
}
/** /**
* Notifies all the listeners that the {@link TabModelSelector} or its {@link TabModel} has * Notifies all the listeners that the {@link TabModelSelector} or its {@link TabModel} has
* changed. * changed.
......
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