| OLD | NEW |
| 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.net.impl; | 5 package org.chromium.net.impl; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 | 10 |
| 11 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
| 12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
| 13 import org.chromium.base.VisibleForTesting; | 13 import org.chromium.base.VisibleForTesting; |
| 14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.net.CronetEngine; | |
| 16 import org.chromium.net.NetworkChangeNotifier; | 15 import org.chromium.net.NetworkChangeNotifier; |
| 17 | 16 |
| 18 /** | 17 /** |
| 19 * CronetLibraryLoader loads and initializes native library on main thread. | 18 * CronetLibraryLoader loads and initializes native library on main thread. |
| 20 */ | 19 */ |
| 21 @JNINamespace("cronet") | 20 @JNINamespace("cronet") |
| 22 @VisibleForTesting | 21 @VisibleForTesting |
| 23 public class CronetLibraryLoader { | 22 public class CronetLibraryLoader { |
| 24 // Synchronize initialization. | 23 // Synchronize initialization. |
| 25 private static final Object sLoadLock = new Object(); | 24 private static final Object sLoadLock = new Object(); |
| 26 private static final String TAG = "CronetLibraryLoader"; | 25 private static final String TAG = "CronetLibraryLoader"; |
| 27 // Has library loading commenced? Setting guarded by sLoadLock. | 26 // Has library loading commenced? Setting guarded by sLoadLock. |
| 28 private static volatile boolean sInitStarted = false; | 27 private static volatile boolean sInitStarted = false; |
| 29 // Has ensureMainThreadInitialized() completed? Only accessed on main threa
d. | 28 // Has ensureMainThreadInitialized() completed? Only accessed on main threa
d. |
| 30 private static boolean sMainThreadInitDone = false; | 29 private static boolean sMainThreadInitDone = false; |
| 31 | 30 |
| 32 /** | 31 /** |
| 33 * Ensure that native library is loaded and initialized. Can be called from | 32 * Ensure that native library is loaded and initialized. Can be called from |
| 34 * any thread, the load and initialization is performed on main thread. | 33 * any thread, the load and initialization is performed on main thread. |
| 35 */ | 34 */ |
| 36 public static void ensureInitialized( | 35 public static void ensureInitialized( |
| 37 final Context context, final CronetEngine.Builder builder) { | 36 final Context context, final CronetEngineBuilderImpl builder) { |
| 38 synchronized (sLoadLock) { | 37 synchronized (sLoadLock) { |
| 39 if (sInitStarted) { | 38 if (sInitStarted) { |
| 40 return; | 39 return; |
| 41 } | 40 } |
| 42 sInitStarted = true; | 41 sInitStarted = true; |
| 43 ContextUtils.initApplicationContext(context.getApplicationContext())
; | 42 ContextUtils.initApplicationContext(context.getApplicationContext())
; |
| 44 if (builder.libraryLoader() != null) { | 43 if (builder.libraryLoader() != null) { |
| 45 builder.libraryLoader().loadLibrary(builder.libraryName()); | 44 builder.libraryLoader().loadLibrary(builder.libraryName()); |
| 46 } else { | 45 } else { |
| 47 System.loadLibrary(builder.libraryName()); | 46 System.loadLibrary(builder.libraryName()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // the undesired initial network change observer notification, which | 94 // the undesired initial network change observer notification, which |
| 96 // will cause active requests to fail with ERR_NETWORK_CHANGED. | 95 // will cause active requests to fail with ERR_NETWORK_CHANGED. |
| 97 nativeCronetInitOnMainThread(); | 96 nativeCronetInitOnMainThread(); |
| 98 sMainThreadInitDone = true; | 97 sMainThreadInitDone = true; |
| 99 } | 98 } |
| 100 | 99 |
| 101 // Native methods are implemented in cronet_library_loader.cc. | 100 // Native methods are implemented in cronet_library_loader.cc. |
| 102 private static native void nativeCronetInitOnMainThread(); | 101 private static native void nativeCronetInitOnMainThread(); |
| 103 private static native String nativeGetCronetVersion(); | 102 private static native String nativeGetCronetVersion(); |
| 104 } | 103 } |
| OLD | NEW |