Commit b5cd7407 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Allow update callback for existing CCT, rolls DEPS to the CL:1076648.

Bug: 847528
Change-Id: Ie119a50be4dc4131954cac001a70821feb94018f
Reviewed-on: https://chromium-review.googlesource.com/1077147
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588850}
parent 118b5d25
...@@ -599,7 +599,7 @@ deps = { ...@@ -599,7 +599,7 @@ deps = {
}, },
'src/third_party/custom_tabs_client/src': { 'src/third_party/custom_tabs_client/src': {
'url': Var('chromium_git') + '/custom-tabs-client.git' + '@' + '81a14bc0885944a65afa81acd00da16cecb74b8b', 'url': Var('chromium_git') + '/custom-tabs-client.git' + '@' + '7ad890c969e7fcae8cd078c1f109f2aadd0793ee',
'condition': 'checkout_android', 'condition': 'checkout_android',
}, },
......
...@@ -31,6 +31,7 @@ import org.chromium.build.BuildHooksAndroid; ...@@ -31,6 +31,7 @@ import org.chromium.build.BuildHooksAndroid;
import org.chromium.build.BuildHooksConfig; import org.chromium.build.BuildHooksConfig;
import org.chromium.chrome.browser.crash.PureJavaExceptionHandler; import org.chromium.chrome.browser.crash.PureJavaExceptionHandler;
import org.chromium.chrome.browser.crash.PureJavaExceptionReporter; import org.chromium.chrome.browser.crash.PureJavaExceptionReporter;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.init.InvalidStartupDialog; import org.chromium.chrome.browser.init.InvalidStartupDialog;
import org.chromium.chrome.browser.metrics.UmaUtils; import org.chromium.chrome.browser.metrics.UmaUtils;
import org.chromium.chrome.browser.preferences.ChromePreferenceManager; import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
...@@ -133,6 +134,8 @@ public class ChromeApplication extends Application { ...@@ -133,6 +134,8 @@ public class ChromeApplication extends Application {
if ((level >= TRIM_MEMORY_RUNNING_LOW && level < TRIM_MEMORY_UI_HIDDEN) if ((level >= TRIM_MEMORY_RUNNING_LOW && level < TRIM_MEMORY_UI_HIDDEN)
|| level >= TRIM_MEMORY_MODERATE) { || level >= TRIM_MEMORY_MODERATE) {
if (mReferencePool != null) mReferencePool.drain(); if (mReferencePool != null) mReferencePool.drain();
CustomTabsConnection.cleanUpUnusedSessions();
} }
} }
......
...@@ -162,6 +162,7 @@ class ClientManager { ...@@ -162,6 +162,7 @@ class ClientManager {
/** Per-session values. */ /** Per-session values. */
private static class SessionParams { private static class SessionParams {
public final int uid; public final int uid;
private CustomTabsCallback mCustomTabsCallback;
public final DisconnectCallback disconnectCallback; public final DisconnectCallback disconnectCallback;
public final PostMessageHandler postMessageHandler; public final PostMessageHandler postMessageHandler;
public final Set<Origin> mLinkedOrigins = new HashSet<>(); public final Set<Origin> mLinkedOrigins = new HashSet<>();
...@@ -182,10 +183,11 @@ class ClientManager { ...@@ -182,10 +183,11 @@ class ClientManager {
private boolean mAllowResourcePrefetch; private boolean mAllowResourcePrefetch;
private boolean mShouldGetPageLoadMetrics; private boolean mShouldGetPageLoadMetrics;
public SessionParams(Context context, int uid, DisconnectCallback callback, public SessionParams(Context context, int uid, CustomTabsCallback customTabsCallback,
PostMessageHandler postMessageHandler) { DisconnectCallback callback, PostMessageHandler postMessageHandler) {
this.uid = uid; this.uid = uid;
mPackageName = getPackageName(context, uid); mPackageName = getPackageName(context, uid);
mCustomTabsCallback = customTabsCallback;
disconnectCallback = callback; disconnectCallback = callback;
this.postMessageHandler = postMessageHandler; this.postMessageHandler = postMessageHandler;
if (postMessageHandler != null) this.postMessageHandler.setPackageName(mPackageName); if (postMessageHandler != null) this.postMessageHandler.setPackageName(mPackageName);
...@@ -253,6 +255,14 @@ class ClientManager { ...@@ -253,6 +255,14 @@ class ClientManager {
public boolean isDefault() { public boolean isDefault() {
return !mIgnoreFragments && !mShouldSpeculateLoadOnCellular; return !mIgnoreFragments && !mShouldSpeculateLoadOnCellular;
} }
public CustomTabsCallback getCustomTabsCallback() {
return mCustomTabsCallback;
}
public void setCustomTabsCallback(CustomTabsCallback customTabsCallback) {
mCustomTabsCallback = customTabsCallback;
}
} }
private final Map<CustomTabsSessionToken, SessionParams> mSessionParams = new HashMap<>(); private final Map<CustomTabsSessionToken, SessionParams> mSessionParams = new HashMap<>();
...@@ -271,15 +281,17 @@ class ClientManager { ...@@ -271,15 +281,17 @@ class ClientManager {
* @param postMessageHandler The handler to be used for postMessage related operations. * @param postMessageHandler The handler to be used for postMessage related operations.
* @return true for success. * @return true for success.
*/ */
public boolean newSession(CustomTabsSessionToken session, int uid, public synchronized boolean newSession(CustomTabsSessionToken session, int uid,
DisconnectCallback onDisconnect, @NonNull PostMessageHandler postMessageHandler) { DisconnectCallback onDisconnect, @NonNull PostMessageHandler postMessageHandler) {
if (session == null) return false; if (session == null || session.getCallback() == null) return false;
SessionParams params = new SessionParams( if (mSessionParams.containsKey(session)) {
ContextUtils.getApplicationContext(), uid, onDisconnect, postMessageHandler); mSessionParams.get(session).setCustomTabsCallback(session.getCallback());
synchronized (this) { } else {
if (mSessionParams.containsKey(session)) return false; SessionParams params = new SessionParams(ContextUtils.getApplicationContext(), uid,
session.getCallback(), onDisconnect, postMessageHandler);
mSessionParams.put(session, params); mSessionParams.put(session, params);
} }
return true; return true;
} }
...@@ -518,7 +530,10 @@ class ClientManager { ...@@ -518,7 +530,10 @@ class ClientManager {
* @return The callback {@link CustomTabsSessionToken} for the given session. * @return The callback {@link CustomTabsSessionToken} for the given session.
*/ */
public synchronized CustomTabsCallback getCallbackForSession(CustomTabsSessionToken session) { public synchronized CustomTabsCallback getCallbackForSession(CustomTabsSessionToken session) {
return session != null ? session.getCallback() : null; if (session != null && mSessionParams.containsKey(session)) {
return mSessionParams.get(session).getCustomTabsCallback();
}
return null;
} }
/** /**
...@@ -748,6 +763,7 @@ class ClientManager { ...@@ -748,6 +763,7 @@ class ClientManager {
* Cleans up all data associated with all sessions. * Cleans up all data associated with all sessions.
*/ */
public synchronized void cleanupAll() { public synchronized void cleanupAll() {
// cleanupSessionInternal modifies mSessionParams therefore we need a copy
List<CustomTabsSessionToken> sessions = new ArrayList<>(mSessionParams.keySet()); List<CustomTabsSessionToken> sessions = new ArrayList<>(mSessionParams.keySet());
for (CustomTabsSessionToken session : sessions) cleanupSession(session); for (CustomTabsSessionToken session : sessions) cleanupSession(session);
} }
...@@ -756,14 +772,44 @@ class ClientManager { ...@@ -756,14 +772,44 @@ class ClientManager {
* Handle any clean up left after a session is destroyed. * Handle any clean up left after a session is destroyed.
* @param session The session that has been destroyed. * @param session The session that has been destroyed.
*/ */
public synchronized void cleanupSession(CustomTabsSessionToken session) { private synchronized void cleanupSessionInternal(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session); SessionParams params = mSessionParams.get(session);
if (params == null) return; if (params == null) return;
mSessionParams.remove(session); mSessionParams.remove(session);
if (params.postMessageHandler != null) if (params.postMessageHandler != null) {
params.postMessageHandler.cleanup(ContextUtils.getApplicationContext()); params.postMessageHandler.cleanup(ContextUtils.getApplicationContext());
}
if (params.originVerifier != null) params.originVerifier.cleanUp(); if (params.originVerifier != null) params.originVerifier.cleanUp();
if (params.disconnectCallback != null) params.disconnectCallback.run(session); if (params.disconnectCallback != null) params.disconnectCallback.run(session);
mUidHasCalledWarmup.delete(params.uid); mUidHasCalledWarmup.delete(params.uid);
} }
/**
* Destroys session when its callback become invalid if the callback is used as identifier.
*
* @param session The session with invalid callback.
*/
public synchronized void cleanupSession(CustomTabsSessionToken session) {
if (session.hasId()) {
// Leave session parameters, so client might update callback later.
// The session will be completely removed when system runs low on memory.
// {@see #cleanupUnusedSessions}
mSessionParams.get(session).setCustomTabsCallback(null);
} else {
cleanupSessionInternal(session);
}
}
/**
* Clean up all sessions which are not currently used.
*/
public synchronized void cleanupUnusedSessions() {
// cleanupSessionInternal modifies mSessionParams therefore we need a copy
List<CustomTabsSessionToken> sessions = new ArrayList<>(mSessionParams.keySet());
for (CustomTabsSessionToken session : sessions) {
if (mSessionParams.get(session).getCustomTabsCallback() == null) {
cleanupSessionInternal(session);
}
}
}
} }
...@@ -185,8 +185,7 @@ public class CustomTabsConnection { ...@@ -185,8 +185,7 @@ public class CustomTabsConnection {
new EnumeratedHistogramSample( new EnumeratedHistogramSample(
"CustomTabs.ParallelRequestStatusOnStart", ParallelRequestStatus.NUM_ENTRIES); "CustomTabs.ParallelRequestStatusOnStart", ParallelRequestStatus.NUM_ENTRIES);
private static final CustomTabsConnection sInstance = private static CustomTabsConnection sInstance;
AppHooks.get().createCustomTabsConnection();
private @Nullable String mTrustedPublisherUrlPackage; private @Nullable String mTrustedPublisherUrlPackage;
/** Holds the parameters for the current hidden tab speculation. */ /** Holds the parameters for the current hidden tab speculation. */
...@@ -259,9 +258,17 @@ public class CustomTabsConnection { ...@@ -259,9 +258,17 @@ public class CustomTabsConnection {
* @return The unique instance of ChromeCustomTabsConnection. * @return The unique instance of ChromeCustomTabsConnection.
*/ */
public static CustomTabsConnection getInstance() { public static CustomTabsConnection getInstance() {
if (sInstance == null) {
sInstance = AppHooks.get().createCustomTabsConnection();
}
return sInstance; return sInstance;
} }
private static boolean hasInstance() {
return sInstance != null;
}
/** /**
* If service requests logging is enabled, logs that a call was made. * If service requests logging is enabled, logs that a call was made.
* *
...@@ -390,7 +397,7 @@ public class CustomTabsConnection { ...@@ -390,7 +397,7 @@ public class CustomTabsConnection {
* @return Whether {@link CustomTabsConnection#warmup(long)} has been called. * @return Whether {@link CustomTabsConnection#warmup(long)} has been called.
*/ */
public static boolean hasWarmUpBeenFinished() { public static boolean hasWarmUpBeenFinished() {
return sInstance.mWarmupHasBeenFinished.get(); return getInstance().mWarmupHasBeenFinished.get();
} }
/** /**
...@@ -1316,6 +1323,13 @@ public class CustomTabsConnection { ...@@ -1316,6 +1323,13 @@ public class CustomTabsConnection {
ThreadUtils.runOnUiThread(() -> mClientManager.cleanupSession(session)); ThreadUtils.runOnUiThread(() -> mClientManager.cleanupSession(session));
} }
/**
* Clean up unused sessions, i.e sessions without callback.
*/
public static void cleanUpUnusedSessions() {
if (hasInstance()) getInstance().mClientManager.cleanupUnusedSessions();
}
@VisibleForTesting @VisibleForTesting
int maySpeculateWithResult(CustomTabsSessionToken session) { int maySpeculateWithResult(CustomTabsSessionToken session) {
if (!DeviceClassManager.enablePrerendering()) { if (!DeviceClassManager.enablePrerendering()) {
......
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