Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2633)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java

Issue 1261893002: customtabs: Allows CustomTabsConnection to be subclassed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Silence findbugs warning. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a9e9f22a2013ee4a40490b2eb612271ead520b29..d61c71eac4c990feba787511be87e026e26a1fd2 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
@@ -53,11 +53,15 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Implementation of the ICustomTabsConnectionService interface.
+ *
+ * Note: This class is meant to be package private, and is public to be
+ * accessible from {@link ChromeApplication}.
*/
-class CustomTabsConnection extends ICustomTabsService.Stub {
+public class CustomTabsConnection extends ICustomTabsService.Stub {
private static final String TAG = "cr.ChromeConnection";
// Values for the "CustomTabs.PredictionStatus" UMA histogram. Append-only.
@@ -66,8 +70,8 @@ class CustomTabsConnection extends ICustomTabsService.Stub {
private static final int BAD_PREDICTION = 2;
private static final int PREDICTION_STATUS_COUNT = 3;
- private static final Object sConstructionLock = new Object();
- private static CustomTabsConnection sInstance;
+ private static AtomicReference<CustomTabsConnection> sInstance =
+ new AtomicReference<CustomTabsConnection>();
private static final class PrerenderedUrlParams {
public final IBinder mSession;
@@ -121,7 +125,7 @@ class CustomTabsConnection extends ICustomTabsService.Stub {
}
}
- private final Application mApplication;
+ protected final Application mApplication;
private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean();
private ExternalPrerenderHandler mExternalPrerenderHandler;
private PrerenderedUrlParams mPrerender;
@@ -170,7 +174,12 @@ class CustomTabsConnection extends ICustomTabsService.Stub {
// mis-behaving application can create a large number of sessions.
private SparseArray<PredictionStats> mUidToPredictionsStats = new SparseArray<>();
- private CustomTabsConnection(Application application) {
+ /**
+ * <strong>DO NOT CALL</strong>
+ * Public to be instanciable from {@link ChromeApplication}. This is however
+ * intended to be private.
+ */
+ public CustomTabsConnection(Application application) {
super();
mApplication = application;
}
@@ -178,11 +187,13 @@ class CustomTabsConnection extends ICustomTabsService.Stub {
/**
* @return The unique instance of ChromeCustomTabsConnection.
*/
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST")
public static CustomTabsConnection getInstance(Application application) {
- synchronized (sConstructionLock) {
- if (sInstance == null) sInstance = new CustomTabsConnection(application);
+ if (sInstance.get() == null) {
+ ChromeApplication chromeApplication = (ChromeApplication) application;
+ sInstance.compareAndSet(null, chromeApplication.createCustomTabsConnection());
}
- return sInstance;
+ return sInstance.get();
}
@Override
@@ -284,6 +295,11 @@ class CustomTabsConnection extends ICustomTabsService.Stub {
return true;
}
+ @Override
+ public Bundle extraCommand(String commandName, Bundle args) {
+ return null;
+ }
+
/**
* Registers a launch of a |url| for a given |session|.
*

Powered by Google App Engine
This is Rietveld 408576698