Roll android_tools to the latest.
[chromium-blink-merge.git] / content / app / android / library_loader_hooks.cc
blob2b81f9a3f2ffd736f4402ed121e4b98dfc3f6c8a
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/public/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/debug/trace_event.h"
15 #include "base/files/file_path.h"
16 #include "base/logging.h"
17 #include "base/strings/string_util.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 "media/base/android/media_jni_registrar.h"
26 #include "net/android/net_jni_registrar.h"
27 #include "ui/base/android/ui_base_jni_registrar.h"
28 #include "ui/gfx/android/gfx_jni_registrar.h"
29 #include "ui/gl/android/gl_jni_registrar.h"
30 #include "ui/shell_dialogs/android/shell_dialogs_jni_registrar.h"
32 namespace content {
34 bool EnsureJniRegistered(JNIEnv* env) {
35 static bool g_jni_init_done = false;
37 if (!g_jni_init_done) {
38 if (!base::android::RegisterJni(env))
39 return false;
41 if (!gfx::android::RegisterJni(env))
42 return false;
44 if (!net::android::RegisterJni(env))
45 return false;
47 if (!ui::android::RegisterJni(env))
48 return false;
50 if (!ui::gl::android::RegisterJni(env))
51 return false;
53 if (!ui::shell_dialogs::RegisterJni(env))
54 return false;
56 if (!content::android::RegisterCommonJni(env))
57 return false;
59 if (!content::android::RegisterBrowserJni(env))
60 return false;
62 if (!content::android::RegisterAppJni(env))
63 return false;
65 if (!media::RegisterJni(env))
66 return false;
68 g_jni_init_done = true;
71 return true;
74 bool LibraryLoaded(JNIEnv* env, jclass clazz) {
75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
77 if (command_line->HasSwitch(switches::kTraceStartup)) {
78 base::debug::CategoryFilter category_filter(
79 command_line->GetSwitchValueASCII(switches::kTraceStartup));
80 base::debug::TraceLog::GetInstance()->SetEnabled(
81 category_filter,
82 base::debug::TraceLog::RECORDING_MODE,
83 base::debug::TraceOptions());
86 // Android's main browser loop is custom so we set the browser
87 // name here as early as possible.
88 TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, "");
89 base::debug::TraceLog::GetInstance()->SetProcessName("Browser");
90 base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
91 kTraceEventBrowserProcessSortIndex);
93 // Can only use event tracing after setting up the command line.
94 TRACE_EVENT0("jni", "JNI_OnLoad continuation");
96 logging::LoggingSettings settings;
97 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
98 logging::InitLogging(settings);
99 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
100 logging::SetLogItems(false, // Process ID
101 false, // Thread ID
102 false, // Timestamp
103 false); // Tick count
104 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
105 << ", default verbosity = " << logging::GetVlogVerbosity();
107 return EnsureJniRegistered(env);
110 } // namespace content