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

Unified Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java

Issue 2726613002: Fix ensureInitialized() to try if the previous attempt failed (Closed)
Patch Set: Removed redundant if statement Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java
diff --git a/components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java b/components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java
index e45dd8f48030fa9a1ec74f60b118fd1b13f81f61..a821c42053792c7487c6c2cc77bffaedc0bf5e12 100644
--- a/components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java
+++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetLibraryLoader.java
@@ -25,9 +25,9 @@ public class CronetLibraryLoader {
private static final String LIBRARY_NAME = "cronet";
private static final String TAG = CronetLibraryLoader.class.getSimpleName();
// Has library loading commenced? Setting guarded by sLoadLock.
- private static volatile boolean sInitStarted = false;
+ private static volatile boolean sLibraryLoaded = false;
// Has ensureMainThreadInitialized() completed? Only accessed on main thread.
- private static boolean sMainThreadInitDone = false;
+ private static volatile boolean sMainThreadInitDone = false;
/**
* Ensure that native library is loaded and initialized. Can be called from
@@ -36,38 +36,41 @@ public class CronetLibraryLoader {
public static void ensureInitialized(
final Context applicationContext, final CronetEngineBuilderImpl builder) {
synchronized (sLoadLock) {
- if (sInitStarted) {
- return;
- }
- sInitStarted = true;
- ContextUtils.initApplicationContext(applicationContext);
- if (builder.libraryLoader() != null) {
- builder.libraryLoader().loadLibrary(LIBRARY_NAME);
- } else {
- System.loadLibrary(LIBRARY_NAME);
- }
- ContextUtils.initApplicationContextForNative();
- String implVersion = ImplVersion.getCronetVersion();
- if (!implVersion.equals(nativeGetCronetVersion())) {
- throw new RuntimeException(String.format("Expected Cronet version number %s, "
- + "actual version number %s.",
- implVersion, nativeGetCronetVersion()));
+ if (!sLibraryLoaded) {
+ ContextUtils.initApplicationContext(applicationContext);
+ if (builder.libraryLoader() != null) {
+ builder.libraryLoader().loadLibrary(LIBRARY_NAME);
+ } else {
+ System.loadLibrary(LIBRARY_NAME);
+ }
+ ContextUtils.initApplicationContextForNative();
+ String implVersion = ImplVersion.getCronetVersion();
+ if (!implVersion.equals(nativeGetCronetVersion())) {
+ throw new RuntimeException(String.format("Expected Cronet version number %s, "
+ + "actual version number %s.",
+ implVersion, nativeGetCronetVersion()));
+ }
+ Log.i(TAG, "Cronet version: %s, arch: %s", implVersion,
+ System.getProperty("os.arch"));
+ sLibraryLoaded = true;
}
- Log.i(TAG, "Cronet version: %s, arch: %s", implVersion, System.getProperty("os.arch"));
- // Init native Chromium CronetEngine on Main UI thread.
- Runnable task = new Runnable() {
- @Override
- public void run() {
- ensureInitializedOnMainThread(applicationContext);
+
+ if (!sMainThreadInitDone) {
+ // Init native Chromium CronetEngine on Main UI thread.
+ Runnable task = new Runnable() {
+ @Override
+ public void run() {
+ ensureInitializedOnMainThread(applicationContext);
+ }
+ };
+ // Run task immediately or post it to the UI thread.
+ if (Looper.getMainLooper() == Looper.myLooper()) {
+ task.run();
+ } else {
+ // The initOnMainThread will complete on the main thread prior
+ // to other tasks posted to the main thread.
+ new Handler(Looper.getMainLooper()).post(task);
}
- };
- // Run task immediately or post it to the UI thread.
- if (Looper.getMainLooper() == Looper.myLooper()) {
- task.run();
- } else {
- // The initOnMainThread will complete on the main thread prior
- // to other tasks posted to the main thread.
- new Handler(Looper.getMainLooper()).post(task);
}
}
}
@@ -78,7 +81,7 @@ public class CronetLibraryLoader {
* main thread native MessageLoop is initialized.
*/
static void ensureInitializedOnMainThread(Context context) {
- assert sInitStarted;
+ assert sLibraryLoaded;
assert Looper.getMainLooper() == Looper.myLooper();
if (sMainThreadInitDone) {
return;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698