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/browser/android_library_loader_hooks.h" | 5 #include "content/public/browser/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_registrar.h" | |
8 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/at_exit.h" | |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
12 #include "base/file_path.h" | 14 #include "base/file_path.h" |
13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
16 #include "base/string_util.h" | 18 #include "base/string_util.h" |
17 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
18 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 #include "content/browser/android/command_line.h" | |
22 #include "content/browser/android/trace_event_binding.h" | |
19 #include "media/base/android/media_jni_registrar.h" | 23 #include "media/base/android/media_jni_registrar.h" |
20 #include "net/android/net_jni_registrar.h" | 24 #include "net/android/net_jni_registrar.h" |
21 | 25 |
26 namespace { | |
27 base::AtExitManager* g_at_exit_manager = NULL; | |
28 } | |
29 | |
30 namespace content { | |
31 namespace android { | |
Ted C
2012/05/09 00:26:41
create a content_jni_registrar
| |
32 | |
33 base::android::RegistrationMethod kContentRegisteredMethods[] = { | |
34 { "CommandLine", RegisterCommandLine }, | |
35 { "TraceEvent", RegisterTraceEvent }, | |
36 }; | |
37 | |
38 bool RegisterJni(JNIEnv* env) { | |
39 return RegisterNativeMethods(env, kContentRegisteredMethods, | |
40 arraysize(kContentRegisteredMethods)); | |
41 } | |
42 | |
43 } // android | |
44 } // content | |
45 | |
22 jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz, | 46 jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz, |
23 jobjectArray init_command_line) { | 47 jobjectArray init_command_line) { |
24 | 48 // We need the Chrome AtExitManager to be created before we do any tracing or |
25 // TODO(tedchoc): Initialize the native command line from the java array | 49 // logging. |
26 // passed in. | 50 g_at_exit_manager = new base::AtExitManager(); |
51 InitNativeCommandLineFromJavaArray(env, init_command_line); | |
27 | 52 |
28 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 53 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
29 | 54 |
30 if (command_line->HasSwitch(switches::kTraceStartup)) { | 55 if (command_line->HasSwitch(switches::kTraceStartup)) { |
31 base::debug::TraceLog::GetInstance()->SetEnabled( | 56 base::debug::TraceLog::GetInstance()->SetEnabled( |
32 command_line->GetSwitchValueASCII(switches::kTraceStartup)); | 57 command_line->GetSwitchValueASCII(switches::kTraceStartup)); |
33 } | 58 } |
34 | 59 |
35 // Can only use event tracing after setting up the command line. | 60 // Can only use event tracing after setting up the command line. |
36 TRACE_EVENT0("jni", "JNI_OnLoad continuation"); | 61 TRACE_EVENT0("jni", "JNI_OnLoad continuation"); |
(...skipping 10 matching lines...) Expand all Loading... | |
47 false); // Tick count | 72 false); // Tick count |
48 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() | 73 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() |
49 << ", default verbosity = " << logging::GetVlogVerbosity(); | 74 << ", default verbosity = " << logging::GetVlogVerbosity(); |
50 | 75 |
51 if (!base::android::RegisterJni(env)) | 76 if (!base::android::RegisterJni(env)) |
52 return JNI_FALSE; | 77 return JNI_FALSE; |
53 | 78 |
54 if (!net::android::RegisterJni(env)) | 79 if (!net::android::RegisterJni(env)) |
55 return JNI_FALSE; | 80 return JNI_FALSE; |
56 | 81 |
82 if (!content::android::RegisterJni(env)) | |
83 return JNI_FALSE; | |
84 | |
57 if (!media::RegisterJni(env)) | 85 if (!media::RegisterJni(env)) |
58 return JNI_FALSE; | 86 return JNI_FALSE; |
59 | 87 |
60 return JNI_TRUE; | 88 return JNI_TRUE; |
61 } | 89 } |
62 | 90 |
91 void LibraryLoaderExitHook() { | |
92 if (g_at_exit_manager) { | |
93 delete g_at_exit_manager; | |
94 g_at_exit_manager = NULL; | |
95 } | |
96 } | |
97 | |
63 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { | 98 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { |
64 // TODO(bulach): use the jni generator once we move jni_helper methods here. | 99 // TODO(bulach): use the jni generator once we move jni_helper methods here. |
65 const JNINativeMethod kMethods[] = { | 100 const JNINativeMethod kMethods[] = { |
66 { "nativeLibraryLoadedOnMainThread", "([Ljava/lang/String;)Z", | 101 { "nativeLibraryLoadedOnMainThread", "([Ljava/lang/String;)Z", |
67 reinterpret_cast<void*>(LibraryLoaderEntryHook) }, | 102 reinterpret_cast<void*>(LibraryLoaderEntryHook) }, |
68 }; | 103 }; |
69 const int kMethodsSize = arraysize(kMethods); | 104 const int kMethodsSize = arraysize(kMethods); |
70 // TODO(tedchoc): Upstream LibraryLoader.java and replace path to make this | 105 const char kLibraryLoaderPath[] = |
71 // work. | 106 "org/chromium/content/browser/LibraryLoader"; |
Ted C
2012/05/09 00:26:41
+2 indent
John Grabowski
2012/05/09 17:18:15
The style guide is ambiguous on this point (as far
| |
72 const char kLibraryLoaderPath[] = ""; | |
73 base::android::ScopedJavaLocalRef<jclass> clazz = | 107 base::android::ScopedJavaLocalRef<jclass> clazz = |
74 base::android::GetClass(env, kLibraryLoaderPath); | 108 base::android::GetClass(env, kLibraryLoaderPath); |
75 | 109 |
76 if (env->RegisterNatives(clazz.obj(), | 110 if (env->RegisterNatives(clazz.obj(), |
77 kMethods, | 111 kMethods, |
78 kMethodsSize) < 0) { | 112 kMethodsSize) < 0) { |
79 return false; | 113 return false; |
80 } | 114 } |
81 return true; | 115 return true; |
82 } | 116 } |
OLD | NEW |