Commit b2659132 authored by dfalcantara's avatar dfalcantara Committed by Commit bot

Make DocumentTabModelImpl fire didSelectTab

DocumentTabModelImpl now fires didSelectTab to its observers. This is done in
setLastShownId() instead of setIndex() for a few reasons:

* setIndex() has the side effect of bringing Tabs forward, which you may not
  want.

* setLastShownId() hopefully more faithfully tracks what Tab was last shown in
  the foreground, and is called by DocumentActivity.onResume().  This might
  still be incorrect (e.g. when opening a Tab in the background), but this is
  one of those weird cases where Android has two Activities in the foreground
  simultaneously.

* It's really difficult to actually indicate what brings a Tab back to the
  foreground.  Slap a TODO on there to actually fix it when an Observer actually
  needs to know the type.

BUG=443772

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

Cr-Commit-Position: refs/heads/master@{#322519}
parent ce9161d6
......@@ -195,8 +195,9 @@ public interface DocumentTabModel extends TabModel {
/**
* Records the ID of the last shown Tab.
* @param id ID of the last shown Tab.
* @return Whether or not the ID had to be updated.
*/
void setLastShownId(int id);
boolean setLastShownId(int id);
/**
* Called to begin loading tab state from disk. It will load the prioritized tab first
......
......@@ -223,7 +223,10 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
}
@Override
public void setLastShownId(int id) {
public boolean setLastShownId(int id) {
if (mLastShownTabId == id) return false;
int previousTabId = mLastShownTabId;
mLastShownTabId = id;
String prefName =
......@@ -232,6 +235,15 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(prefName, id);
editor.apply();
// TODO(dfalcantara): Figure out how to fire the correct type of TabSelectionType, which is
// quite hard to do in Document-mode from where we call this.
for (TabModelObserver obs : mObservers) {
obs.didSelectTab(
TabModelUtils.getCurrentTab(this), TabSelectionType.FROM_USER, previousTabId);
}
return true;
}
@Override
......
......@@ -142,9 +142,9 @@ public class OffTheRecordDocumentTabModel extends OffTheRecordTabModel implement
}
@Override
public void setLastShownId(int id) {
public boolean setLastShownId(int id) {
ensureTabModelImpl();
getDelegateDocumentTabModel().setLastShownId(id);
return getDelegateDocumentTabModel().setLastShownId(id);
}
@Override
......
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