Commit 1c3e620e authored by Lei Tian's avatar Lei Tian Committed by Commit Bot

Reland "Use TabPersistentStoreObserver.onMetadataSavedAsynchronously to...

Reland "Use TabPersistentStoreObserver.onMetadataSavedAsynchronously to background the Browser Actions tab creation service"

This relands commit 64565fd7.

Original change's description:
> Use TabPersistentStoreObserver.onMetadataSavedAsynchronously to
background the Browser Actions tab creation service
>
> Change the logic to background the Browser Actions tab creation
service
> based on TabPersistentStoreObserver.onMetadataSavedAsynchronously. The
> callback indicates that tab model lists are backuped so the saved tabs
> can be restored succesfully.
>
> Also for the notification when a new tab has not been created (tabId
is
> not available), the Intent to bind the notification will be a VIEW
> intent. This notification is necessary to make the service foreground.
>
> Bug: 766349
> Change-Id: I73d49e2a1e26410b2dd6e51a07f35e9965b9a38a
> Reviewed-on: https://chromium-review.googlesource.com/769852
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Commit-Queue: Lei Tian <ltian@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#517492}

Bug: 766349
Change-Id: Icb35c3b0e3ed2186e48c7f0e77ceb6a07bc1f39f
Reviewed-on: https://chromium-review.googlesource.com/791392Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Lei Tian <ltian@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519509}
parent 614ea918
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.browseractions;
import android.os.AsyncTask;
import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.browseractions.BrowserActionsTabCreatorManager.BrowserActionsTabCreator;
......@@ -126,11 +127,12 @@ public class BrowserActionsTabModelSelector
/**
* Creates a new Tab with given url in Browser Actions tab model.
* @param loadUrlParams The url params to be opened.
* @param tabCreatedCallback The {@link Callback} to run when tab is created.
*/
public void openNewTab(LoadUrlParams loadUrlParams) {
public void openNewTab(LoadUrlParams loadUrlParams, Callback<Integer> tabCreatedCallback) {
// If tab model is restored, directly create a new tab.
if (isTabStateInitialized()) {
createNewTab(loadUrlParams);
createNewTab(loadUrlParams, tabCreatedCallback);
return;
}
if (mTabCreationRunnable == null) {
......@@ -138,7 +140,7 @@ public class BrowserActionsTabModelSelector
@Override
public void run() {
for (int i = 0; i < mPendingUrls.size(); i++) {
createNewTab(mPendingUrls.get(i));
createNewTab(mPendingUrls.get(i), tabCreatedCallback);
}
mPendingUrls.clear();
}
......@@ -156,8 +158,9 @@ public class BrowserActionsTabModelSelector
mPendingUrls.add(loadUrlParams);
}
private void createNewTab(LoadUrlParams params) {
openNewTab(params, TabLaunchType.FROM_BROWSER_ACTIONS, null, false);
private void createNewTab(LoadUrlParams params, Callback<Integer> tabCreatedCallback) {
Tab tab = openNewTab(params, TabLaunchType.FROM_BROWSER_ACTIONS, null, false);
tabCreatedCallback.onResult(tab.getId());
}
@Override
......@@ -242,4 +245,12 @@ public class BrowserActionsTabModelSelector
public void addTabPersistentStoreObserver(TabPersistentStoreObserver observer) {
mTabSaver.addObserver(observer);
}
/**
* Remove a {@link TabPersistentStoreObserver} from {@link TabPersistentStore}.
* @param observer The observer to remove.
*/
public void removeTabPersistentStoreObserver(TabPersistentStoreObserver observer) {
mTabSaver.removeObserver(observer);
}
}
......@@ -424,4 +424,12 @@ public class TabModelSelectorImpl extends TabModelSelectorBase implements TabMod
public void addTabPersistentStoreObserver(TabPersistentStoreObserver observer) {
mTabSaver.addObserver(observer);
}
/**
* Remove a {@link TabPersistentStoreObserver} from {@link TabPersistentStore}.
* @param observer The observer to remove.
*/
public void removeTabPersistentStoreObserver(TabPersistentStoreObserver observer) {
mTabSaver.removeObserver(observer);
}
}
......@@ -519,7 +519,8 @@ public class BrowserActionActivityTest {
@Override
public boolean isSatisfied() {
return activity2.areTabModelsInitialized()
&& activity2.getTabModelSelector().isTabStateInitialized();
&& activity2.getTabModelSelector().isTabStateInitialized()
&& activity2.getActivityTab() != null;
}
});
String cta2ActivityTabUrl = activity2.getActivityTab().getUrl();
......
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