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

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

Issue 1879013002: 🍈 Unify application context usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove @CalledByNative 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 16 matching lines...) Expand all
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()) ;
37 builder.loadLibrary(); 38 builder.loadLibrary();
38 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) { 39 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) {
39 throw new RuntimeException(String.format( 40 throw new RuntimeException(String.format(
40 "Expected Cronet version number %s, " 41 "Expected Cronet version number %s, "
41 + "actual version number %s.", 42 + "actual version number %s.",
42 Version.CRONET_VERSION, 43 Version.CRONET_VERSION,
43 nativeGetCronetVersion())); 44 nativeGetCronetVersion()));
44 } 45 }
45 Log.i(TAG, "Cronet version: %s, arch: %s", 46 Log.i(TAG, "Cronet version: %s, arch: %s",
46 Version.CRONET_VERSION, System.getProperty("os.arch")); 47 Version.CRONET_VERSION, System.getProperty("os.arch"));
47 ContextUtils.initApplicationContext(context.getApplicationContext()) ;
48 // Init native Chromium CronetEngine on Main UI thread. 48 // Init native Chromium CronetEngine on Main UI thread.
49 Runnable task = new Runnable() { 49 Runnable task = new Runnable() {
50 @Override
50 public void run() { 51 public void run() {
51 initOnMainThread(context); 52 initOnMainThread(context);
52 } 53 }
53 }; 54 };
54 // Run task immediately or post it to the UI thread. 55 // Run task immediately or post it to the UI thread.
55 if (Looper.getMainLooper() == Looper.myLooper()) { 56 if (Looper.getMainLooper() == Looper.myLooper()) {
56 task.run(); 57 task.run();
57 } else { 58 } else {
58 // The initOnMainThread will complete on the main thread prior 59 // The initOnMainThread will complete on the main thread prior
59 // to other tasks posted to the main thread. 60 // to other tasks posted to the main thread.
(...skipping 15 matching lines...) Expand all
75 // NetworkChangeNotifierAndroid is created, so as to avoid receiving 76 // NetworkChangeNotifierAndroid is created, so as to avoid receiving
76 // the undesired initial network change observer notification, which 77 // the undesired initial network change observer notification, which
77 // will cause active requests to fail with ERR_NETWORK_CHANGED. 78 // will cause active requests to fail with ERR_NETWORK_CHANGED.
78 nativeCronetInitOnMainThread(); 79 nativeCronetInitOnMainThread();
79 } 80 }
80 81
81 // Native methods are implemented in cronet_library_loader.cc. 82 // Native methods are implemented in cronet_library_loader.cc.
82 private static native void nativeCronetInitOnMainThread(); 83 private static native void nativeCronetInitOnMainThread();
83 private static native String nativeGetCronetVersion(); 84 private static native String nativeGetCronetVersion();
84 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698