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

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

Issue 1927863004: Revert of [Cronet] Avoid crashing when CronetEngines are created on multiple threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java » ('j') | 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/CronetLibraryLoader.java
diff --git a/components/cronet/android/java/src/org/chromium/net/CronetLibraryLoader.java b/components/cronet/android/java/src/org/chromium/net/CronetLibraryLoader.java
index 59d9b326b92d59228617b6a02847d66fb900524b..0ce0b5430f2fcfe233de5cb98a9ce86e3ef0da91 100644
--- a/components/cronet/android/java/src/org/chromium/net/CronetLibraryLoader.java
+++ b/components/cronet/android/java/src/org/chromium/net/CronetLibraryLoader.java
@@ -17,24 +17,23 @@
*/
@JNINamespace("cronet")
class CronetLibraryLoader {
- // Synchronize initialization.
+ /**
+ * Synchronize access to sInitTaskPosted and initialization routine.
+ */
private static final Object sLoadLock = new Object();
private static final String TAG = "CronetLibraryLoader";
- // Has library loading commenced? Setting guarded by sLoadLock.
- private static volatile boolean sInitStarted = false;
- // Has ensureMainThreadInitialized() completed? Only accessed on main thread.
- private static boolean sMainThreadInitDone = false;
+ private static boolean sInitTaskPosted = false;
/**
* Ensure that native library is loaded and initialized. Can be called from
* any thread, the load and initialization is performed on main thread.
*/
- static void ensureInitialized(final Context context, final CronetEngine.Builder builder) {
+ public static void ensureInitialized(
+ final Context context, final CronetEngine.Builder builder) {
synchronized (sLoadLock) {
- if (sInitStarted) {
+ if (sInitTaskPosted) {
return;
}
- sInitStarted = true;
builder.loadLibrary();
if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) {
throw new RuntimeException(String.format(
@@ -49,7 +48,7 @@
// Init native Chromium CronetEngine on Main UI thread.
Runnable task = new Runnable() {
public void run() {
- ensureInitializedOnMainThread(context);
+ initOnMainThread(context);
}
};
// Run task immediately or post it to the UI thread.
@@ -60,20 +59,11 @@
// to other tasks posted to the main thread.
new Handler(Looper.getMainLooper()).post(task);
}
+ sInitTaskPosted = true;
}
}
- /**
- * Ensure that the main thread initialization has completed. Can only be called from
- * the main thread. Ensures that the NetworkChangeNotifier is initialzied and the
- * main thread native MessageLoop is initialized.
- */
- static void ensureInitializedOnMainThread(Context context) {
- assert sInitStarted;
- assert Looper.getMainLooper() == Looper.myLooper();
- if (sMainThreadInitDone) {
- return;
- }
+ private static void initOnMainThread(final Context context) {
NetworkChangeNotifier.init(context);
// Registers to always receive network notifications. Note
// that this call is fine for Cronet because Cronet
@@ -86,7 +76,6 @@
// the undesired initial network change observer notification, which
// will cause active requests to fail with ERR_NETWORK_CHANGED.
nativeCronetInitOnMainThread();
- sMainThreadInitDone = true;
}
// Native methods are implemented in cronet_library_loader.cc.
« no previous file with comments | « no previous file | components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698