Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / app / android / library_loader_hooks.cc
blob930da5e88ab09e466a91b499a22b42bfe16a8678
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
3 // found in the LICENSE file.
5 #include "content/app/android/library_loader_hooks.h"
7 #include "base/android/base_jni_registrar.h"
8 #include "base/android/command_line_android.h"
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_registrar.h"
11 #include "base/android/jni_string.h"
12 #include "base/base_switches.h"
13 #include "base/command_line.h"
14 #include "base/files/file_path.h"
15 #include "base/logging.h"
16 #include "base/strings/string_util.h"
17 #include "base/trace_event/trace_event.h"
18 #include "base/tracked_objects.h"
19 #include "content/app/android/app_jni_registrar.h"
20 #include "content/browser/android/browser_jni_registrar.h"
21 #include "content/common/android/common_jni_registrar.h"
22 #include "content/common/content_constants_internal.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/result_codes.h"
25 #include "device/vibration/android/vibration_jni_registrar.h"
26 #include "media/base/android/media_jni_registrar.h"
27 #include "net/android/net_jni_registrar.h"
28 #include "ui/android/ui_android_jni_registrar.h"
29 #include "ui/base/android/ui_base_jni_registrar.h"
30 #include "ui/gfx/android/gfx_jni_registrar.h"
31 #include "ui/gl/android/gl_jni_registrar.h"
32 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
34 namespace content {
36 bool EnsureJniRegistered(JNIEnv* env) {
37 static bool g_jni_init_done = false;
39 if (!g_jni_init_done) {
40 if (!base::android::RegisterJni(env))
41 return false;
43 if (!gfx::android::RegisterJni(env))
44 return false;
46 if (!net::android::RegisterJni(env))
47 return false;
49 if (!ui::android::RegisterJni(env))
50 return false;
52 if (!ui::gl::android::RegisterJni(env))
53 return false;
55 if (!ui::shell_dialogs::RegisterJni(env))
56 return false;
58 if (!content::android::RegisterCommonJni(env))
59 return false;
61 if (!content::android::RegisterBrowserJni(env))
62 return false;
64 if (!content::android::RegisterAppJni(env))
65 return false;
67 if (!device::android::RegisterVibrationJni(env))
68 return false;
70 if (!media::RegisterJni(env))
71 return false;
73 if (!ui::RegisterUIAndroidJni(env))
74 return false;
76 g_jni_init_done = true;
79 return true;
82 bool LibraryLoaded(JNIEnv* env, jclass clazz) {
83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
85 if (command_line->HasSwitch(switches::kTraceStartup)) {
86 base::trace_event::CategoryFilter category_filter(
87 command_line->GetSwitchValueASCII(switches::kTraceStartup));
88 base::trace_event::TraceLog::GetInstance()->SetEnabled(
89 category_filter,
90 base::trace_event::TraceLog::RECORDING_MODE,
91 base::trace_event::TraceOptions());
94 // Android's main browser loop is custom so we set the browser
95 // name here as early as possible.
96 TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, "");
97 base::trace_event::TraceLog::GetInstance()->SetProcessName("Browser");
98 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
99 kTraceEventBrowserProcessSortIndex);
101 // Can only use event tracing after setting up the command line.
102 TRACE_EVENT0("jni", "JNI_OnLoad continuation");
104 logging::LoggingSettings settings;
105 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
106 logging::InitLogging(settings);
107 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
108 logging::SetLogItems(false, // Process ID
109 false, // Thread ID
110 false, // Timestamp
111 false); // Tick count
112 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
113 << ", default verbosity = " << logging::GetVlogVerbosity();
115 return true;
118 } // namespace content