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

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: update tests to account for mRegistered change Created 3 years, 7 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 e4d6b1a2819618ce7fd89c465100e348d17a251a..d31d6d27a8bdb2ad7b7fe8a7684f1aacd4b741ea 100644
--- a/components/cronet/android/cronet_library_loader.cc
+++ b/components/cronet/android/cronet_library_loader.cc
@@ -53,9 +53,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;
@@ -76,6 +76,11 @@ bool NativeInit() {
} // namespace
+bool OnInitThread() {
+ DCHECK(g_init_message_loop);
+ 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);
@@ -91,7 +96,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
@@ -101,9 +106,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());
« no previous file with comments | « components/cronet/android/cronet_library_loader.h ('k') | components/cronet/android/cronet_url_request_context_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698