| 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.NetworkChangeNotifier; | 15 import org.chromium.net.NetworkChangeNotifier; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * CronetLibraryLoader loads and initializes native library on main thread. | 18 * CronetLibraryLoader loads and initializes native library on main thread. |
| 19 */ | 19 */ |
| 20 @JNINamespace("cronet") | 20 @JNINamespace("cronet") |
| 21 @VisibleForTesting | 21 @VisibleForTesting |
| 22 public class CronetLibraryLoader { | 22 public class CronetLibraryLoader { |
| 23 // Synchronize initialization. | 23 // Synchronize initialization. |
| 24 private static final Object sLoadLock = new Object(); | 24 private static final Object sLoadLock = new Object(); |
| 25 private static final String LIBRARY_NAME = "cronet"; | 25 private static final String LIBRARY_NAME = "cronet." + ImplVersion.getCronet
Version(); |
| 26 private static final String TAG = CronetLibraryLoader.class.getSimpleName(); | 26 private static final String TAG = CronetLibraryLoader.class.getSimpleName(); |
| 27 // Has library loading commenced? Setting guarded by sLoadLock. | 27 // Has library loading commenced? Setting guarded by sLoadLock. |
| 28 private static volatile boolean sLibraryLoaded = false; | 28 private static volatile boolean sLibraryLoaded = false; |
| 29 // Has ensureMainThreadInitialized() completed? Only accessed on main threa
d. | 29 // Has ensureMainThreadInitialized() completed? Only accessed on main threa
d. |
| 30 private static volatile boolean sMainThreadInitDone = false; | 30 private static volatile boolean sMainThreadInitDone = false; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Ensure that native library is loaded and initialized. Can be called from | 33 * Ensure that native library is loaded and initialized. Can be called from |
| 34 * any thread, the load and initialization is performed on main thread. | 34 * any thread, the load and initialization is performed on main thread. |
| 35 */ | 35 */ |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // the undesired initial network change observer notification, which | 98 // the undesired initial network change observer notification, which |
| 99 // will cause active requests to fail with ERR_NETWORK_CHANGED. | 99 // will cause active requests to fail with ERR_NETWORK_CHANGED. |
| 100 nativeCronetInitOnMainThread(); | 100 nativeCronetInitOnMainThread(); |
| 101 sMainThreadInitDone = true; | 101 sMainThreadInitDone = true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Native methods are implemented in cronet_library_loader.cc. | 104 // Native methods are implemented in cronet_library_loader.cc. |
| 105 private static native void nativeCronetInitOnMainThread(); | 105 private static native void nativeCronetInitOnMainThread(); |
| 106 private static native String nativeGetCronetVersion(); | 106 private static native String nativeGetCronetVersion(); |
| 107 } | 107 } |
| OLD | NEW |