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; | 5 package org.chromium.net; |
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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 /** | 27 /** |
28 * Ensure that native library is loaded and initialized. Can be called from | 28 * Ensure that native library is loaded and initialized. Can be called from |
29 * any thread, the load and initialization is performed on main thread. | 29 * any thread, the load and initialization is performed on main thread. |
30 */ | 30 */ |
31 public static void ensureInitialized( | 31 public static void ensureInitialized( |
32 final Context context, final CronetEngine.Builder builder) { | 32 final Context context, final CronetEngine.Builder builder) { |
33 synchronized (sLoadLock) { | 33 synchronized (sLoadLock) { |
34 if (sInitTaskPosted) { | 34 if (sInitTaskPosted) { |
35 return; | 35 return; |
36 } | 36 } |
37 ContextUtils.initApplicationContext(context.getApplicationContext())
; | |
38 builder.loadLibrary(); | 37 builder.loadLibrary(); |
39 ContextUtils.initApplicationContextForNative(); | |
40 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) { | 38 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) { |
41 throw new RuntimeException(String.format( | 39 throw new RuntimeException(String.format( |
42 "Expected Cronet version number %s, " | 40 "Expected Cronet version number %s, " |
43 + "actual version number %s.", | 41 + "actual version number %s.", |
44 Version.CRONET_VERSION, | 42 Version.CRONET_VERSION, |
45 nativeGetCronetVersion())); | 43 nativeGetCronetVersion())); |
46 } | 44 } |
47 Log.i(TAG, "Cronet version: %s, arch: %s", | 45 Log.i(TAG, "Cronet version: %s, arch: %s", |
48 Version.CRONET_VERSION, System.getProperty("os.arch")); | 46 Version.CRONET_VERSION, System.getProperty("os.arch")); |
| 47 ContextUtils.initApplicationContext(context.getApplicationContext())
; |
49 // Init native Chromium CronetEngine on Main UI thread. | 48 // Init native Chromium CronetEngine on Main UI thread. |
50 Runnable task = new Runnable() { | 49 Runnable task = new Runnable() { |
51 @Override | |
52 public void run() { | 50 public void run() { |
53 initOnMainThread(context); | 51 initOnMainThread(context); |
54 } | 52 } |
55 }; | 53 }; |
56 // Run task immediately or post it to the UI thread. | 54 // Run task immediately or post it to the UI thread. |
57 if (Looper.getMainLooper() == Looper.myLooper()) { | 55 if (Looper.getMainLooper() == Looper.myLooper()) { |
58 task.run(); | 56 task.run(); |
59 } else { | 57 } else { |
60 // The initOnMainThread will complete on the main thread prior | 58 // The initOnMainThread will complete on the main thread prior |
61 // to other tasks posted to the main thread. | 59 // to other tasks posted to the main thread. |
(...skipping 15 matching lines...) Expand all Loading... |
77 // NetworkChangeNotifierAndroid is created, so as to avoid receiving | 75 // NetworkChangeNotifierAndroid is created, so as to avoid receiving |
78 // the undesired initial network change observer notification, which | 76 // the undesired initial network change observer notification, which |
79 // will cause active requests to fail with ERR_NETWORK_CHANGED. | 77 // will cause active requests to fail with ERR_NETWORK_CHANGED. |
80 nativeCronetInitOnMainThread(); | 78 nativeCronetInitOnMainThread(); |
81 } | 79 } |
82 | 80 |
83 // Native methods are implemented in cronet_library_loader.cc. | 81 // Native methods are implemented in cronet_library_loader.cc. |
84 private static native void nativeCronetInitOnMainThread(); | 82 private static native void nativeCronetInitOnMainThread(); |
85 private static native String nativeGetCronetVersion(); | 83 private static native String nativeGetCronetVersion(); |
86 } | 84 } |
OLD | NEW |