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 a7eb899580bff3..fd6cb3230bbec6 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 @@ -75,7 +75,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; /** * Implementation of the ICustomTabsConnectionService interface. @@ -137,7 +136,8 @@ public class CustomTabsConnection { @VisibleForTesting static final String REDIRECT_ENDPOINT_KEY = "android.support.customtabs.REDIRECT_ENDPOINT"; - private static AtomicReference sInstance = new AtomicReference<>(); + private static final CustomTabsConnection sInstance = + AppHooks.get().createCustomTabsConnection(); /** Holds the parameters for the current speculation. */ @VisibleForTesting @@ -228,10 +228,7 @@ public CustomTabsConnection() { * @return The unique instance of ChromeCustomTabsConnection. */ public static CustomTabsConnection getInstance() { - if (sInstance.get() == null) { - sInstance.compareAndSet(null, AppHooks.get().createCustomTabsConnection()); - } - return sInstance.get(); + return sInstance; } /** @@ -362,7 +359,7 @@ public boolean warmup(long flags) { * @return Whether {@link CustomTabsConnection#warmup(long)} has been called. */ public static boolean hasWarmUpBeenFinished() { - return getInstance().mWarmupHasBeenFinished.get(); + return sInstance.mWarmupHasBeenFinished.get(); } /** diff --git a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java index 2f2878b8eb68cc..7ebb139d6e325a 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/externalauth/ExternalAuthUtils.java @@ -29,7 +29,6 @@ import org.chromium.chrome.browser.AppHooks; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; /** * Utility class for external authentication tools. @@ -41,9 +40,8 @@ public class ExternalAuthUtils { public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1; private static final String TAG = "ExternalAuthUtils"; - // Use an AtomicReference since getInstance() can be called from multiple threads. - private static AtomicReference sInstance = - new AtomicReference(); + private static final ExternalAuthUtils sInstance = AppHooks.get().createExternalAuthUtils(); + private final SparseHistogramSample mConnectionResultHistogramSample = new SparseHistogramSample("GooglePlayServices.ConnectionResult"); private final TimesHistogramSample mRegistrationTimeHistogramSample = new TimesHistogramSample( @@ -53,10 +51,7 @@ public class ExternalAuthUtils { * Returns the singleton instance of ExternalAuthUtils, creating it if needed. */ public static ExternalAuthUtils getInstance() { - if (sInstance.get() == null) { - sInstance.compareAndSet(null, AppHooks.get().createExternalAuthUtils()); - } - return sInstance.get(); + return sInstance; } /** @@ -217,7 +212,7 @@ public void run() { * @return true if and only if Google Play Services can be used */ public static boolean canUseGooglePlayServices() { - return getInstance().canUseGooglePlayServices(new UserRecoverableErrorHandler.Silent()); + return sInstance.canUseGooglePlayServices(new UserRecoverableErrorHandler.Silent()); } /** @@ -248,7 +243,7 @@ public boolean canUseFirstPartyGooglePlayServices( * @return true if and only if first-party Google Play Services can be used */ public static boolean canUseFirstPartyGooglePlayServices() { - return getInstance().canUseFirstPartyGooglePlayServices( + return sInstance.canUseFirstPartyGooglePlayServices( new UserRecoverableErrorHandler.Silent()); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java index 8121429b839b13..e7df974f4e3252 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java @@ -27,7 +27,6 @@ import java.lang.ref.WeakReference; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nullable; @@ -37,7 +36,8 @@ * Thread-safe: This class may be accessed from any thread. */ public class MultiWindowUtils implements ActivityStateListener { - private static AtomicReference sInstance = new AtomicReference<>(); + // getInstance() is called early in start-up, so there is not point in lazily initializing it. + private static final MultiWindowUtils sInstance = AppHooks.get().createMultiWindowUtils(); // Used to keep track of whether ChromeTabbedActivity2 is running. A tri-state Boolean is // used in case both activities die in the background and MultiWindowUtils is recreated. @@ -46,13 +46,10 @@ public class MultiWindowUtils implements ActivityStateListener { private boolean mIsInMultiWindowModeForTesting; /** - * Returns the singleton instance of MultiWindowUtils, creating it if needed. + * Returns the singleton instance of MultiWindowUtils. */ public static MultiWindowUtils getInstance() { - if (sInstance.get() == null) { - sInstance.compareAndSet(null, AppHooks.get().createMultiWindowUtils()); - } - return sInstance.get(); + return sInstance; } /** @@ -90,11 +87,11 @@ public Class getOpenInOtherWindowActivity(Activity current) // If a second ChromeTabbedActivity is created, MultiWindowUtils needs to listen for // activity state changes to facilitate determining which ChromeTabbedActivity should // be used for intents. - ApplicationStatus.registerStateListenerForAllActivities(sInstance.get()); + ApplicationStatus.registerStateListenerForAllActivities(sInstance); return ChromeTabbedActivity.class; } else if (current instanceof ChromeTabbedActivity) { mTabbedActivity2TaskRunning = true; - ApplicationStatus.registerStateListenerForAllActivities(sInstance.get()); + ApplicationStatus.registerStateListenerForAllActivities(sInstance); return ChromeTabbedActivity2.class; } else { return null; diff --git a/chrome/android/java/src/org/chromium/chrome/browser/rlz/RevenueStats.java b/chrome/android/java/src/org/chromium/chrome/browser/rlz/RevenueStats.java index 6ec03e1dd9d759..7f44a167b94443 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/rlz/RevenueStats.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/rlz/RevenueStats.java @@ -12,8 +12,6 @@ import org.chromium.chrome.browser.AppHooks; import org.chromium.chrome.browser.tab.Tab; -import java.util.concurrent.atomic.AtomicReference; - /** * Utility class for managing revenue sharing information. */ @@ -21,17 +19,13 @@ public class RevenueStats { private static final String PREF_RLZ_NOTIFIED = "rlz_first_search_notified"; - // Use an AtomicReference since getInstance() can be called from multiple threads. - private static AtomicReference sInstance = new AtomicReference(); + private static final RevenueStats sInstance = AppHooks.get().createRevenueStatsInstance(); /** * Returns the singleton instance of ExternalAuthUtils, creating it if needed. */ public static RevenueStats getInstance() { - if (sInstance.get() == null) { - sInstance.compareAndSet(null, AppHooks.get().createRevenueStatsInstance()); - } - return sInstance.get(); + return sInstance; } /**