Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 * Ensure that native library is loaded and initialized. Can be called from | 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. | 26 * any thread, the load and initialization is performed on main thread. |
| 27 */ | 27 */ |
| 28 public static void ensureInitialized( | 28 public static void ensureInitialized( |
| 29 final Context context, final UrlRequestContextConfig config) { | 29 final Context context, final UrlRequestContextConfig config) { |
| 30 synchronized (sLoadLock) { | 30 synchronized (sLoadLock) { |
| 31 if (sInitTaskPosted) { | 31 if (sInitTaskPosted) { |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 System.loadLibrary(config.libraryName()); | 34 System.loadLibrary(config.libraryName()); |
| 35 nativeCronetInitApplicationContext(context.getApplicationContext()); | |
| 35 // Init native Chromium URLRequestContext on Main UI thread. | 36 // Init native Chromium URLRequestContext on Main UI thread. |
| 36 Runnable task = new Runnable() { | 37 Runnable task = new Runnable() { |
| 37 public void run() { | 38 public void run() { |
| 38 initOnMainThread(context); | 39 initOnMainThread(context); |
| 39 } | 40 } |
| 40 }; | 41 }; |
| 41 // Run task immediately or post it to the UI thread. | 42 // Run task immediately or post it to the UI thread. |
| 42 if (Looper.getMainLooper() == Looper.myLooper()) { | 43 if (Looper.getMainLooper() == Looper.myLooper()) { |
| 43 task.run(); | 44 task.run(); |
| 44 } else { | 45 } else { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 // Registers to always receive network notifications. Note | 56 // Registers to always receive network notifications. Note |
| 56 // that this call is fine for Cronet because Cronet | 57 // that this call is fine for Cronet because Cronet |
| 57 // embedders do not have API access to create network change | 58 // embedders do not have API access to create network change |
| 58 // observers. Existing observers in the net stack do not | 59 // observers. Existing observers in the net stack do not |
| 59 // perform expensive work. | 60 // perform expensive work. |
| 60 NetworkChangeNotifier.registerToReceiveNotificationsAlways(); | 61 NetworkChangeNotifier.registerToReceiveNotificationsAlways(); |
| 61 // registerToReceiveNotificationsAlways() is called before the native | 62 // registerToReceiveNotificationsAlways() is called before the native |
| 62 // NetworkChangeNotifierAndroid is created, so as to avoid receiving | 63 // NetworkChangeNotifierAndroid is created, so as to avoid receiving |
| 63 // the undesired initial network change observer notification, which | 64 // the undesired initial network change observer notification, which |
| 64 // will cause active requests to fail with ERR_NETWORK_CHANGED. | 65 // will cause active requests to fail with ERR_NETWORK_CHANGED. |
| 65 nativeCronetInitOnMainThread(context.getApplicationContext()); | 66 nativeCronetInitOnMainThread(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Native methods are implemented in cronet_loader.cc. | 69 // Native methods are implemented in cronet_loader.cc. |
| 69 private static native void nativeCronetInitOnMainThread(Context appContext); | 70 private static native void nativeCronetInitOnMainThread(); |
| 71 private static native void nativeCronetInitApplicationContext(Context appCon text); | |
|
xunjieli
2015/03/09 18:13:21
nit: I feel that there are too many "Cronet" in th
pauljensen
2015/03/09 19:04:36
I didn't want to use InitApplicationContext as tha
xunjieli
2015/03/09 19:37:51
But this two are in cronet namespace, so there won
| |
| 70 } | 72 } |
| OLD | NEW |