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

Unified Diff: mojo/shell/android/mojo_main.cc

Issue 399663002: Have mojo_shell run in its custom thread on android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java ('k') | mojo/shell/context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/android/mojo_main.cc
diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc
index 9a574b80080914b7f94d63c61b661b3433cb95c0..4848ad9483cb9d410f226086a41d6caf4b20d954 100644
--- a/mojo/shell/android/mojo_main.cc
+++ b/mojo/shell/android/mojo_main.cc
@@ -4,6 +4,7 @@
#include "mojo/shell/android/mojo_main.h"
+#include "base/android/java_handler_thread.h"
#include "base/android/jni_string.h"
#include "base/at_exit.h"
#include "base/bind.h"
@@ -32,6 +33,18 @@ LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop =
LazyInstance<scoped_ptr<shell::Context> > g_context =
LAZY_INSTANCE_INITIALIZER;
+LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread =
+ LAZY_INSTANCE_INITIALIZER;
+
+void RunShell(std::vector<GURL> app_urls) {
+ shell::Context* shell_context = new shell::Context();
+ shell_context->set_activity(base::android::GetApplicationContext());
+ shell_context->set_ui_loop(g_java_message_loop.Get().get());
+
+ g_context.Get().reset(shell_context);
+ shell::Run(shell_context, app_urls);
+}
+
} // namespace
static void Init(JNIEnv* env, jclass clazz, jobject context) {
@@ -51,7 +64,7 @@ static void Init(JNIEnv* env, jclass clazz, jobject context) {
gfx::GLSurface::InitializeOneOff();
}
-static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) {
+static void Start(JNIEnv* env, jclass clazz, jstring jurl) {
std::vector<GURL> app_urls;
#if defined(MOJO_SHELL_DEBUG_URL)
app_urls.push_back(GURL(MOJO_SHELL_DEBUG_URL));
@@ -62,14 +75,11 @@ static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) {
app_urls.push_back(GURL(base::android::ConvertJavaStringToUTF8(env, jurl)));
#endif
- base::android::ScopedJavaGlobalRef<jobject> activity;
- activity.Reset(env, context);
-
- shell::Context* shell_context = new shell::Context();
- shell_context->set_activity(activity.obj());
-
- g_context.Get().reset(shell_context);
- shell::Run(shell_context, app_urls);
+ g_shell_thread.Get().reset(
+ new base::android::JavaHandlerThread("shell_thread"));
+ g_shell_thread.Get()->Start();
+ g_shell_thread.Get()->message_loop()->PostTask(
+ FROM_HERE, base::Bind(&RunShell, app_urls));
}
bool RegisterMojoMain(JNIEnv* env) {
« no previous file with comments | « mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java ('k') | mojo/shell/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698