Chromium Code Reviews| 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; |