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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/shell/android/mojo_main.h" 5 #include "mojo/shell/android/mojo_main.h"
6 6
7 #include "base/android/java_handler_thread.h"
7 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
8 #include "base/at_exit.h" 9 #include "base/at_exit.h"
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "jni/MojoMain_jni.h" 16 #include "jni/MojoMain_jni.h"
16 #include "mojo/service_manager/service_loader.h" 17 #include "mojo/service_manager/service_loader.h"
17 #include "mojo/service_manager/service_manager.h" 18 #include "mojo/service_manager/service_manager.h"
18 #include "mojo/shell/context.h" 19 #include "mojo/shell/context.h"
19 #include "mojo/shell/init.h" 20 #include "mojo/shell/init.h"
20 #include "mojo/shell/run.h" 21 #include "mojo/shell/run.h"
21 #include "ui/gl/gl_surface_egl.h" 22 #include "ui/gl/gl_surface_egl.h"
22 23
23 using base::LazyInstance; 24 using base::LazyInstance;
24 25
25 namespace mojo { 26 namespace mojo {
26 27
27 namespace { 28 namespace {
28 29
29 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = 30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop =
30 LAZY_INSTANCE_INITIALIZER; 31 LAZY_INSTANCE_INITIALIZER;
31 32
32 LazyInstance<scoped_ptr<shell::Context> > g_context = 33 LazyInstance<scoped_ptr<shell::Context> > g_context =
33 LAZY_INSTANCE_INITIALIZER; 34 LAZY_INSTANCE_INITIALIZER;
34 35
36 LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread =
37 LAZY_INSTANCE_INITIALIZER;
38
39 void RunShell(std::vector<GURL> app_urls) {
40 shell::Context* shell_context = new shell::Context();
41 shell_context->set_activity(base::android::GetApplicationContext());
42 shell_context->set_ui_loop(g_java_message_loop.Get().get());
43
44 g_context.Get().reset(shell_context);
45 shell::Run(shell_context, app_urls);
46 }
47
35 } // namespace 48 } // namespace
36 49
37 static void Init(JNIEnv* env, jclass clazz, jobject context) { 50 static void Init(JNIEnv* env, jclass clazz, jobject context) {
38 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); 51 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
39 52
40 base::android::InitApplicationContext(env, scoped_context); 53 base::android::InitApplicationContext(env, scoped_context);
41 54
42 base::CommandLine::Init(0, 0); 55 base::CommandLine::Init(0, 0);
43 mojo::shell::InitializeLogging(); 56 mojo::shell::InitializeLogging();
44 57
45 g_java_message_loop.Get().reset(new base::MessageLoopForUI); 58 g_java_message_loop.Get().reset(new base::MessageLoopForUI);
46 base::MessageLoopForUI::current()->Start(); 59 base::MessageLoopForUI::current()->Start();
47 60
48 // TODO(abarth): At which point should we switch to cross-platform 61 // TODO(abarth): At which point should we switch to cross-platform
49 // initialization? 62 // initialization?
50 63
51 gfx::GLSurface::InitializeOneOff(); 64 gfx::GLSurface::InitializeOneOff();
52 } 65 }
53 66
54 static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) { 67 static void Start(JNIEnv* env, jclass clazz, jstring jurl) {
55 std::vector<GURL> app_urls; 68 std::vector<GURL> app_urls;
56 #if defined(MOJO_SHELL_DEBUG_URL) 69 #if defined(MOJO_SHELL_DEBUG_URL)
57 app_urls.push_back(GURL(MOJO_SHELL_DEBUG_URL)); 70 app_urls.push_back(GURL(MOJO_SHELL_DEBUG_URL));
58 // Sleep for 5 seconds to give the debugger a chance to attach. 71 // Sleep for 5 seconds to give the debugger a chance to attach.
59 sleep(5); 72 sleep(5);
60 #else 73 #else
61 if (jurl) 74 if (jurl)
62 app_urls.push_back(GURL(base::android::ConvertJavaStringToUTF8(env, jurl))); 75 app_urls.push_back(GURL(base::android::ConvertJavaStringToUTF8(env, jurl)));
63 #endif 76 #endif
64 77
65 base::android::ScopedJavaGlobalRef<jobject> activity; 78 g_shell_thread.Get().reset(
66 activity.Reset(env, context); 79 new base::android::JavaHandlerThread("shell_thread"));
67 80 g_shell_thread.Get()->Start();
68 shell::Context* shell_context = new shell::Context(); 81 g_shell_thread.Get()->message_loop()->PostTask(
69 shell_context->set_activity(activity.obj()); 82 FROM_HERE, base::Bind(&RunShell, app_urls));
70
71 g_context.Get().reset(shell_context);
72 shell::Run(shell_context, app_urls);
73 } 83 }
74 84
75 bool RegisterMojoMain(JNIEnv* env) { 85 bool RegisterMojoMain(JNIEnv* env) {
76 return RegisterNativesImpl(env); 86 return RegisterNativesImpl(env);
77 } 87 }
78 88
79 } // namespace mojo 89 } // namespace mojo
OLDNEW
« 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