OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/android/base_jni_registrar.h" | 5 #include "base/android/base_jni_registrar.h" |
6 #include "base/android/jni_android.h" | 6 #include "base/android/jni_android.h" |
7 #include "base/android/jni_registrar.h" | 7 #include "base/android/jni_registrar.h" |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/message_loop/message_loop.h" | |
9 #include "components/cronet/android/chromium_url_request.h" | 10 #include "components/cronet/android/chromium_url_request.h" |
10 #include "components/cronet/android/chromium_url_request_context.h" | 11 #include "components/cronet/android/chromium_url_request_context.h" |
11 #include "components/cronet/android/cronet_url_request.h" | 12 #include "components/cronet/android/cronet_url_request.h" |
12 #include "components/cronet/android/cronet_url_request_context.h" | 13 #include "components/cronet/android/cronet_url_request_context.h" |
13 #include "components/cronet/android/histogram_manager.h" | 14 #include "components/cronet/android/histogram_manager.h" |
15 #include "jni/CronetLibraryLoader_jni.h" | |
14 #include "net/android/net_jni_registrar.h" | 16 #include "net/android/net_jni_registrar.h" |
17 #include "net/android/network_change_notifier_factory_android.h" | |
18 #include "net/base/network_change_notifier.h" | |
15 #include "url/android/url_jni_registrar.h" | 19 #include "url/android/url_jni_registrar.h" |
16 #include "url/url_util.h" | 20 #include "url/url_util.h" |
17 | 21 |
18 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID) | 22 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID) |
19 #include "base/i18n/icu_util.h" | 23 #include "base/i18n/icu_util.h" |
20 #endif | 24 #endif |
21 | 25 |
22 namespace cronet { | 26 namespace cronet { |
23 namespace { | 27 namespace { |
24 | 28 |
25 const base::android::RegistrationMethod kCronetRegisteredMethods[] = { | 29 const base::android::RegistrationMethod kCronetRegisteredMethods[] = { |
26 {"BaseAndroid", base::android::RegisterJni}, | 30 {"BaseAndroid", base::android::RegisterJni}, |
27 {"ChromiumUrlRequest", cronet::ChromiumUrlRequestRegisterJni}, | 31 {"ChromiumUrlRequest", cronet::ChromiumUrlRequestRegisterJni}, |
mmenke
2015/01/23 20:41:41
We're in the cronet namespace. All of these crone
mef
2015/01/28 21:32:27
Done.
| |
28 {"ChromiumUrlRequestContext", cronet::ChromiumUrlRequestContextRegisterJni}, | 32 {"ChromiumUrlRequestContext", cronet::ChromiumUrlRequestContextRegisterJni}, |
33 {"CronetLibraryLoader", cronet::RegisterNativesImpl}, | |
29 {"CronetUrlRequest", cronet::CronetUrlRequestRegisterJni}, | 34 {"CronetUrlRequest", cronet::CronetUrlRequestRegisterJni}, |
30 {"CronetUrlRequestContext", cronet::CronetUrlRequestContextRegisterJni}, | 35 {"CronetUrlRequestContext", cronet::CronetUrlRequestContextRegisterJni}, |
31 {"HistogramManager", cronet::HistogramManagerRegisterJni}, | 36 {"HistogramManager", cronet::HistogramManagerRegisterJni}, |
32 {"NetAndroid", net::android::RegisterJni}, | 37 {"NetAndroid", net::android::RegisterJni}, |
33 {"UrlAndroid", url::android::RegisterJni}, | 38 {"UrlAndroid", url::android::RegisterJni}, |
34 }; | 39 }; |
35 | 40 |
36 base::AtExitManager* g_at_exit_manager = NULL; | 41 base::AtExitManager* g_at_exit_manager = NULL; |
42 // MessageLoop on the main thread, which is where objects that receive Java | |
43 // notifications generally live. | |
44 base::MessageLoop* g_main_message_loop = nullptr; | |
45 | |
46 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; | |
37 | 47 |
38 } // namespace | 48 } // namespace |
39 | 49 |
40 // Checks the available version of JNI. Also, caches Java reflection artifacts. | 50 // Checks the available version of JNI. Also, caches Java reflection artifacts. |
41 jint CronetOnLoad(JavaVM* vm, void* reserved) { | 51 jint CronetOnLoad(JavaVM* vm, void* reserved) { |
42 JNIEnv* env; | 52 JNIEnv* env; |
43 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { | 53 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
44 return -1; | 54 return -1; |
45 } | 55 } |
46 | 56 |
(...skipping 15 matching lines...) Expand all Loading... | |
62 return JNI_VERSION_1_6; | 72 return JNI_VERSION_1_6; |
63 } | 73 } |
64 | 74 |
65 void CronetOnUnLoad(JavaVM* jvm, void* reserved) { | 75 void CronetOnUnLoad(JavaVM* jvm, void* reserved) { |
66 if (g_at_exit_manager) { | 76 if (g_at_exit_manager) { |
67 delete g_at_exit_manager; | 77 delete g_at_exit_manager; |
68 g_at_exit_manager = NULL; | 78 g_at_exit_manager = NULL; |
69 } | 79 } |
70 } | 80 } |
71 | 81 |
82 jlong CronetInitOnMainThread(JNIEnv* env, jclass jcaller, jobject jcontext) { | |
83 // Set application context. | |
84 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, jcontext); | |
85 base::android::InitApplicationContext(env, scoped_context); | |
86 #if !defined(USE_ICU_ALTERNATIVES_ON_ANDROID) | |
87 base::i18n::InitializeICU(); | |
mmenke
2015/01/23 20:41:41
I don't think we need to initialize this both here
mef
2015/01/28 21:32:27
Done.
mef
2015/01/28 22:30:57
It turns out that initializing it here instead of
| |
88 #endif | |
89 | |
90 if (!base::MessageLoop::current()) { | |
mmenke
2015/01/23 20:41:41
Is there any case where this will have been initia
mef
2015/01/28 21:32:27
I can't think of any reason to call this method tw
| |
91 DCHECK(!g_main_message_loop); | |
92 g_main_message_loop = new base::MessageLoopForUI(); | |
93 base::MessageLoopForUI::current()->Start(); | |
94 } | |
95 DCHECK_EQ(g_main_message_loop, base::MessageLoop::current()); | |
96 if (!g_network_change_notifier) { | |
97 net::NetworkChangeNotifier::SetFactory( | |
98 new net::NetworkChangeNotifierFactoryAndroid()); | |
99 g_network_change_notifier = net::NetworkChangeNotifier::Create(); | |
100 } | |
101 | |
102 return 0; | |
103 } | |
104 | |
72 } // namespace cronet | 105 } // namespace cronet |
OLD | NEW |