OLD | NEW |
---|---|
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 "content/public/app/android_library_loader_hooks.h" | 5 #include "content/public/app/android_library_loader_hooks.h" |
6 | 6 |
7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_registrar.h" | 9 #include "base/android/jni_registrar.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
27 #include "jni/LibraryLoader_jni.h" | 27 #include "jni/LibraryLoader_jni.h" |
28 #include "media/base/android/media_jni_registrar.h" | 28 #include "media/base/android/media_jni_registrar.h" |
29 #include "net/android/net_jni_registrar.h" | 29 #include "net/android/net_jni_registrar.h" |
30 #include "ui/base/android/ui_jni_registrar.h" | 30 #include "ui/base/android/ui_jni_registrar.h" |
31 #include "ui/gfx/android/gfx_jni_registrar.h" | 31 #include "ui/gfx/android/gfx_jni_registrar.h" |
32 #include "ui/gl/android/gl_jni_registrar.h" | 32 #include "ui/gl/android/gl_jni_registrar.h" |
33 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h" | 33 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h" |
34 | 34 |
35 namespace content { | |
36 | |
35 namespace { | 37 namespace { |
38 | |
36 base::AtExitManager* g_at_exit_manager = NULL; | 39 base::AtExitManager* g_at_exit_manager = NULL; |
40 | |
41 bool DoJniRegistration(JNIEnv* env) { | |
42 static bool g_jni_init_done = false; | |
43 | |
44 if (!g_jni_init_done) { | |
45 if (!base::android::RegisterJni(env)) | |
46 return false; | |
47 | |
48 if (!gfx::android::RegisterJni(env)) | |
49 return false; | |
50 | |
51 if (!net::android::RegisterJni(env)) | |
52 return false; | |
53 | |
54 if (!ui::android::RegisterJni(env)) | |
55 return false; | |
56 | |
57 if (!ui::gl::android::RegisterJni(env)) | |
58 return false; | |
59 | |
60 if (!ui::shell_dialogs::RegisterJni(env)) | |
61 return false; | |
62 | |
63 if (!content::android::RegisterChildJni(env)) | |
64 return false; | |
65 | |
66 if (!content::android::RegisterCommonJni(env)) | |
67 return false; | |
68 | |
69 if (!content::android::RegisterBrowserJni(env)) | |
70 return false; | |
71 | |
72 if (!content::android::RegisterAppJni(env)) | |
73 return false; | |
74 | |
75 if (!media::RegisterJni(env)) | |
76 return false; | |
77 | |
78 g_jni_init_done = true; | |
79 } | |
80 | |
81 return true; | |
37 } | 82 } |
38 | 83 |
39 namespace content { | 84 } // namespace |
40 | 85 |
41 static jint LibraryLoaded(JNIEnv* env, jclass clazz, | 86 static jint LibraryLoaded(JNIEnv* env, jclass clazz, |
42 jobjectArray init_command_line) { | 87 jobjectArray init_command_line) { |
43 InitNativeCommandLineFromJavaArray(env, init_command_line); | 88 InitNativeCommandLineFromJavaArray(env, init_command_line); |
44 | 89 |
45 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 90 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
46 | 91 |
47 if (command_line->HasSwitch(switches::kTraceStartup)) { | 92 if (command_line->HasSwitch(switches::kTraceStartup)) { |
48 base::debug::CategoryFilter category_filter( | 93 base::debug::CategoryFilter category_filter( |
49 command_line->GetSwitchValueASCII(switches::kTraceStartup)); | 94 command_line->GetSwitchValueASCII(switches::kTraceStartup)); |
(...skipping 15 matching lines...) Expand all Loading... | |
65 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 110 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
66 logging::InitLogging(settings); | 111 logging::InitLogging(settings); |
67 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 112 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
68 logging::SetLogItems(false, // Process ID | 113 logging::SetLogItems(false, // Process ID |
69 false, // Thread ID | 114 false, // Thread ID |
70 false, // Timestamp | 115 false, // Timestamp |
71 false); // Tick count | 116 false); // Tick count |
72 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() | 117 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
73 << ", default verbosity = " << logging::GetVlogVerbosity(); | 118 << ", default verbosity = " << logging::GetVlogVerbosity(); |
74 | 119 |
75 if (!base::android::RegisterJni(env)) | 120 if (!DoJniRegistration(env)) |
76 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
77 | |
78 if (!gfx::android::RegisterJni(env)) | |
79 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
80 | |
81 if (!net::android::RegisterJni(env)) | |
82 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
83 | |
84 if (!ui::android::RegisterJni(env)) | |
85 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
86 | |
87 if (!ui::gl::android::RegisterJni(env)) | |
88 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
89 | |
90 if (!ui::shell_dialogs::RegisterJni(env)) | |
91 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
92 | |
93 if (!content::android::RegisterChildJni(env)) | |
94 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
95 | |
96 if (!content::android::RegisterCommonJni(env)) | |
97 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
98 | |
99 if (!content::android::RegisterBrowserJni(env)) | |
100 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
101 | |
102 if (!content::android::RegisterAppJni(env)) | |
103 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
104 | |
105 if (!media::RegisterJni(env)) | |
106 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | 121 return RESULT_CODE_FAILED_TO_REGISTER_JNI; |
107 | 122 |
108 return 0; | 123 return 0; |
109 } | 124 } |
110 | 125 |
111 static void RecordContentAndroidLinkerHistogram( | 126 static void RecordContentAndroidLinkerHistogram( |
112 JNIEnv* env, | 127 JNIEnv* env, |
113 jclass clazz, | 128 jclass clazz, |
114 jboolean loaded_at_fixed_address_failed, | 129 jboolean loaded_at_fixed_address_failed, |
115 jboolean is_low_memory_device) { | 130 jboolean is_low_memory_device) { |
116 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.LoadedAtFixedAddressFailed", | 131 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.LoadedAtFixedAddressFailed", |
117 loaded_at_fixed_address_failed); | 132 loaded_at_fixed_address_failed); |
118 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.IsLowMemoryDevice", | 133 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.IsLowMemoryDevice", |
119 is_low_memory_device); | 134 is_low_memory_device); |
120 } | 135 } |
121 | 136 |
122 void LibraryLoaderExitHook() { | 137 void LibraryLoaderExitHook() { |
123 if (g_at_exit_manager) { | 138 if (g_at_exit_manager) { |
124 delete g_at_exit_manager; | 139 delete g_at_exit_manager; |
125 g_at_exit_manager = NULL; | 140 g_at_exit_manager = NULL; |
126 } | 141 } |
127 } | 142 } |
128 | 143 |
129 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { | 144 bool RegisterLibraryLoaderEntryHook(JNIEnv* env, bool lazy_jni_registration) { |
Yaron
2013/10/31 21:28:31
Alternatively, just make DoJniRegistration public
| |
130 // We need the AtExitManager to be created at the very beginning. | 145 // We need the AtExitManager to be created at the very beginning. |
131 g_at_exit_manager = new base::AtExitManager(); | 146 g_at_exit_manager = new base::AtExitManager(); |
132 | 147 |
133 return RegisterNativesImpl(env); | 148 if (!RegisterNativesImpl(env)) |
149 return false; | |
150 | |
151 if (!lazy_jni_registration && !DoJniRegistration(env)) | |
152 return false; | |
153 | |
154 return true; | |
134 } | 155 } |
135 | 156 |
136 } // namespace content | 157 } // namespace content |
OLD | NEW |