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

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

Issue 726013002: [Cronet] Hook up library loader, system proxy and network change notifier to async api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests. Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.net;
6
7 import android.content.Context;
8 import android.os.Handler;
9 import android.os.Looper;
10
11 import org.chromium.base.JNINamespace;
12
13 /**
14 * CronetLibraryLoader loads and initializes native library on main thread.
15 */
16 @JNINamespace("cronet")
17 class CronetLibraryLoader {
xunjieli 2015/02/05 19:47:49 One last request. How about changing CronetLibrary
mef 2015/02/05 20:31:06 Done. I've renamed the cc file as I think CronetLo
18 /**
19 * Synchronize access to sInitTaskPosted and initialization routine.
20 */
21 private static final Object sLoadLock = new Object();
22 private static boolean sInitTaskPosted = false;
23
24 /**
25 * Ensure that native library is loaded and initialized. Can be called from
26 * any thread, the load and initialization is performed on main thread.
27 */
28 public static void ensureInitialized(
29 final Context context, final UrlRequestContextConfig config) {
30 synchronized (sLoadLock) {
31 if (sInitTaskPosted) {
32 return;
33 }
34 System.loadLibrary(config.libraryName());
35 // Init native Chromium URLRequestContext on Main UI thread.
36 Runnable task = new Runnable() {
37 public void run() {
38 initOnMainThread(context);
39 }
40 };
41 // Run task immediately or post it to the UI thread.
42 if (Looper.getMainLooper() == Looper.myLooper()) {
43 task.run();
44 } else {
45 // The initOnMainThread will complete on the main thread prior
46 // to other tasks posted to the main thread.
47 new Handler(Looper.getMainLooper()).post(task);
48 }
49 sInitTaskPosted = true;
50 }
51 }
52
53 private static void initOnMainThread(final Context context) {
54 NetworkChangeNotifier.init(context);
55 // Registers to always receive network notifications. Note
56 // that this call is fine for Cronet because Cronet
57 // embedders do not have API access to create network change
58 // observers. Existing observers in the net stack do not
59 // perform expensive work.
60 NetworkChangeNotifier.registerToReceiveNotificationsAlways();
61 nativeCronetInitOnMainThread(context);
62 }
63
64 // Native methods are implemented in cronet_loader.cc.
65 private static native void nativeCronetInitOnMainThread(Context context);
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698