Commit 65bb962f authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Respond to lifecycle events and periodcally refresh the last tab button

* Periodically queries the history service and refreshes the last tab
  button.
* Responds to tab events to refresh the last tab button.

Bug: 959860
Change-Id: Ib4f039c377211e8471267991442ff81318068867
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627895
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665278}
parent 9de7c72a
...@@ -19,6 +19,9 @@ import org.chromium.chrome.browser.history.HistoryItem; ...@@ -19,6 +19,9 @@ import org.chromium.chrome.browser.history.HistoryItem;
import org.chromium.chrome.browser.history.HistoryProvider; import org.chromium.chrome.browser.history.HistoryProvider;
import org.chromium.chrome.browser.native_page.NativePageHost; import org.chromium.chrome.browser.native_page.NativePageHost;
import org.chromium.chrome.browser.profiles.Profile; 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.tabmodel.TabSelectionType;
import org.chromium.chrome.browser.util.UrlUtilities; import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.chrome.browser.util.ViewUtils; import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.RoundedIconGenerator; import org.chromium.chrome.browser.widget.RoundedIconGenerator;
...@@ -34,7 +37,8 @@ import java.util.List; ...@@ -34,7 +37,8 @@ import java.util.List;
* Mediator used to look for history events and update the model accordingly. * Mediator used to look for history events and update the model accordingly.
*/ */
// TODO(crbug.com/948858): Add unit tests for this behavior. // TODO(crbug.com/948858): Add unit tests for this behavior.
class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, FocusableComponent { class OpenLastTabMediator extends EmptyTabObserver
implements HistoryProvider.BrowsingHistoryObserver, FocusableComponent {
private static final String FIRST_LAUNCHED_KEY = "TOUCHLESS_WAS_FIRST_LAUNCHED"; private static final String FIRST_LAUNCHED_KEY = "TOUCHLESS_WAS_FIRST_LAUNCHED";
private final Context mContext; private final Context mContext;
...@@ -49,14 +53,15 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo ...@@ -49,14 +53,15 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo
OpenLastTabMediator(Context context, Profile profile, NativePageHost nativePageHost, OpenLastTabMediator(Context context, Profile profile, NativePageHost nativePageHost,
PropertyModel model, OpenLastTabView view) { PropertyModel model, OpenLastTabView view) {
mModel = model;
mContext = context; mContext = context;
mProfile = profile; mProfile = profile;
mNativePageHost = nativePageHost; mNativePageHost = nativePageHost;
mModel = model;
mHistoryBridge = new BrowsingHistoryBridge(false); mHistoryBridge = new BrowsingHistoryBridge(false);
mHistoryBridge.setObserver(this); mHistoryBridge.setObserver(this);
mNativePageHost.getActiveTab().addObserver(this);
mIconGenerator = mIconGenerator =
ViewUtils.createDefaultRoundedIconGenerator(mContext.getResources(), false); ViewUtils.createDefaultRoundedIconGenerator(mContext.getResources(), false);
mIconBridge = new LargeIconBridge(mProfile); mIconBridge = new LargeIconBridge(mProfile);
...@@ -74,7 +79,7 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo ...@@ -74,7 +79,7 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo
// TODO(wylieb):Investigate adding an item limit to the API. // TODO(wylieb):Investigate adding an item limit to the API.
// Query the history for everything (no API exists to only query for the most recent). // Query the history for everything (no API exists to only query for the most recent).
mHistoryBridge.queryHistory(""); refreshHistoryData();
} }
void destroy() { void destroy() {
...@@ -82,6 +87,18 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo ...@@ -82,6 +87,18 @@ class OpenLastTabMediator implements HistoryProvider.BrowsingHistoryObserver, Fo
mHistoryBridge.destroy(); mHistoryBridge.destroy();
mHistoryBridge = null; mHistoryBridge = null;
} }
mNativePageHost.getActiveTab().removeObserver(this);
}
void refreshHistoryData() {
mHistoryBridge.queryHistory("");
}
@Override
public void onShown(Tab tab, @TabSelectionType int type) {
// Query the history as it may have been cleared while the app was hidden. This could happen
// via the Android settings.
refreshHistoryData();
} }
@Override @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