| OLD | NEW |
| 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/java_handler_thread.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = | 30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = |
| 31 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 32 | 32 |
| 33 LazyInstance<scoped_ptr<shell::Context> > g_context = | 33 LazyInstance<scoped_ptr<shell::Context> > g_context = |
| 34 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
| 35 | 35 |
| 36 LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread = | 36 LazyInstance<scoped_ptr<base::android::JavaHandlerThread> > g_shell_thread = |
| 37 LAZY_INSTANCE_INITIALIZER; | 37 LAZY_INSTANCE_INITIALIZER; |
| 38 | 38 |
| 39 void RunShell(std::vector<GURL> app_urls) { | 39 void RunShell(std::vector<GURL> app_urls) { |
| 40 shell::Context* shell_context = new shell::Context(); | |
| 41 shell_context->set_ui_loop(g_java_message_loop.Get().get()); | 40 shell_context->set_ui_loop(g_java_message_loop.Get().get()); |
| 42 | |
| 43 g_context.Get().reset(shell_context); | |
| 44 shell::Run(shell_context, app_urls); | 41 shell::Run(shell_context, app_urls); |
| 45 } | 42 } |
| 46 | 43 |
| 47 } // namespace | 44 } // namespace |
| 48 | 45 |
| 49 static void Init(JNIEnv* env, jclass clazz, jobject context) { | 46 static void Init(JNIEnv* env, jclass clazz, jobject context) { |
| 50 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 47 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
| 51 | 48 |
| 52 base::android::InitApplicationContext(env, scoped_context); | 49 base::android::InitApplicationContext(env, scoped_context); |
| 53 | 50 |
| 54 base::CommandLine::Init(0, 0); | 51 base::CommandLine::Init(0, 0); |
| 55 mojo::shell::InitializeLogging(); | 52 mojo::shell::InitializeLogging(); |
| 56 | 53 |
| 54 // We want ~MessageLoop to happen prior to ~Context. Initializing |
| 55 // LazyInstances is akin to stack-allocating objects; their destructors |
| 56 // will be invoked first-in-last-out. |
| 57 shell::Context* shell_context = new shell::Context(); |
| 58 g_context.Get().reset(shell_context); |
| 57 g_java_message_loop.Get().reset(new base::MessageLoopForUI); | 59 g_java_message_loop.Get().reset(new base::MessageLoopForUI); |
| 60 shell_context->Init(); |
| 58 base::MessageLoopForUI::current()->Start(); | 61 base::MessageLoopForUI::current()->Start(); |
| 59 | 62 |
| 60 // TODO(abarth): At which point should we switch to cross-platform | 63 // TODO(abarth): At which point should we switch to cross-platform |
| 61 // initialization? | 64 // initialization? |
| 62 | 65 |
| 63 gfx::GLSurface::InitializeOneOff(); | 66 gfx::GLSurface::InitializeOneOff(); |
| 64 } | 67 } |
| 65 | 68 |
| 66 static void Start(JNIEnv* env, jclass clazz, jstring jurl) { | 69 static void Start(JNIEnv* env, jclass clazz, jstring jurl) { |
| 67 std::vector<GURL> app_urls; | 70 std::vector<GURL> app_urls; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 g_shell_thread.Get()->Start(); | 82 g_shell_thread.Get()->Start(); |
| 80 g_shell_thread.Get()->message_loop()->PostTask( | 83 g_shell_thread.Get()->message_loop()->PostTask( |
| 81 FROM_HERE, base::Bind(&RunShell, app_urls)); | 84 FROM_HERE, base::Bind(&RunShell, app_urls)); |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool RegisterMojoMain(JNIEnv* env) { | 87 bool RegisterMojoMain(JNIEnv* env) { |
| 85 return RegisterNativesImpl(env); | 88 return RegisterNativesImpl(env); |
| 86 } | 89 } |
| 87 | 90 |
| 88 } // namespace mojo | 91 } // namespace mojo |
| OLD | NEW |