diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-26 12:44:33 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-26 12:44:33 +0000 |
commit | 4612b236c0c4d6f6c4f77e53a4967885ff3ebc2b (patch) | |
tree | 0ef3a9e1f02f00cd2d3a32b3ab11f07243a5f884 /mojo | |
parent | 861ef0124345b4e9fb4fd4fc31933d84f6903b5b (diff) | |
download | chromium_src-4612b236c0c4d6f6c4f77e53a4967885ff3ebc2b.zip chromium_src-4612b236c0c4d6f6c4f77e53a4967885ff3ebc2b.tar.gz chromium_src-4612b236c0c4d6f6c4f77e53a4967885ff3ebc2b.tar.bz2 |
mojo_shell should start without crashing on Android
This CL finishes the bootup process for mojo_shell on Android. We now succeed
in starting all the threads we expect. Instead of crashing, we now error out
because there's no --app command line argument. I've also wired up logging to
the Android system log.
In order to initialize |net| properly, I've introduced a direct dependency from
mojo/shell to net. We're considering doing that in another CL, and I now think
having that dependency will make things easier, at least in the near term.
R=darin@chromium.org, aa@chromium.org
Review URL: https://codereview.chromium.org/45383002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/shell/DEPS | 3 | ||||
-rw-r--r-- | mojo/shell/android/library_loader.cc | 13 | ||||
-rw-r--r-- | mojo/shell/android/mojo_main.cc | 31 | ||||
-rw-r--r-- | mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoMain.java | 6 | ||||
-rw-r--r-- | mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java | 4 | ||||
-rw-r--r-- | mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellApplication.java | 17 | ||||
-rw-r--r-- | mojo/shell/run.cc | 6 |
7 files changed, 63 insertions, 17 deletions
diff --git a/mojo/shell/DEPS b/mojo/shell/DEPS new file mode 100644 index 0000000..8fa9d48 --- /dev/null +++ b/mojo/shell/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+net", +] diff --git a/mojo/shell/android/library_loader.cc b/mojo/shell/android/library_loader.cc index 38278a5..f824469 100644 --- a/mojo/shell/android/library_loader.cc +++ b/mojo/shell/android/library_loader.cc @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/android/base_jni_registrar.h" #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" +#include "base/logging.h" #include "mojo/shell/android/mojo_main.h" +#include "net/android/net_jni_registrar.h" namespace { @@ -12,7 +15,7 @@ base::android::RegistrationMethod kMojoRegisteredMethods[] = { { "MojoMain", mojo::RegisterMojoMain }, }; -bool RegisterJni(JNIEnv* env) { +bool RegisterMojoJni(JNIEnv* env) { return RegisterNativeMethods(env, kMojoRegisteredMethods, arraysize(kMojoRegisteredMethods)); } @@ -24,7 +27,13 @@ JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { base::android::InitVM(vm); JNIEnv* env = base::android::AttachCurrentThread(); - if (!RegisterJni(env)) + if (!base::android::RegisterJni(env)) + return -1; + + if (!net::android::RegisterJni(env)) + return -1; + + if (!RegisterMojoJni(env)) return -1; return JNI_VERSION_1_4; diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc index 777b640..17f6f431b 100644 --- a/mojo/shell/android/mojo_main.cc +++ b/mojo/shell/android/mojo_main.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/lazy_instance.h" +#include "base/logging.h" #include "base/threading/thread.h" #include "jni/MojoMain_jni.h" #include "mojo/shell/run.h" @@ -23,21 +24,39 @@ base::AtExitManager* g_at_exit = 0; LazyInstance<scoped_ptr<base::Thread> > g_main_thread = LAZY_INSTANCE_INITIALIZER; +void InitializeLogging() { + logging::LoggingSettings settings; + settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; + settings.dcheck_state = + logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; + logging::InitLogging(settings); + // To view log output with IDs and timestamps use "adb logcat -v threadtime". + logging::SetLogItems(false, // Process ID + false, // Thread ID + false, // Timestamp + false); // Tick count +} + +void RunShell() { + g_main_thread.Get().reset(new base::Thread("shell_thread")); + g_main_thread.Get()->Start(); + g_main_thread.Get()->message_loop()->PostTask(FROM_HERE, + base::Bind(shell::Run)); +} + } // namspace -static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) { +static void Start(JNIEnv* env, jclass clazz, jobject context) { base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); base::android::InitApplicationContext(scoped_context); if (g_at_exit) return; - g_at_exit = new base::AtExitManager(); + CommandLine::Init(0, 0); - g_main_thread.Get().reset(new base::Thread("shell_thread")); - g_main_thread.Get()->Start(); - g_main_thread.Get()->message_loop()->PostTask(FROM_HERE, - base::Bind(shell::Run)); + InitializeLogging(); + RunShell(); // TODO(abarth): Currently we leak g_at_exit and g_main_thread. } diff --git a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoMain.java b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoMain.java index 57a870c..1a8e273 100644 --- a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoMain.java +++ b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoMain.java @@ -13,9 +13,9 @@ public class MojoMain { /** * Initialize application context in native side. **/ - public static void initApplicationContext(Context context) { - nativeInitApplicationContext(context); + public static void start(Context context) { + nativeStart(context); } - private static native void nativeInitApplicationContext(Context context); + private static native void nativeStart(Context context); }; diff --git a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java index 1ec79dc..7acf283 100644 --- a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java +++ b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java @@ -30,7 +30,7 @@ public class MojoShellActivity extends Activity { finish(); return; } - MojoMain.initApplicationContext(this); - Log.i(TAG, "MojoMain.initApplicationContext() success."); + MojoMain.start(this); + Log.i(TAG, "Mojo started."); } } diff --git a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellApplication.java b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellApplication.java index 775e3a4..df927ee 100644 --- a/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellApplication.java +++ b/mojo/shell/android/shell_apk/src/org/chromium/mojo_shell_apk/MojoShellApplication.java @@ -4,7 +4,24 @@ package org.chromium.mojo_shell_apk; +import android.util.Log; + import org.chromium.base.BaseChromiumApplication; +import org.chromium.base.PathUtils; public class MojoShellApplication extends BaseChromiumApplication { + private static final String TAG = "MojoShellApplication"; + private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "mojo_shell"; + + @Override + public void onCreate() { + super.onCreate(); + initializeApplicationParameters(); + } + + public static void initializeApplicationParameters() { + PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); + Log.i(TAG, "MojoShellApplication.initializeApplicationParameters() success."); + } + } diff --git a/mojo/shell/run.cc b/mojo/shell/run.cc index ab44294..0f25e2a 100644 --- a/mojo/shell/run.cc +++ b/mojo/shell/run.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "mojo/shell/run.h" + #include "base/command_line.h" #include "base/files/file_path.h" #include "base/logging.h" @@ -20,10 +22,6 @@ namespace shell { void Run() { system::CoreImpl::Init(); -#if defined(OS_ANDROID) - return; // TODO(abarth): Run more of RunShell on Android. -#endif - // TODO(abarth): Group these objects into a "context" object. TaskRunners task_runners(base::MessageLoop::current()->message_loop_proxy()); Storage storage; |