Commit e343c8c5 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Save tab state after detaching all tabs

This will prevent TabPersistentStore from restoring a tab we're in the
process of reparenting.

Bug: 1042565
Change-Id: I1b7e505c0870e7c6b7d77eaf1012abde8cdd5c9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042681
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740370}
parent fcd114f7
......@@ -90,10 +90,10 @@ public class NightModeReparentingController implements NightModeStateProvider.Ob
/** Reattach the given task/pair to the activity/tab-model. */
private void reattachTab(ReparentingTask task, TabReparentingParams params, TabModel tabModel) {
final Tab tab = params.getTabToReparent();
task.finish(mReparentingDelegate, () -> {
tabModel.addTab(params.getTabToReparent(), params.getTabIndex(),
TabLaunchType.FROM_REPARENTING);
AsyncTabParamsManager.remove(params.getTabToReparent().getId());
tabModel.addTab(tab, params.getTabIndex(), TabLaunchType.FROM_REPARENTING);
AsyncTabParamsManager.remove(tab.getId());
});
}
......@@ -120,10 +120,13 @@ public class NightModeReparentingController implements NightModeStateProvider.Ob
}
AsyncTabParamsManager.add(tab.getId(), params);
model.removeTab(tab);
ReparentingTask.from(tab).detach();
}
}
// Save the current state to overwrite tab state that was previously saved to disk. See
// crbug.com/1042565 for more info.
mDelegate.getTabModelSelector().saveState();
}
/** @return Mapping from TabModel to all the Tabs in that model. */
......
......@@ -163,6 +163,12 @@ public interface TabModelSelector {
*/
void commitAllTabClosures();
/**
* Save the current state of the tab model. Usage of this method is discouraged due to it
* writing to disk.
**/
void saveState();
/**
* Sets the delegate to handle the requests to close tabs in a single model.
* @param delegate The delegate to be used.
......
......@@ -192,6 +192,9 @@ public abstract class TabModelSelectorBase implements TabModelSelector {
}
}
@Override
public void saveState() {}
@Override
public Tab getTabById(int id) {
for (int i = 0; i < getModels().size(); i++) {
......
......@@ -261,6 +261,7 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
return isIncognitoSelected() == model.isIncognito();
}
@Override
public void saveState() {
commitAllTabClosures();
mTabSaver.saveState();
......
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