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

Side by Side Diff: base/android/java/src/org/chromium/base/ContextUtils.java

Issue 2247143004: Remove app context init from LibraryLoader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix per review. Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.base; 5 package org.chromium.base;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
9 import android.preference.PreferenceManager; 9 import android.preference.PreferenceManager;
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 * 47 *
48 * This should be called exactly once early on during startup, before native is loaded and 48 * This should be called exactly once early on during startup, before native is loaded and
49 * before any other clients make use of the application context through this class. 49 * before any other clients make use of the application context through this class.
50 * 50 *
51 * @param appContext The application context. 51 * @param appContext The application context.
52 */ 52 */
53 public static void initApplicationContext(Context appContext) { 53 public static void initApplicationContext(Context appContext) {
54 // Conceding that occasionally in tests, native is loaded before the bro wser process is 54 // Conceding that occasionally in tests, native is loaded before the bro wser process is
55 // started, in which case the browser process re-sets the application co ntext. 55 // started, in which case the browser process re-sets the application co ntext.
56 if (sApplicationContext != null && sApplicationContext != appContext) { 56 if (sApplicationContext != null && sApplicationContext != appContext) {
57 // For webview, sometimes the client app overrides getApplicationCon text in a poor way 57 throw new RuntimeException("Attempting to set multiple global applic ation contexts.");
58 // and fails to make it idempotent. We cannot crash in this scenario , so we ignore new
59 // assignments and assume that the first initialized context is the right application
60 // object. See http://crbug.com/637389.
61 // TODO(wnwen): Add runtime exception back once the underlying issue in LibraryLoader is
62 // fixed.
63 Log.d(TAG, "Multiple contexts detected, ignoring new application con text.");
64 return;
65 } 58 }
66 initJavaSideApplicationContext(appContext); 59 initJavaSideApplicationContext(appContext);
67 } 60 }
68 61
69 /** 62 /**
70 * Initialize the native Android application context to be the same as the j ava counter-part. 63 * Initialize the native Android application context to be the same as the j ava counter-part.
71 */ 64 */
72 public static void initApplicationContextForNative() { 65 public static void initApplicationContextForNative() {
73 if (sApplicationContext == null) { 66 if (sApplicationContext == null) {
74 throw new RuntimeException("Cannot have native global application co ntext be null."); 67 throw new RuntimeException("Cannot have native global application co ntext be null.");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 104
112 private static void initJavaSideApplicationContext(Context appContext) { 105 private static void initJavaSideApplicationContext(Context appContext) {
113 if (appContext == null) { 106 if (appContext == null) {
114 throw new RuntimeException("Global application context cannot be set to null."); 107 throw new RuntimeException("Global application context cannot be set to null.");
115 } 108 }
116 sApplicationContext = appContext; 109 sApplicationContext = appContext;
117 } 110 }
118 111
119 private static native void nativeInitNativeSideApplicationContext(Context ap pContext); 112 private static native void nativeInitNativeSideApplicationContext(Context ap pContext);
120 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698