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

Unified Diff: base/android/jni_generator/jni_generator.py

Issue 2501193003: Selectively perform JNI registration in render processes on Android. (Closed)
Patch Set: Address Ted C comments 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 side-by-side diff with in-line comments
Download patch
Index: base/android/jni_generator/jni_generator.py
diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py
index 0173a2c1172e0bf21de939fb3cd0e6fcae86e311..99d8b424f02db8a4753ba96c29cc83c66d26de9b 100755
--- a/base/android/jni_generator/jni_generator.py
+++ b/base/android/jni_generator/jni_generator.py
@@ -412,6 +412,19 @@ def ExtractNatives(contents, ptr_type):
return natives
+def IsMainDexJavaClass(contents):
+ """Returns "true" if the class is annotated with "@MainDex", "false" if not.
+
+ JNI registration doesn't always need to be completed for non-browser processes
+ since most Java code is only used by the browser process. Classes that are
+ needed by non-browser processes must explicitly be annotated with @MainDex
+ to force JNI registration.
+ """
+ re_maindex = re.compile(r'@MainDex[\s\S]*class\s+\w+\s*{')
+ found = re.search(re_maindex, contents)
+ return 'true' if found else 'false'
+
+
def GetStaticCastForReturnType(return_type):
type_map = { 'String' : 'jstring',
'java/lang/String' : 'jstring',
@@ -634,8 +647,8 @@ class JNIFromJavaP(object):
value=value.group('value')))
self.inl_header_file_generator = InlHeaderFileGenerator(
- self.namespace, self.fully_qualified_class, [],
- self.called_by_natives, self.constant_fields, options)
+ self.namespace, self.fully_qualified_class, [], self.called_by_natives,
+ self.constant_fields, options)
def GetContent(self):
return self.inl_header_file_generator.GetContent()
@@ -669,12 +682,13 @@ class JNIFromJavaSource(object):
jni_namespace = ExtractJNINamespace(contents) or options.namespace
natives = ExtractNatives(contents, options.ptr_type)
called_by_natives = ExtractCalledByNatives(contents)
+ maindex = IsMainDexJavaClass(contents)
if len(natives) == 0 and len(called_by_natives) == 0:
raise SyntaxError('Unable to find any JNI methods for %s.' %
fully_qualified_class)
inl_header_file_generator = InlHeaderFileGenerator(
- jni_namespace, fully_qualified_class, natives, called_by_natives,
- [], options)
+ jni_namespace, fully_qualified_class, natives, called_by_natives, [],
+ options, maindex)
self.content = inl_header_file_generator.GetContent()
@classmethod
@@ -710,7 +724,7 @@ class InlHeaderFileGenerator(object):
"""Generates an inline header file for JNI integration."""
def __init__(self, namespace, fully_qualified_class, natives,
- called_by_natives, constant_fields, options):
+ called_by_natives, constant_fields, options, maindex='false'):
self.namespace = namespace
self.fully_qualified_class = fully_qualified_class
self.class_name = self.fully_qualified_class.split('/')[-1]
@@ -718,6 +732,7 @@ class InlHeaderFileGenerator(object):
self.called_by_natives = called_by_natives
self.header_guard = fully_qualified_class.replace('/', '_') + '_JNI'
self.constant_fields = constant_fields
+ self.maindex = maindex
self.options = options
@@ -862,8 +877,9 @@ ${NATIVES}
early_exit = ''
if self.options.native_exports_optional:
early_exit = """\
- if (base::android::IsManualJniRegistrationDisabled()) return true;
-"""
+ if (jni_generator::ShouldSkipJniRegistration(%s))
+ return true;
+""" % self.maindex
values = {'REGISTER_NATIVES_SIGNATURE': signature,
'EARLY_EXIT': early_exit,
« no previous file with comments | « base/android/jni_generator/SampleForTests_jni.golden ('k') | base/android/jni_generator/jni_generator_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698