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

Side by Side Diff: content/browser/android/library_loader_hooks.cc

Issue 10035034: Implement the skeleton of an android content shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing up most of the review comments. Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/android/library_loader_hooks.h"
6
7 #include "base/android/build_info.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h"
10 #include "base/android/path_utils.h"
11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h"
13 #include "base/file_path.h"
14 #include "base/file_util.h"
15 #include "base/logging.h"
16 #include "base/string_tokenizer.h"
17 #include "base/string_util.h"
18 #include "base/tracked_objects.h"
19 #include "content/browser/android/jni_helper.h"
20 #include "content/public/common/content_switches.h"
21 #include "media/base/android/media_player_bridge.h"
22
23 namespace base {
24 bool RegisterSystemMessageHandler(JNIEnv* env);
25 }
26
27 // The following arrays list the registration methods for all native methods
28 // required by either ChromeView or tests. They are registered in all
John Grabowski 2012/04/19 18:55:27 ChromeView --> ContentView
Ted C 2012/04/19 23:21:07 Done.
29 // processes. Native methods required only by the browser application in the
30 // browser process should be registered in InitBrowserProcess().
31
32 static RegistrationMethod kContentRegisteredMethods[] = {
John Grabowski 2012/04/19 18:55:27 (see below...)
Ted C 2012/04/19 23:21:07 Done.
33 { "MediaPlayerListener",
34 media::MediaPlayerBridge::RegisterMediaPlayerListener },
35 };
36
37 static RegistrationMethod kBaseRegisteredMethods[] = {
John Grabowski 2012/04/19 18:55:27 Seems like this struct should live in base, and be
Ted C 2012/04/19 23:21:07 Done.
38 { "BuildInfo", base::android::RegisterBuildInfo },
39 { "PathUtils", base::android::RegisterPathUtils },
40 { "SystemMessageHandler", base::RegisterSystemMessageHandler },
41 };
42
43 // Return true if the registration of the given methods succeed.
44 bool RegisterNativeMethods(JNIEnv* env,
45 const RegistrationMethod* method,
46 size_t count) {
47 const RegistrationMethod* end = method + count;
48 while (method != end) {
49 if (!method->func(env) < 0) {
50 DLOG(ERROR) << method->name << " failed registration!";
51 return false;
52 }
53 method++;
54 }
55 return true;
56 }
57
58 jboolean LibraryLoaderEntryHook(JNIEnv* env, jclass clazz,
59 jobjectArray init_command_line) {
60
61 // TODO(tedchoc): Initialize the native command line from the java array
62 // passed in.
63
64 CommandLine* command_line = CommandLine::ForCurrentProcess();
65
66 if (command_line->HasSwitch(switches::kTraceStartup)) {
67 base::debug::TraceLog::GetInstance()->SetEnabled(
68 command_line->GetSwitchValueASCII(switches::kTraceStartup));
69 }
70
71 // Can only use event tracing after setting up the command line.
72 TRACE_EVENT0("jni", "JNI_OnLoad continuation");
73
74 logging::InitLogging(NULL,
75 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
76 logging::DONT_LOCK_LOG_FILE,
77 logging::DELETE_OLD_LOG_FILE,
78 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
79 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
80 logging::SetLogItems(false, // Process ID
81 false, // Thread ID
82 false, // Timestamp
83 false); // Tick count
84 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
85 << ", default verbosity = " << logging::GetVlogVerbosity();
86
87 if (!RegisterNativeMethods(env, kBaseRegisteredMethods,
88 arraysize(kBaseRegisteredMethods)))
89 return JNI_FALSE;
90
91 // TODO(yfriedman): Add net registration.
92
93 if (!RegisterNativeMethods(env, kContentRegisteredMethods,
94 arraysize(kContentRegisteredMethods)))
95 return JNI_FALSE;
96
97 return JNI_TRUE;
98 }
99
100 bool RegisterLibraryLoaderEntryHook(JNIEnv* env) {
101 // TODO(bulach): use the jni generator once we move jni_helper methods here.
102 const JNINativeMethod kMethods[] = {
103 { "nativeLibraryLoadedOnMainThread", "([Ljava/lang/String;)Z",
104 reinterpret_cast<void*>(LibraryLoaderEntryHook) },
105 };
106 const int kMethodsSize = arraysize(kMethods);
107 // TODO(tedchoc): Upstream LibraryLoader.java and replace path to make this
108 // work.
109 const char kLibraryLoaderPath[] = "";
110 base::android::ScopedJavaLocalRef<jclass> clazz =
111 base::android::GetClass(env, kLibraryLoaderPath);
112
113 if (env->RegisterNatives(clazz.obj(),
114 kMethods,
115 kMethodsSize) < 0) {
116 return false;
117 }
118 return true;
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698