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

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

Issue 2976023002: Revert of customtabs: Remove unnecessary Context plumbing. (Closed)
Patch Set: Created 3 years, 5 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 4ef154ee1a0a60233816b9ecc2833daf1cb0f9ec..e79e1d6bc87d987bf6a34c818af1c37f03066f07 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
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.customtabs;
import android.app.ActivityManager;
+import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -26,7 +27,6 @@
import android.util.Pair;
import android.widget.RemoteViews;
-import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
@@ -180,7 +180,7 @@
@VisibleForTesting
SpeculationParams mSpeculation;
- protected final Context mContext;
+ protected final Application mApplication;
protected final ClientManager mClientManager;
private final boolean mLogRequests;
private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean();
@@ -197,20 +197,21 @@
* Public to be instanciable from {@link ChromeApplication}. This is however
* intended to be private.
*/
- public CustomTabsConnection() {
+ public CustomTabsConnection(Application application) {
super();
- mContext = ContextUtils.getApplicationContext();
- // Command line switch values are used below.
- BaseChromiumApplication.initCommandLine(mContext);
- mClientManager = new ClientManager(mContext);
+ mApplication = application;
+ mClientManager = new ClientManager(mApplication);
mLogRequests = CommandLine.getInstance().hasSwitch(LOG_SERVICE_REQUESTS);
}
/**
* @return The unique instance of ChromeCustomTabsConnection.
- */
- public static CustomTabsConnection getInstance() {
+ * TODO(estevenson): Remove Application param.
+ */
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST")
+ public static CustomTabsConnection getInstance(Application application) {
if (sInstance.get() == null) {
+ ((ChromeApplication) application).initCommandLine();
sInstance.compareAndSet(null, AppHooks.get().createCustomTabsConnection());
}
return sInstance.get();
@@ -263,16 +264,17 @@
/** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT")
- private static void initializeBrowser(final Context context) {
+ private static void initializeBrowser(final Application app) {
ThreadUtils.assertOnUiThread();
try {
- ChromeBrowserInitializer.getInstance(context).handleSynchronousStartupWithGpuWarmUp();
+ ChromeBrowserInitializer.getInstance(app).handleSynchronousStartupWithGpuWarmUp();
} catch (ProcessInitException e) {
Log.e(TAG, "ProcessInitException while starting the browser process.");
// Cannot do anything without the native library, and cannot show a
// dialog to the user.
System.exit(-1);
}
+ final Context context = app.getApplicationContext();
ChildProcessLauncherHelper.warmUp(context);
ChromeBrowserInitializer.initNetworkChangeNotifier(context);
WarmupManager.getInstance().initializeViewHierarchy(
@@ -293,8 +295,8 @@
/**
* @return Whether {@link CustomTabsConnection#warmup(long)} has been called.
*/
- public static boolean hasWarmUpBeenFinished() {
- return getInstance().mWarmupHasBeenFinished.get();
+ public static boolean hasWarmUpBeenFinished(Application application) {
+ return getInstance(application).mWarmupHasBeenFinished.get();
}
/**
@@ -323,7 +325,7 @@
// 4. RequestThrottler first access has to be done only once.
// (1)
- if (!initialized) initializeBrowser(mContext);
+ if (!initialized) initializeBrowser(mApplication);
// (2)
if (mayCreateSpareWebContents && mSpeculation == null) {
@@ -339,7 +341,7 @@
// The throttling database uses shared preferences, that can cause a
// StrictMode violation on the first access. Make sure that this access is
// not in mayLauchUrl.
- RequestThrottler.loadInBackground(mContext);
+ RequestThrottler.loadInBackground(mApplication);
}
} finally {
TraceEvent.end("CustomTabsConnection.warmupInternal");
@@ -1007,7 +1009,7 @@
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
do {
ActivityManager am =
- (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
// Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere
// in this code.
// See https://crbug.com/654705.
@@ -1066,7 +1068,8 @@
return SPECULATION_STATUS_ON_START_NOT_ALLOWED_DATA_REDUCTION_ENABLED;
}
ConnectivityManager cm =
- (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ (ConnectivityManager) mApplication.getApplicationContext().getSystemService(
+ Context.CONNECTIVITY_SERVICE);
if (cm.isActiveNetworkMetered() && !shouldPrerenderOnCellularForSession(session)) {
return SPECULATION_STATUS_ON_START_NOT_ALLOWED_NETWORK_METERED;
}
@@ -1162,7 +1165,7 @@
if (mExternalPrerenderHandler == null) {
mExternalPrerenderHandler = new ExternalPrerenderHandler();
}
- Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mContext, true);
+ Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mApplication, true);
String referrer = getReferrer(session, extrasIntent);
boolean forced = shouldPrerenderOnCellularForSession(session);
@@ -1217,12 +1220,12 @@
}
@VisibleForTesting
- void resetThrottling(int uid) {
+ void resetThrottling(Context context, int uid) {
mClientManager.resetThrottling(uid);
}
@VisibleForTesting
- void ban(int uid) {
+ void ban(Context context, int uid) {
mClientManager.ban(uid);
}

Powered by Google App Engine
This is Rietveld 408576698