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

Unified Diff: base/android/java/src/org/chromium/base/ContextUtils.java

Issue 1879013002: 🍈 Unify application context usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reduce scope again. Created 4 years, 8 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: base/android/java/src/org/chromium/base/ContextUtils.java
diff --git a/base/android/java/src/org/chromium/base/ContextUtils.java b/base/android/java/src/org/chromium/base/ContextUtils.java
index 51adcff8f67375a4bf0507fedfeecf72daa07396..8cecac1333ec928c26096f6fb2e5ccf48576edf0 100644
--- a/base/android/java/src/org/chromium/base/ContextUtils.java
+++ b/base/android/java/src/org/chromium/base/ContextUtils.java
@@ -34,27 +34,46 @@ public class ContextUtils {
}
/**
- * Initialize the Android application context.
+ * Initializes the java application context.
+ *
+ * @param appContext The application context.
+ */
+ public static void setApplicationContext(Context appContext) {
+ // TODO(wnwen): Figure out how to fix this for JUnit tests. Currently they fail this assert
Torne 2016/04/13 15:38:38 Why weren't the tests having this problem before?
Peter Wen 2016/04/13 18:49:20 It's due to BaseChromiumApplication setting this u
+ // due to repeatedly calling onCreate in the base application and keeping global state.
+ //assert sApplicationContext == null || sApplicationContext == appContext;
+ initJavaSideApplicationContext(appContext);
+ }
+
+ /**
+ * Initialize the native Android application context to be the same as the java counter-part.
*
* Either this or the native equivalent base::android::InitApplicationContext must be called
Torne 2016/04/13 15:38:38 Not sure the comment here makes sense any more; it
Peter Wen 2016/04/13 18:49:20 Updated comments.
* once during startup. JNI bindings must have been initialized, as the context is stored on
* both sides.
*/
+ public static void initApplicationContextForNative() {
+ assert sApplicationContext != null;
+ nativeInitNativeSideApplicationContext(sApplicationContext);
+ }
+
+ // TODO(wnwen): Remove when all callers are migrated to new methods as needed.
public static void initApplicationContext(Context appContext) {
- assert appContext != null;
- assert sApplicationContext == null || sApplicationContext == appContext;
- initJavaSideApplicationContext(appContext);
- nativeInitNativeSideApplicationContext(appContext);
+ setApplicationContext(appContext);
+ initApplicationContextForNative();
}
/**
* JUnit Robolectric tests run without native code; allow them to set just the Java-side
* context. Do not use in configurations that actually run on Android!
+ *
+ * TODO(wnwen): These calls can now be safely removed.
*/
public static void initApplicationContextForJUnitTests(Context appContext) {
initJavaSideApplicationContext(appContext);
}
+
@CalledByNative
private static void initJavaSideApplicationContext(Context appContext) {
sApplicationContext = appContext;

Powered by Google App Engine
This is Rietveld 408576698