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

Side by Side Diff: base/android/jni_android.cc

Issue 2501193003: Selectively perform JNI registration in render processes on Android. (Closed)
Patch Set: Conditionally register JNI based on process type. Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/jni_android.h" 5 #include "base/android/jni_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/android/build_info.h" 11 #include "base/android/build_info.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/android/jni_utils.h" 13 #include "base/android/jni_utils.h"
14 #include "base/android/library_loader/library_loader_hooks.h"
14 #include "base/debug/debugging_flags.h" 15 #include "base/debug/debugging_flags.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/threading/thread_local.h" 18 #include "base/threading/thread_local.h"
18 19
19 namespace { 20 namespace {
20 using base::android::GetClass; 21 using base::android::GetClass;
21 using base::android::MethodID; 22 using base::android::MethodID;
22 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
23 24
24 bool g_disable_manual_jni_registration = false; 25 base::android::JniRegistrationType g_jni_registration_type =
26 base::android::UNINITIALIZED_JNI_REGISTRATION;
25 27
26 JavaVM* g_jvm = NULL; 28 JavaVM* g_jvm = NULL;
27 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky 29 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky
28 g_class_loader = LAZY_INSTANCE_INITIALIZER; 30 g_class_loader = LAZY_INSTANCE_INITIALIZER;
29 jmethodID g_class_loader_load_class_method_id = 0; 31 jmethodID g_class_loader_load_class_method_id = 0;
30 32
31 #if BUILDFLAG(ENABLE_PROFILING) && HAVE_TRACE_STACK_FRAME_POINTERS 33 #if BUILDFLAG(ENABLE_PROFILING) && HAVE_TRACE_STACK_FRAME_POINTERS
32 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky 34 base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky
33 g_stack_frame_pointer = LAZY_INSTANCE_INITIALIZER; 35 g_stack_frame_pointer = LAZY_INSTANCE_INITIALIZER;
34 #endif 36 #endif
35 37
36 } // namespace 38 } // namespace
37 39
38 namespace base { 40 namespace base {
39 namespace android { 41 namespace android {
40 42
41 bool IsManualJniRegistrationDisabled() { 43 void InitJniRegistrationType(JNIEnv* env, bool force_registration) {
Torne 2017/01/12 13:48:06 I assume you have force_registration here to handl
42 return g_disable_manual_jni_registration; 44 if (force_registration) {
45 g_jni_registration_type = ALL_JNI_REGISTRATION;
46 return;
47 }
48 DCHECK(g_jni_registration_type == UNINITIALIZED_JNI_REGISTRATION);
49 switch (GetLibraryProcessType(env)) {
50 case PROCESS_WEBVIEW:
51 case PROCESS_WEBVIEW_CHILD:
52 g_jni_registration_type = NO_JNI_REGISTRATION;
53 break;
54 case PROCESS_BROWSER:
55 g_jni_registration_type = ALL_JNI_REGISTRATION;
56 break;
57 case PROCESS_CHILD:
58 g_jni_registration_type = SELECTIVE_JNI_REGISTRATION;
59 break;
60 default:
61 NOTREACHED();
62 }
43 } 63 }
44 64
45 void DisableManualJniRegistration() { 65 JniRegistrationType GetJniRegistrationType() {
46 DCHECK(!g_disable_manual_jni_registration); 66 return g_jni_registration_type;
47 g_disable_manual_jni_registration = true;
48 } 67 }
49 68
50 JNIEnv* AttachCurrentThread() { 69 JNIEnv* AttachCurrentThread() {
51 DCHECK(g_jvm); 70 DCHECK(g_jvm);
52 JNIEnv* env = NULL; 71 JNIEnv* env = NULL;
53 jint ret = g_jvm->AttachCurrentThread(&env, NULL); 72 jint ret = g_jvm->AttachCurrentThread(&env, NULL);
54 DCHECK_EQ(JNI_OK, ret); 73 DCHECK_EQ(JNI_OK, ret);
55 return env; 74 return env;
56 } 75 }
57 76
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 320 }
302 321
303 void* JNIStackFrameSaver::SavedFrame() { 322 void* JNIStackFrameSaver::SavedFrame() {
304 return g_stack_frame_pointer.Pointer()->Get(); 323 return g_stack_frame_pointer.Pointer()->Get();
305 } 324 }
306 325
307 #endif // ENABLE_PROFILING && HAVE_TRACE_STACK_FRAME_POINTERS 326 #endif // ENABLE_PROFILING && HAVE_TRACE_STACK_FRAME_POINTERS
308 327
309 } // namespace android 328 } // namespace android
310 } // namespace base 329 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698