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/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "jni/MojoMain_jni.h" | 15 #include "jni/MojoMain_jni.h" |
| 16 #include "mojo/public/cpp/environment/environment.h" |
16 #include "mojo/public/cpp/shell/application.h" | 17 #include "mojo/public/cpp/shell/application.h" |
17 #include "mojo/service_manager/service_loader.h" | 18 #include "mojo/service_manager/service_loader.h" |
18 #include "mojo/service_manager/service_manager.h" | 19 #include "mojo/service_manager/service_manager.h" |
19 #include "mojo/shell/context.h" | 20 #include "mojo/shell/context.h" |
20 #include "mojo/shell/init.h" | 21 #include "mojo/shell/init.h" |
21 #include "mojo/shell/run.h" | 22 #include "mojo/shell/run.h" |
22 #include "ui/gl/gl_surface_egl.h" | 23 #include "ui/gl/gl_surface_egl.h" |
23 | 24 |
24 using base::LazyInstance; | 25 using base::LazyInstance; |
25 | 26 |
26 namespace mojo { | 27 namespace mojo { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = | 31 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = |
31 LAZY_INSTANCE_INITIALIZER; | 32 LAZY_INSTANCE_INITIALIZER; |
32 | 33 |
33 LazyInstance<scoped_ptr<shell::Context> > g_context = | 34 LazyInstance<scoped_ptr<shell::Context> > g_context = |
34 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
35 | 36 |
| 37 |
| 38 LazyInstance<scoped_ptr<mojo::Environment> > g_env = |
| 39 LAZY_INSTANCE_INITIALIZER; |
| 40 |
36 } // namspace | 41 } // namspace |
37 | 42 |
38 static void Init(JNIEnv* env, jclass clazz, jobject context) { | 43 static void Init(JNIEnv* env, jclass clazz, jobject context) { |
39 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 44 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
40 | 45 |
41 base::android::InitApplicationContext(env, scoped_context); | 46 base::android::InitApplicationContext(env, scoped_context); |
42 | 47 |
43 CommandLine::Init(0, 0); | 48 CommandLine::Init(0, 0); |
44 mojo::shell::InitializeLogging(); | 49 mojo::shell::InitializeLogging(); |
45 | 50 |
(...skipping 16 matching lines...) Expand all Loading... |
62 if (jurl) | 67 if (jurl) |
63 app_url = base::android::ConvertJavaStringToUTF8(env, jurl); | 68 app_url = base::android::ConvertJavaStringToUTF8(env, jurl); |
64 #endif | 69 #endif |
65 if (!app_url.empty()) { | 70 if (!app_url.empty()) { |
66 std::vector<std::string> argv; | 71 std::vector<std::string> argv; |
67 argv.push_back("mojo_shell"); | 72 argv.push_back("mojo_shell"); |
68 argv.push_back(app_url); | 73 argv.push_back(app_url); |
69 CommandLine::ForCurrentProcess()->InitFromArgv(argv); | 74 CommandLine::ForCurrentProcess()->InitFromArgv(argv); |
70 } | 75 } |
71 | 76 |
| 77 g_env.Get().reset(new Environment); |
| 78 |
72 base::android::ScopedJavaGlobalRef<jobject> activity; | 79 base::android::ScopedJavaGlobalRef<jobject> activity; |
73 activity.Reset(env, context); | 80 activity.Reset(env, context); |
74 | 81 |
75 shell::Context* shell_context = new shell::Context(); | 82 shell::Context* shell_context = new shell::Context(); |
76 shell_context->set_activity(activity.obj()); | 83 shell_context->set_activity(activity.obj()); |
77 | 84 |
78 g_context.Get().reset(shell_context); | 85 g_context.Get().reset(shell_context); |
79 shell::Run(shell_context); | 86 shell::Run(shell_context); |
80 } | 87 } |
81 | 88 |
82 bool RegisterMojoMain(JNIEnv* env) { | 89 bool RegisterMojoMain(JNIEnv* env) { |
83 return RegisterNativesImpl(env); | 90 return RegisterNativesImpl(env); |
84 } | 91 } |
85 | 92 |
86 } // namespace mojo | 93 } // namespace mojo |
OLD | NEW |