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/command_line_android.h" | 8 #include "base/android/command_line_android.h" |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_registrar.h" | 10 #include "base/android/jni_registrar.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/at_exit.h" | |
13 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
15 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
16 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/metrics/histogram.h" | |
19 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
20 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
21 #include "content/app/android/app_jni_registrar.h" | 19 #include "content/app/android/app_jni_registrar.h" |
22 #include "content/browser/android/browser_jni_registrar.h" | 20 #include "content/browser/android/browser_jni_registrar.h" |
23 #include "content/child/android/child_jni_registrar.h" | 21 #include "content/child/android/child_jni_registrar.h" |
24 #include "content/common/android/common_jni_registrar.h" | 22 #include "content/common/android/common_jni_registrar.h" |
25 #include "content/common/content_constants_internal.h" | 23 #include "content/common/content_constants_internal.h" |
26 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/result_codes.h" | 25 #include "content/public/common/result_codes.h" |
28 #include "jni/LibraryLoader_jni.h" | |
29 #include "media/base/android/media_jni_registrar.h" | 26 #include "media/base/android/media_jni_registrar.h" |
30 #include "net/android/net_jni_registrar.h" | 27 #include "net/android/net_jni_registrar.h" |
31 #include "ui/base/android/ui_base_jni_registrar.h" | 28 #include "ui/base/android/ui_base_jni_registrar.h" |
32 #include "ui/gfx/android/gfx_jni_registrar.h" | 29 #include "ui/gfx/android/gfx_jni_registrar.h" |
33 #include "ui/gl/android/gl_jni_registrar.h" | 30 #include "ui/gl/android/gl_jni_registrar.h" |
34 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h" | 31 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h" |
35 | 32 |
36 namespace content { | 33 namespace content { |
37 | 34 |
38 namespace { | |
39 base::AtExitManager* g_at_exit_manager = NULL; | |
40 const char* g_library_version_number = ""; | |
41 } | |
42 | |
43 bool EnsureJniRegistered(JNIEnv* env) { | 35 bool EnsureJniRegistered(JNIEnv* env) { |
44 static bool g_jni_init_done = false; | 36 static bool g_jni_init_done = false; |
45 | 37 |
46 if (!g_jni_init_done) { | 38 if (!g_jni_init_done) { |
47 if (!base::android::RegisterJni(env)) | 39 if (!base::android::RegisterJni(env)) |
48 return false; | 40 return false; |
49 | 41 |
50 if (!gfx::android::RegisterJni(env)) | 42 if (!gfx::android::RegisterJni(env)) |
51 return false; | 43 return false; |
52 | 44 |
(...skipping 23 matching lines...) Expand all Loading... |
76 | 68 |
77 if (!media::RegisterJni(env)) | 69 if (!media::RegisterJni(env)) |
78 return false; | 70 return false; |
79 | 71 |
80 g_jni_init_done = true; | 72 g_jni_init_done = true; |
81 } | 73 } |
82 | 74 |
83 return true; | 75 return true; |
84 } | 76 } |
85 | 77 |
86 static jint LibraryLoaded(JNIEnv* env, jclass clazz, | 78 bool LibraryLoaded(JNIEnv* env, jclass clazz, |
87 jobjectArray init_command_line) { | 79 jobjectArray init_command_line) { |
88 base::android::InitNativeCommandLineFromJavaArray(env, init_command_line); | 80 base::android::InitNativeCommandLineFromJavaArray(env, init_command_line); |
89 | 81 |
90 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 82 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
91 | 83 |
92 if (command_line->HasSwitch(switches::kTraceStartup)) { | 84 if (command_line->HasSwitch(switches::kTraceStartup)) { |
93 base::debug::CategoryFilter category_filter( | 85 base::debug::CategoryFilter category_filter( |
94 command_line->GetSwitchValueASCII(switches::kTraceStartup)); | 86 command_line->GetSwitchValueASCII(switches::kTraceStartup)); |
95 base::debug::TraceLog::GetInstance()->SetEnabled(category_filter, | 87 base::debug::TraceLog::GetInstance()->SetEnabled(category_filter, |
96 base::debug::TraceLog::RECORDING_MODE, | 88 base::debug::TraceLog::RECORDING_MODE, |
(...skipping 21 matching lines...) Expand all Loading... |
118 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 110 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
119 logging::InitLogging(settings); | 111 logging::InitLogging(settings); |
120 // 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". |
121 logging::SetLogItems(false, // Process ID | 113 logging::SetLogItems(false, // Process ID |
122 false, // Thread ID | 114 false, // Thread ID |
123 false, // Timestamp | 115 false, // Timestamp |
124 false); // Tick count | 116 false); // Tick count |
125 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() | 117 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
126 << ", default verbosity = " << logging::GetVlogVerbosity(); | 118 << ", default verbosity = " << logging::GetVlogVerbosity(); |
127 | 119 |
128 if (!EnsureJniRegistered(env)) | 120 return EnsureJniRegistered(env); |
129 return RESULT_CODE_FAILED_TO_REGISTER_JNI; | |
130 | |
131 return 0; | |
132 } | |
133 | |
134 static void RecordContentAndroidLinkerHistogram( | |
135 JNIEnv* env, | |
136 jclass clazz, | |
137 jboolean loaded_at_fixed_address_failed, | |
138 jboolean is_low_memory_device) { | |
139 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.LoadedAtFixedAddressFailed", | |
140 loaded_at_fixed_address_failed); | |
141 UMA_HISTOGRAM_BOOLEAN("ContentAndroidLinker.IsLowMemoryDevice", | |
142 is_low_memory_device); | |
143 } | |
144 | |
145 void LibraryLoaderExitHook() { | |
146 if (g_at_exit_manager) { | |
147 delete g_at_exit_manager; | |
148 g_at_exit_manager = NULL; | |
149 } | |
150 } | |
151 | |
152 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { | |
153 // We need the AtExitManager to be created at the very beginning. | |
154 g_at_exit_manager = new base::AtExitManager(); | |
155 | |
156 return RegisterNativesImpl(env); | |
157 } | |
158 | |
159 void SetVersionNumber(const char* version_number) { | |
160 g_library_version_number = strdup(version_number); | |
161 } | |
162 | |
163 jstring GetVersionNumber(JNIEnv* env, jclass clazz) { | |
164 return env->NewStringUTF(g_library_version_number); | |
165 } | 121 } |
166 | 122 |
167 } // namespace content | 123 } // namespace content |
OLD | NEW |