Commit 121e4bc8 authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Replace partial OneshotSupplier usage with Callback.

This usage here caused problems when trying to change the method
signature of OneshotSupplier[Impl]. This method should not take
OneshotSupplier objects because get() is never used. Similarly, the
implementation of onAvailable() acts without any consideration for what
get() would return.

Refactored to use Callback<Callback<T>> to more closely match the usage.

Bug: 1144824
Change-Id: I7018d3f66aeba3e7b4449f0afff379f0c7d72506
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2514595Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarDavid Maunder <davidjm@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824154}
parent 72f93d1d
......@@ -16,7 +16,6 @@ import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.ObserverList;
import org.chromium.base.TraceEvent;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tab.WebContentsState;
......@@ -139,13 +138,9 @@ public class CriticalPersistedTabData extends PersistedTabData {
PersistedTabData.from(tab,
(data, storage, id)
-> { return new CriticalPersistedTabData(tab, data, storage, id); },
new OneshotSupplierImpl<CriticalPersistedTabData>() {
@Override
public void onAvailable(Callback<CriticalPersistedTabData> supplierCallback) {
supplierCallback.onResult(
tab.isInitialized() ? CriticalPersistedTabData.build(tab) : null);
}
},
(supplierCallback)
-> supplierCallback.onResult(
tab.isInitialized() ? CriticalPersistedTabData.build(tab) : null),
CriticalPersistedTabData.class, callback);
}
......
......@@ -15,7 +15,6 @@ import org.chromium.base.TraceEvent;
import org.chromium.base.UserData;
import org.chromium.base.UserDataHost;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.Supplier;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.tab.Tab;
......@@ -92,22 +91,22 @@ public abstract class PersistedTabData implements UserData {
* At a minimum, a frozen tab with an identifier and isIncognito fields set
* is required.
* @param factory {@link PersistedTabDataFactory} which will create {@link PersistedTabData}
* @param supplier for constructing a {@link PersistedTabData} from a
* {@link Tab}. This will be used as a fallback in the event that the {@link PersistedTabData}
* cannot be found in storage.
* @param tabDataCreator for constructing a {@link PersistedTabData} corresponding to the passed
* in tab. This will be used as a fallback in the event that the {@link PersistedTabData} cannot
* be found in storage or needs an update.
* @param clazz class of the {@link PersistedTabData}
* @param callback callback to pass the {@link PersistedTabData} in
* @return {@link PersistedTabData} from storage
*/
protected static <T extends PersistedTabData> void from(Tab tab,
PersistedTabDataFactory<T> factory, OneshotSupplier<T> supplier, Class<T> clazz,
Callback<T> callback) {
PersistedTabDataFactory<T> factory, Callback<Callback<T>> tabDataCreator,
Class<T> clazz, Callback<T> callback) {
ThreadUtils.assertOnUiThread();
// TODO(crbug.com/1059602) cache callbacks
T persistedTabDataFromTab = getUserData(tab, clazz);
if (persistedTabDataFromTab != null) {
if (persistedTabDataFromTab.needsUpdate()) {
supplier.onAvailable((tabData) -> {
tabDataCreator.onResult((tabData) -> {
updateLastUpdatedMs(tabData);
if (tabData != null) {
setUserData(tab, clazz, tabData);
......@@ -129,14 +128,14 @@ public abstract class PersistedTabData implements UserData {
PersistedTabDataConfiguration.get(clazz, tab.isIncognito());
config.storage.restore(tab.getId(), config.id, (data) -> {
if (data == null) {
supplier.onAvailable((tabData) -> {
tabDataCreator.onResult((tabData) -> {
updateLastUpdatedMs(tabData);
onPersistedTabDataResult(tabData, tab, clazz, key);
});
} else {
T persistedTabDataFromStorage = factory.create(data, config.storage, config.id);
if (persistedTabDataFromStorage.needsUpdate()) {
supplier.onAvailable((tabData) -> {
tabDataCreator.onResult((tabData) -> {
updateLastUpdatedMs(tabData);
onPersistedTabDataResult(tabData, tab, clazz, key);
});
......
......@@ -18,7 +18,6 @@ import org.json.JSONObject;
import org.chromium.base.Callback;
import org.chromium.base.Log;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.chrome.browser.endpoint_fetcher.EndpointFetcher;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
......@@ -84,9 +83,8 @@ public class ShoppingPersistedTabData extends PersistedTabData {
PersistedTabData.from(tab,
(data, storage, id)
-> { return new ShoppingPersistedTabData(tab, data, storage, id); },
new OneshotSupplierImpl<ShoppingPersistedTabData>() {
@Override
public void onAvailable(Callback<ShoppingPersistedTabData> supplierCallback) {
(supplierCallback)
-> {
ShoppingPersistedTabData previousShoppingPersistedTabData =
PersistedTabData.from(tab, USER_DATA_KEY);
EndpointFetcher.fetchUsingOAuth(
......@@ -97,9 +95,8 @@ public class ShoppingPersistedTabData extends PersistedTabData {
previousShoppingPersistedTabData));
},
Profile.getLastUsedRegularProfile(), OAUTH_NAME,
String.format(Locale.US, ENDPOINT, tab.getUrlString()),
HTTPS_METHOD, CONTENT_TYPE, SCOPES, EMPTY_POST_DATA, TIMEOUT_MS);
}
String.format(Locale.US, ENDPOINT, tab.getUrlString()), HTTPS_METHOD,
CONTENT_TYPE, SCOPES, EMPTY_POST_DATA, TIMEOUT_MS);
},
ShoppingPersistedTabData.class, callback);
}
......
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