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

Unified Diff: components/cronet/android/cronet_library_loader.cc

Issue 2812963002: [Cronet] Move initialization to a new thread rather than the UI thread. (Closed)
Patch Set: mostly renaming Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_library_loader.cc
diff --git a/components/cronet/android/cronet_library_loader.cc b/components/cronet/android/cronet_library_loader.cc
index 6d4d11730c8c0cd7adb5e4f8711007a5841d9e15..6239785e6fd5d8d0cff54f9c03af703fab9b5a18 100644
--- a/components/cronet/android/cronet_library_loader.cc
+++ b/components/cronet/android/cronet_library_loader.cc
@@ -52,9 +52,9 @@ const base::android::RegistrationMethod kCronetRegisteredMethods[] = {
{"NetAndroid", net::android::RegisterJni},
};
-// MessageLoop on the main thread, which is where objects that receive Java
+// MessageLoop on the init thread, which is where objects that receive Java
// notifications generally live.
-base::MessageLoop* g_main_message_loop = nullptr;
+base::MessageLoop* g_init_message_loop = nullptr;
net::NetworkChangeNotifier* g_network_change_notifier = nullptr;
@@ -72,6 +72,10 @@ bool NativeInit() {
} // namespace
+bool OnInitThread() {
xunjieli 2017/04/13 18:44:54 This global static function will return true if g_
pauljensen 2017/05/01 15:35:53 Done.
+ return g_init_message_loop == base::MessageLoop::current();
+}
+
// Checks the available version of JNI. Also, caches Java reflection artifacts.
jint CronetOnLoad(JavaVM* vm, void* reserved) {
base::android::InitVM(vm);
@@ -87,7 +91,7 @@ void CronetOnUnLoad(JavaVM* jvm, void* reserved) {
base::android::LibraryLoaderExitHook();
}
-void CronetInitOnMainThread(JNIEnv* env, const JavaParamRef<jclass>& jcaller) {
+void CronetInitOnInitThread(JNIEnv* env, const JavaParamRef<jclass>& jcaller) {
#if !BUILDFLAG(USE_PLATFORM_ICU_ALTERNATIVES)
base::i18n::InitializeICU();
#endif
@@ -97,9 +101,8 @@ void CronetInitOnMainThread(JNIEnv* env, const JavaParamRef<jclass>& jcaller) {
// configuration information.
base::CommandLine::Init(0, nullptr);
DCHECK(!base::MessageLoop::current());
- DCHECK(!g_main_message_loop);
- g_main_message_loop = new base::MessageLoopForUI();
- base::MessageLoopForUI::current()->Start();
+ DCHECK(!g_init_message_loop);
+ g_init_message_loop = new base::MessageLoop();
DCHECK(!g_network_change_notifier);
net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid());

Powered by Google App Engine
This is Rietveld 408576698