 Chromium Code Reviews
 Chromium Code Reviews Issue 1303023002:
  Use third_party/custom_tabs_client as the src for customtabs library  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1303023002:
  Use third_party/custom_tabs_client as the src for customtabs library  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java | 
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java | 
| index 045aef059bd1ec91fbbf1d01033d8bd8ceddde3f..0ca47ff9cd52c8c7df2bbee9e567dc8ff61c9fb3 100644 | 
| --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java | 
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java | 
| @@ -21,10 +21,9 @@ import android.os.Build; | 
| import android.os.Bundle; | 
| import android.os.IBinder; | 
| import android.os.Process; | 
| -import android.os.RemoteException; | 
| import android.os.SystemClock; | 
| -import android.support.customtabs.ICustomTabsCallback; | 
| -import android.support.customtabs.ICustomTabsService; | 
| +import android.support.customtabs.CustomTabsCallback; | 
| +import android.support.customtabs.CustomTabsSessionToken; | 
| import android.text.TextUtils; | 
| import android.util.SparseArray; | 
| import android.view.WindowManager; | 
| @@ -66,7 +65,7 @@ import java.util.concurrent.atomic.AtomicReference; | 
| * Note: This class is meant to be package private, and is public to be | 
| * accessible from {@link ChromeApplication}. | 
| */ | 
| -public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| +public class CustomTabsConnection { | 
| private static final String TAG = "cr.ChromeConnection"; | 
| private static final String NO_PRERENDERING_KEY = | 
| "android.support.customtabs.maylaunchurl.NO_PRERENDERING"; | 
| @@ -81,14 +80,14 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| new AtomicReference<CustomTabsConnection>(); | 
| private static final class PrerenderedUrlParams { | 
| - public final IBinder mSession; | 
| + public final CustomTabsSessionToken mSession; | 
| public final WebContents mWebContents; | 
| public final String mUrl; | 
| public final String mReferrer; | 
| public final Bundle mExtras; | 
| - PrerenderedUrlParams(IBinder session, WebContents webContents, String url, String referrer, | 
| - Bundle extras) { | 
| + PrerenderedUrlParams(CustomTabsSessionToken session, | 
| + WebContents webContents, String url, String referrer, Bundle extras) { | 
| mSession = session; | 
| mWebContents = webContents; | 
| mUrl = url; | 
| @@ -141,12 +140,12 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| private static class SessionParams { | 
| public final int mUid; | 
| public final Referrer mReferrer; | 
| - public final ICustomTabsCallback mCallback; | 
| + public final CustomTabsCallback mCallback; | 
| private ServiceConnection mServiceConnection; | 
| private String mPredictedUrl; | 
| private long mLastMayLaunchUrlTimestamp; | 
| - public SessionParams(Context context, int uid, ICustomTabsCallback callback) { | 
| + public SessionParams(Context context, int uid, CustomTabsCallback callback) { | 
| mUid = uid; | 
| mCallback = callback; | 
| mServiceConnection = null; | 
| @@ -185,7 +184,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| } | 
| private final Object mLock = new Object(); | 
| - private final Map<IBinder, SessionParams> mSessionParams = new HashMap<>(); | 
| + private final Map<CustomTabsSessionToken, SessionParams> mSessionParams = new HashMap<>(); | 
| // Prediction tracking is done by UID and not by session, since a | 
| // mis-behaving application can create a large number of sessions. | 
| private SparseArray<PredictionStats> mUidToPredictionsStats = new SparseArray<>(); | 
| @@ -212,28 +211,15 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return sInstance.get(); | 
| } | 
| - @Override | 
| - public boolean newSession(ICustomTabsCallback callback) { | 
| - if (callback == null) return false; | 
| + /** | 
| + * See {@link CustomTabsConnectionService#newSession(CustomTabsSessionToken)}. | 
| + */ | 
| + public boolean newSession(CustomTabsSessionToken session) { | 
| + if (session == null) return false; | 
| final int uid = Binder.getCallingUid(); | 
| - SessionParams sessionParams = new SessionParams(mApplication, uid, callback); | 
| - final IBinder session = callback.asBinder(); | 
| + SessionParams sessionParams = new SessionParams(mApplication, uid, session.getCallback()); | 
| synchronized (mLock) { | 
| if (mSessionParams.containsKey(session)) return false; | 
| - try { | 
| - callback.asBinder().linkToDeath(new IBinder.DeathRecipient() { | 
| - @Override | 
| - public void binderDied() { | 
| - synchronized (mLock) { | 
| - cleanupAlreadyLocked(session); | 
| - } | 
| - } | 
| - }, 0); | 
| - } catch (RemoteException e) { | 
| - // The return code doesn't matter, because this executes when | 
| - // the caller has died. | 
| - return false; | 
| - } | 
| mSessionParams.put(session, sessionParams); | 
| if (mUidToPredictionsStats.get(uid) == null) { | 
| mUidToPredictionsStats.put(uid, new PredictionStats()); | 
| @@ -242,7 +228,9 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return true; | 
| } | 
| - @Override | 
| + /** | 
| + * See {@link CustomTabsConnectionService#warmup(long)}. | 
| + */ | 
| public boolean warmup(long flags) { | 
| // Here and in mayLaunchUrl(), don't do expensive work for background applications. | 
| if (!isCallerForegroundOrSelf()) return false; | 
| @@ -278,8 +266,11 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return true; | 
| } | 
| - @Override | 
| - public boolean mayLaunchUrl(ICustomTabsCallback callback, Uri url, final Bundle extras, | 
| + /** | 
| + * See {@link CustomTabsConnectionService# | 
| + * mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List)}. | 
| + */ | 
| + public boolean mayLaunchUrl(final CustomTabsSessionToken session, Uri url, final Bundle extras, | 
| List<Bundle> otherLikelyBundles) { | 
| // Don't do anything for unknown schemes. Not having a scheme is | 
| // allowed, as we allow "www.example.com". | 
| @@ -287,7 +278,6 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| if (scheme != null && !scheme.equals("http") && !scheme.equals("https")) return false; | 
| if (!isCallerForegroundOrSelf()) return false; | 
| - final IBinder session = callback.asBinder(); | 
| final String urlString = url.toString(); | 
| final boolean noPrerendering = | 
| extras != null ? extras.getBoolean(NO_PRERENDERING_KEY, false) : false; | 
| @@ -315,7 +305,9 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return true; | 
| } | 
| - @Override | 
| + /** | 
| + * {@link CustomTabsConnectionService#extraCommand(String, Bundle)}. | 
| + */ | 
| public Bundle extraCommand(String commandName, Bundle args) { | 
| 
Benoit L
2015/08/21 11:20:47
This no longer overrides a method?
 | 
| return null; | 
| } | 
| @@ -325,7 +317,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| * | 
| * This is used for accounting. | 
| */ | 
| - void registerLaunch(IBinder session, String url) { | 
| + void registerLaunch(CustomTabsSessionToken session, String url) { | 
| int outcome; | 
| long elapsedTimeMs = -1; | 
| synchronized (mLock) { | 
| @@ -380,7 +372,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| * @param referrer The referrer to use for |url|. | 
| * @return The prerendered WebContents, or null. | 
| */ | 
| - WebContents takePrerenderedUrl(IBinder session, String url, String referrer) { | 
| + WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, String referrer) { | 
| ThreadUtils.assertOnUiThread(); | 
| if (mPrerender == null || session == null || !session.equals(mPrerender.mSession)) { | 
| return null; | 
| @@ -399,12 +391,12 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return null; | 
| } | 
| - public Referrer getReferrerForSession(IBinder session) { | 
| + public Referrer getReferrerForSession(CustomTabsSessionToken session) { | 
| if (!mSessionParams.containsKey(session)) return null; | 
| return mSessionParams.get(session).mReferrer; | 
| } | 
| - private ICustomTabsCallback getCallbackForSession(IBinder session) { | 
| + private CustomTabsCallback getCallbackForSession(CustomTabsSessionToken session) { | 
| synchronized (mLock) { | 
| SessionParams sessionParams = mSessionParams.get(session); | 
| if (sessionParams == null) return null; | 
| @@ -415,15 +407,15 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| /** | 
| * Notifies the application of a navigation event. | 
| * | 
| - * Delivers the {@link ICustomTabsConnectionCallback#onNavigationEvent} | 
| + * Delivers the {@link CustomTabsCallback#onNavigationEvent} | 
| * callback to the aplication. | 
| * | 
| * @param session The Binder object identifying the session. | 
| * @param navigationEvent The navigation event code, defined in {@link CustomTabsCallback} | 
| * @return true for success. | 
| */ | 
| - boolean notifyNavigationEvent(IBinder session, int navigationEvent) { | 
| - ICustomTabsCallback callback = getCallbackForSession(session); | 
| + boolean notifyNavigationEvent(CustomTabsSessionToken session, int navigationEvent) { | 
| + CustomTabsCallback callback = getCallbackForSession(session); | 
| if (callback == null) return false; | 
| try { | 
| callback.onNavigationEvent(navigationEvent, null); | 
| @@ -447,7 +439,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| * @param intent Intent describing the service to bind to. | 
| * @return true for success. | 
| */ | 
| - boolean keepAliveForSession(IBinder session, Intent intent) { | 
| + boolean keepAliveForSession(CustomTabsSessionToken session, Intent intent) { | 
| // When an application is bound to a service, its priority is raised to | 
| // be at least equal to the application's one. This binds to a dummy | 
| // service (no calls to this service are made). | 
| @@ -492,7 +484,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| * | 
| * @param session The Binder object identifying the session. | 
| */ | 
| - void dontKeepAliveForSession(IBinder session) { | 
| + void dontKeepAliveForSession(CustomTabsSessionToken session) { | 
| SessionParams sessionParams; | 
| synchronized (mLock) { | 
| sessionParams = mSessionParams.get(session); | 
| @@ -566,17 +558,17 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| @VisibleForTesting | 
| void cleanupAll() { | 
| - synchronized (mLock) { | 
| - List<IBinder> sessions = new ArrayList<>(mSessionParams.keySet()); | 
| - for (IBinder session : sessions) cleanupAlreadyLocked(session); | 
| - } | 
| + List<CustomTabsSessionToken> sessions = new ArrayList<>(mSessionParams.keySet()); | 
| + for (CustomTabsSessionToken session : sessions) cleanupSession(session); | 
| } | 
| /** | 
| * Called when a remote client has died. | 
| */ | 
| - private void cleanupAlreadyLocked(IBinder session) { | 
| - mSessionParams.remove(session); | 
| + void cleanupSession(CustomTabsSessionToken session) { | 
| + synchronized (mLock) { | 
| + mSessionParams.remove(session); | 
| + } | 
| if (mPrerender != null && session.equals(mPrerender.mSession)) { | 
| prerenderUrl(session, null, null); // Cancels the pre-render. | 
| 
Benoit L
2015/08/21 11:20:47
Has we have discovered recently, this needs to be
 | 
| } | 
| @@ -591,7 +583,7 @@ public class CustomTabsConnection extends ICustomTabsService.Stub { | 
| return !cm.isActiveNetworkMetered(); | 
| } | 
| - private void prerenderUrl(IBinder session, String url, Bundle extras) { | 
| + private void prerenderUrl(CustomTabsSessionToken session, String url, Bundle extras) { | 
| ThreadUtils.assertOnUiThread(); | 
| // TODO(lizeb): Prerendering through ChromePrerenderService is | 
| // incompatible with prerendering through this service. Remove this |