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

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

Issue 1407233017: Define a Java-side global application context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo changes to ApplicationStatus Created 5 years 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
11 import org.chromium.base.ContextUtils;
11 import org.chromium.base.annotations.JNINamespace; 12 import org.chromium.base.annotations.JNINamespace;
12 13
13 /** 14 /**
14 * CronetLibraryLoader loads and initializes native library on main thread. 15 * CronetLibraryLoader loads and initializes native library on main thread.
15 */ 16 */
16 @JNINamespace("cronet") 17 @JNINamespace("cronet")
17 class CronetLibraryLoader { 18 class CronetLibraryLoader {
18 /** 19 /**
19 * Synchronize access to sInitTaskPosted and initialization routine. 20 * Synchronize access to sInitTaskPosted and initialization routine.
20 */ 21 */
(...skipping 11 matching lines...) Expand all
32 return; 33 return;
33 } 34 }
34 System.loadLibrary(builder.libraryName()); 35 System.loadLibrary(builder.libraryName());
35 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) { 36 if (!Version.CRONET_VERSION.equals(nativeGetCronetVersion())) {
36 throw new RuntimeException(String.format( 37 throw new RuntimeException(String.format(
37 "Expected Cronet version number %s, " 38 "Expected Cronet version number %s, "
38 + "actual version number %s.", 39 + "actual version number %s.",
39 Version.CRONET_VERSION, 40 Version.CRONET_VERSION,
40 nativeGetCronetVersion())); 41 nativeGetCronetVersion()));
41 } 42 }
42 nativeCronetInitApplicationContext(context.getApplicationContext()); 43 ContextUtils.initApplicationContext(context.getApplicationContext()) ;
43 // Init native Chromium CronetEngine on Main UI thread. 44 // Init native Chromium CronetEngine on Main UI thread.
44 Runnable task = new Runnable() { 45 Runnable task = new Runnable() {
45 public void run() { 46 public void run() {
46 initOnMainThread(context); 47 initOnMainThread(context);
47 } 48 }
48 }; 49 };
49 // Run task immediately or post it to the UI thread. 50 // Run task immediately or post it to the UI thread.
50 if (Looper.getMainLooper() == Looper.myLooper()) { 51 if (Looper.getMainLooper() == Looper.myLooper()) {
51 task.run(); 52 task.run();
52 } else { 53 } else {
(...skipping 15 matching lines...) Expand all
68 NetworkChangeNotifier.registerToReceiveNotificationsAlways(); 69 NetworkChangeNotifier.registerToReceiveNotificationsAlways();
69 // registerToReceiveNotificationsAlways() is called before the native 70 // registerToReceiveNotificationsAlways() is called before the native
70 // NetworkChangeNotifierAndroid is created, so as to avoid receiving 71 // NetworkChangeNotifierAndroid is created, so as to avoid receiving
71 // the undesired initial network change observer notification, which 72 // the undesired initial network change observer notification, which
72 // will cause active requests to fail with ERR_NETWORK_CHANGED. 73 // will cause active requests to fail with ERR_NETWORK_CHANGED.
73 nativeCronetInitOnMainThread(); 74 nativeCronetInitOnMainThread();
74 } 75 }
75 76
76 // Native methods are implemented in cronet_loader.cc. 77 // Native methods are implemented in cronet_loader.cc.
77 private static native void nativeCronetInitOnMainThread(); 78 private static native void nativeCronetInitOnMainThread();
78 private static native void nativeCronetInitApplicationContext(Context appCon text);
79 private static native String nativeGetCronetVersion(); 79 private static native String nativeGetCronetVersion();
80 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698