Chromium Code Reviews| Index: components/cronet/android/cronet_loader.cc |
| diff --git a/components/cronet/android/cronet_loader.cc b/components/cronet/android/cronet_loader.cc |
| index 3929b6cb516af3639a92de51f03f51aabe0fdc02..34799c0edc41da76eead8456e1a2f45cfce08eae 100644 |
| --- a/components/cronet/android/cronet_loader.cc |
| +++ b/components/cronet/android/cronet_loader.cc |
| @@ -6,12 +6,16 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_registrar.h" |
| #include "base/at_exit.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "components/cronet/android/chromium_url_request.h" |
| #include "components/cronet/android/chromium_url_request_context.h" |
| #include "components/cronet/android/cronet_url_request.h" |
| #include "components/cronet/android/cronet_url_request_context.h" |
| #include "components/cronet/android/histogram_manager.h" |
| +#include "jni/CronetLibraryLoader_jni.h" |
| #include "net/android/net_jni_registrar.h" |
| +#include "net/android/network_change_notifier_factory_android.h" |
| +#include "net/base/network_change_notifier.h" |
| #include "url/android/url_jni_registrar.h" |
| #include "url/url_util.h" |
| @@ -26,6 +30,7 @@ const base::android::RegistrationMethod kCronetRegisteredMethods[] = { |
| {"BaseAndroid", base::android::RegisterJni}, |
| {"ChromiumUrlRequest", cronet::ChromiumUrlRequestRegisterJni}, |
| {"ChromiumUrlRequestContext", cronet::ChromiumUrlRequestContextRegisterJni}, |
| + {"CronetLibraryLoader", cronet::RegisterNativesImpl}, |
| {"CronetUrlRequest", cronet::CronetUrlRequestRegisterJni}, |
| {"CronetUrlRequestContext", cronet::CronetUrlRequestContextRegisterJni}, |
| {"HistogramManager", cronet::HistogramManagerRegisterJni}, |
| @@ -34,6 +39,11 @@ const base::android::RegistrationMethod kCronetRegisteredMethods[] = { |
| }; |
| base::AtExitManager* g_at_exit_manager = NULL; |
| +// MessageLoop on the main thread, which is where objects that receive Java |
| +// notifications generally live. |
| +base::MessageLoop* g_main_message_loop = nullptr; |
| + |
| +net::NetworkChangeNotifier* g_network_change_notifier = nullptr; |
| } // namespace |
| @@ -69,4 +79,27 @@ void CronetOnUnLoad(JavaVM* jvm, void* reserved) { |
| } |
| } |
| +jlong CronetInitOnMainThread(JNIEnv* env, jclass jcaller, jobject jcontext) { |
| + // Set application context. |
| + base::android::ScopedJavaLocalRef<jobject> scoped_context(env, jcontext); |
| + base::android::InitApplicationContext(env, scoped_context); |
| +#if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID) |
| + base::i18n::InitializeICU(); |
|
mmenke
2015/01/08 19:06:16
Don't think we need to do this twice, and we're al
mef
2015/01/08 21:17:02
Done.
|
| +#endif |
| + |
| + if (!base::MessageLoop::current()) { |
| + DCHECK(!g_main_message_loop); |
| + g_main_message_loop = new base::MessageLoopForUI(); |
| + base::MessageLoopForUI::current()->Start(); |
|
mmenke
2015/01/08 19:06:16
What code depends on the main Java thread having a
mef
2015/01/08 21:17:02
Helen will correct me if I'm wrong, but my underst
xunjieli
2015/01/08 21:34:24
Yes, we need to set up a message loop for the main
|
| + } |
| + DCHECK_EQ(g_main_message_loop, base::MessageLoop::current()); |
| + if (!g_network_change_notifier) { |
| + net::NetworkChangeNotifier::SetFactory( |
| + new net::NetworkChangeNotifierFactoryAndroid()); |
| + g_network_change_notifier = net::NetworkChangeNotifier::Create(); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| } // namespace cronet |