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

Side by Side Diff: components/cronet/android/cronet_library_loader.cc

Issue 2620303004: Remove JNI onload callback vector construction in favour of direct calls. (Closed)
Patch Set: rebase compile errors Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 "components/cronet/android/cronet_library_loader.h" 5 #include "components/cronet/android/cronet_library_loader.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/android/base_jni_onload.h" 10 #include "base/android/base_jni_onload.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // notifications generally live. 56 // notifications generally live.
57 base::MessageLoop* g_main_message_loop = nullptr; 57 base::MessageLoop* g_main_message_loop = nullptr;
58 58
59 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; 59 net::NetworkChangeNotifier* g_network_change_notifier = nullptr;
60 60
61 bool RegisterJNI(JNIEnv* env) { 61 bool RegisterJNI(JNIEnv* env) {
62 return base::android::RegisterNativeMethods( 62 return base::android::RegisterNativeMethods(
63 env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods)); 63 env, kCronetRegisteredMethods, arraysize(kCronetRegisteredMethods));
64 } 64 }
65 65
66 bool Init() { 66 bool NativeInit() {
67 if (!base::android::OnJNIOnLoadInit())
68 return false;
67 url::Initialize(); 69 url::Initialize();
68 return true; 70 return true;
69 } 71 }
70 72
71 } // namespace 73 } // namespace
72 74
73 // Checks the available version of JNI. Also, caches Java reflection artifacts. 75 // Checks the available version of JNI. Also, caches Java reflection artifacts.
74 jint CronetOnLoad(JavaVM* vm, void* reserved) { 76 jint CronetOnLoad(JavaVM* vm, void* reserved) {
75 std::vector<base::android::RegisterCallback> register_callbacks; 77 base::android::InitVM(vm);
76 register_callbacks.push_back(base::Bind(&RegisterJNI)); 78 JNIEnv* env = base::android::AttachCurrentThread();
77 std::vector<base::android::InitCallback> init_callbacks; 79 if (!base::android::OnJNIOnLoadRegisterJNI(env) || !RegisterJNI(env) ||
78 init_callbacks.push_back(base::Bind(&Init)); 80 !NativeInit()) {
79 if (!base::android::OnJNIOnLoadRegisterJNI(vm, register_callbacks) ||
80 !base::android::OnJNIOnLoadInit(init_callbacks)) {
81 return -1; 81 return -1;
82 } 82 }
83 return JNI_VERSION_1_6; 83 return JNI_VERSION_1_6;
84 } 84 }
85 85
86 void CronetOnUnLoad(JavaVM* jvm, void* reserved) { 86 void CronetOnUnLoad(JavaVM* jvm, void* reserved) {
87 base::android::LibraryLoaderExitHook(); 87 base::android::LibraryLoaderExitHook();
88 } 88 }
89 89
90 void CronetInitOnMainThread(JNIEnv* env, const JavaParamRef<jclass>& jcaller) { 90 void CronetInitOnMainThread(JNIEnv* env, const JavaParamRef<jclass>& jcaller) {
(...skipping 15 matching lines...) Expand all
106 g_network_change_notifier = net::NetworkChangeNotifier::Create(); 106 g_network_change_notifier = net::NetworkChangeNotifier::Create();
107 } 107 }
108 108
109 ScopedJavaLocalRef<jstring> GetCronetVersion( 109 ScopedJavaLocalRef<jstring> GetCronetVersion(
110 JNIEnv* env, 110 JNIEnv* env,
111 const JavaParamRef<jclass>& jcaller) { 111 const JavaParamRef<jclass>& jcaller) {
112 return base::android::ConvertUTF8ToJavaString(env, CRONET_VERSION); 112 return base::android::ConvertUTF8ToJavaString(env, CRONET_VERSION);
113 } 113 }
114 114
115 } // namespace cronet 115 } // namespace cronet
OLDNEW
« no previous file with comments | « chromecast/app/android/cast_jni_loader.cc ('k') | components/cronet/android/test/cronet_test_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698