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

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

Issue 1936093002: Reland 2 of Unify application context usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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 unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 /** 28 /**
29 * Ensure that native library is loaded and initialized. Can be called from 29 * Ensure that native library is loaded and initialized. Can be called from
30 * any thread, the load and initialization is performed on main thread. 30 * any thread, the load and initialization is performed on main thread.
31 */ 31 */
32 static void ensureInitialized(final Context context, final CronetEngine.Buil der builder) { 32 static void ensureInitialized(final Context context, final CronetEngine.Buil der builder) {
33 synchronized (sLoadLock) { 33 synchronized (sLoadLock) {
34 if (sInitStarted) { 34 if (sInitStarted) {
35 return; 35 return;
36 } 36 }
37 sInitStarted = true; 37 sInitStarted = true;
38 ContextUtils.initApplicationContext(context.getApplicationContext()) ;
38 builder.loadLibrary(); 39 builder.loadLibrary();
40 ContextUtils.initApplicationContextForNative();
39 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) { 41 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) {
40 throw new RuntimeException(String.format( 42 throw new RuntimeException(String.format(
41 "Expected Cronet version number %s, " 43 "Expected Cronet version number %s, "
42 + "actual version number %s.", 44 + "actual version number %s.",
43 Version.CRONET_VERSION, 45 Version.CRONET_VERSION,
44 nativeGetCronetVersion())); 46 nativeGetCronetVersion()));
45 } 47 }
46 Log.i(TAG, "Cronet version: %s, arch: %s", 48 Log.i(TAG, "Cronet version: %s, arch: %s",
47 Version.CRONET_VERSION, System.getProperty("os.arch")); 49 Version.CRONET_VERSION, System.getProperty("os.arch"));
48 ContextUtils.initApplicationContext(context.getApplicationContext()) ;
49 // Init native Chromium CronetEngine on Main UI thread. 50 // Init native Chromium CronetEngine on Main UI thread.
50 Runnable task = new Runnable() { 51 Runnable task = new Runnable() {
52 @Override
51 public void run() { 53 public void run() {
52 ensureInitializedOnMainThread(context); 54 ensureInitializedOnMainThread(context);
53 } 55 }
54 }; 56 };
55 // Run task immediately or post it to the UI thread. 57 // Run task immediately or post it to the UI thread.
56 if (Looper.getMainLooper() == Looper.myLooper()) { 58 if (Looper.getMainLooper() == Looper.myLooper()) {
57 task.run(); 59 task.run();
58 } else { 60 } else {
59 // The initOnMainThread will complete on the main thread prior 61 // The initOnMainThread will complete on the main thread prior
60 // to other tasks posted to the main thread. 62 // to other tasks posted to the main thread.
(...skipping 25 matching lines...) Expand all
86 // the undesired initial network change observer notification, which 88 // the undesired initial network change observer notification, which
87 // will cause active requests to fail with ERR_NETWORK_CHANGED. 89 // will cause active requests to fail with ERR_NETWORK_CHANGED.
88 nativeCronetInitOnMainThread(); 90 nativeCronetInitOnMainThread();
89 sMainThreadInitDone = true; 91 sMainThreadInitDone = true;
90 } 92 }
91 93
92 // Native methods are implemented in cronet_library_loader.cc. 94 // Native methods are implemented in cronet_library_loader.cc.
93 private static native void nativeCronetInitOnMainThread(); 95 private static native void nativeCronetInitOnMainThread();
94 private static native String nativeGetCronetVersion(); 96 private static native String nativeGetCronetVersion();
95 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698