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

Side by Side Diff: shell/android/mojo_main.cc

Issue 805113002: Moves android specific code into android directory (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: merge 2 trunk Created 6 years 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
« no previous file with comments | « shell/android/mojo_main.h ('k') | shell/android/ui_application_loader_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "shell/android/mojo_main.h" 5 #include "shell/android/mojo_main.h"
6 6
7 #include "base/android/command_line_android.h" 7 #include "base/android/command_line_android.h"
8 #include "base/android/java_handler_thread.h" 8 #include "base/android/java_handler_thread.h"
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "jni/MojoMain_jni.h" 19 #include "jni/MojoMain_jni.h"
20 #include "mojo/application_manager/application_loader.h" 20 #include "mojo/application_manager/application_loader.h"
21 #include "mojo/application_manager/application_manager.h" 21 #include "mojo/application_manager/application_manager.h"
22 #include "mojo/application_manager/background_shell_application_loader.h"
23 #include "services/gles2/gpu_impl.h"
24 #include "services/native_viewport/native_viewport_impl.h"
25 #include "shell/android/android_handler_loader.h"
26 #include "shell/android/ui_application_loader_android.h"
22 #include "shell/context.h" 27 #include "shell/context.h"
23 #include "shell/init.h" 28 #include "shell/init.h"
24 #include "ui/gl/gl_surface_egl.h" 29 #include "ui/gl/gl_surface_egl.h"
25 30
26 using base::LazyInstance; 31 using base::LazyInstance;
27 32
28 namespace mojo { 33 namespace mojo {
34 namespace shell {
29 35
30 namespace { 36 namespace {
31 37
32 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = 38 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop =
33 LAZY_INSTANCE_INITIALIZER; 39 LAZY_INSTANCE_INITIALIZER;
34 40
35 LazyInstance<scoped_ptr<shell::Context>> g_context = LAZY_INSTANCE_INITIALIZER; 41 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER;
36 42
37 LazyInstance<scoped_ptr<base::android::JavaHandlerThread>> g_shell_thread = 43 LazyInstance<scoped_ptr<base::android::JavaHandlerThread>> g_shell_thread =
38 LAZY_INSTANCE_INITIALIZER; 44 LAZY_INSTANCE_INITIALIZER;
39 45
46 class NativeViewportApplicationLoader : public ApplicationLoader,
47 public ApplicationDelegate,
48 public InterfaceFactory<NativeViewport>,
49 public InterfaceFactory<Gpu> {
50 public:
51 NativeViewportApplicationLoader() : gpu_state_(new gles2::GpuImpl::State) {}
52 ~NativeViewportApplicationLoader() override {}
53
54 private:
55 // ApplicationLoader implementation.
56 void Load(ApplicationManager* manager,
57 const GURL& url,
58 ScopedMessagePipeHandle shell_handle,
59 LoadCallback callback) override {
60 DCHECK(shell_handle.is_valid());
61 app_.reset(new ApplicationImpl(this, shell_handle.Pass()));
62 }
63
64 void OnApplicationError(ApplicationManager* manager,
65 const GURL& url) override {}
66
67 // ApplicationDelegate implementation.
68 bool ConfigureIncomingConnection(
69 mojo::ApplicationConnection* connection) override {
70 connection->AddService<NativeViewport>(this);
71 connection->AddService<Gpu>(this);
72 return true;
73 }
74
75 // InterfaceFactory<NativeViewport> implementation.
76 void Create(ApplicationConnection* connection,
77 InterfaceRequest<NativeViewport> request) override {
78 BindToRequest(new native_viewport::NativeViewportImpl(app_.get(), false),
79 &request);
80 }
81
82 // InterfaceFactory<Gpu> implementation.
83 void Create(ApplicationConnection* connection,
84 InterfaceRequest<Gpu> request) override {
85 new gles2::GpuImpl(request.Pass(), gpu_state_);
86 }
87
88 scoped_refptr<gles2::GpuImpl::State> gpu_state_;
89 scoped_ptr<ApplicationImpl> app_;
90 DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader);
91 };
92
93 void ConfigureAndroidServices(Context* context) {
94 context->application_manager()->SetLoaderForURL(
95 make_scoped_ptr(new UIApplicationLoader(
96 make_scoped_ptr(new NativeViewportApplicationLoader()),
97 g_java_message_loop.Get().get())),
98 GURL("mojo:native_viewport_service"));
99
100 // Android handler is bundled with the Mojo shell, because it uses the
101 // MojoShell application as the JNI bridge to bootstrap execution of other
102 // Android Mojo apps that need JNI.
103 context->application_manager()->SetLoaderForURL(
104 make_scoped_ptr(new BackgroundShellApplicationLoader(
105 make_scoped_ptr(new AndroidHandlerLoader()), "android_handler",
106 base::MessageLoop::TYPE_DEFAULT)),
107 GURL("mojo:android_handler"));
108 }
109
40 void RunShell(std::vector<GURL> app_urls) { 110 void RunShell(std::vector<GURL> app_urls) {
41 shell::Context* context = g_context.Pointer()->get(); 111 Context* context = g_context.Pointer()->get();
42 context->Init(); 112 context->Init();
43 context->set_ui_loop(g_java_message_loop.Get().get()); 113 ConfigureAndroidServices(context);
44 for (std::vector<GURL>::const_iterator it = app_urls.begin(); 114 for (std::vector<GURL>::const_iterator it = app_urls.begin();
45 it != app_urls.end(); ++it) { 115 it != app_urls.end(); ++it) {
46 context->Run(*it); 116 context->Run(*it);
47 } 117 }
48 } 118 }
49 119
50 } // namespace 120 } // namespace
51 121
52 static void Init(JNIEnv* env, 122 static void Init(JNIEnv* env,
53 jclass clazz, 123 jclass clazz,
54 jobject context, 124 jobject context,
55 jstring mojo_shell_path, 125 jstring mojo_shell_path,
56 jobjectArray jparameters, 126 jobjectArray jparameters,
57 jstring j_local_apps_directory) { 127 jstring j_local_apps_directory) {
58 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); 128 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
59 base::android::InitApplicationContext(env, scoped_context); 129 base::android::InitApplicationContext(env, scoped_context);
60 130
61 base::android::InitNativeCommandLineFromJavaArray(env, jparameters); 131 base::android::InitNativeCommandLineFromJavaArray(env, jparameters);
62 base::FilePath mojo_shell_file_path( 132 base::FilePath mojo_shell_file_path(
63 base::android::ConvertJavaStringToUTF8(env, mojo_shell_path)); 133 base::android::ConvertJavaStringToUTF8(env, mojo_shell_path));
64 base::CommandLine::ForCurrentProcess()->SetProgram(mojo_shell_file_path); 134 base::CommandLine::ForCurrentProcess()->SetProgram(mojo_shell_file_path);
65 mojo::shell::InitializeLogging(); 135 InitializeLogging();
66 136
67 // We want ~MessageLoop to happen prior to ~Context. Initializing 137 // We want ~MessageLoop to happen prior to ~Context. Initializing
68 // LazyInstances is akin to stack-allocating objects; their destructors 138 // LazyInstances is akin to stack-allocating objects; their destructors
69 // will be invoked first-in-last-out. 139 // will be invoked first-in-last-out.
70 shell::Context* shell_context = new shell::Context(); 140 Context* shell_context = new Context();
71 shell_context->mojo_url_resolver()->SetLocalAppsPath(base::FilePath( 141 shell_context->mojo_url_resolver()->SetLocalAppsPath(base::FilePath(
72 base::android::ConvertJavaStringToUTF8(env, j_local_apps_directory))); 142 base::android::ConvertJavaStringToUTF8(env, j_local_apps_directory)));
73 g_context.Get().reset(shell_context); 143 g_context.Get().reset(shell_context);
74 144
75 g_java_message_loop.Get().reset(new base::MessageLoopForUI); 145 g_java_message_loop.Get().reset(new base::MessageLoopForUI);
76 base::MessageLoopForUI::current()->Start(); 146 base::MessageLoopForUI::current()->Start();
77 147
78 // TODO(abarth): At which point should we switch to cross-platform 148 // TODO(abarth): At which point should we switch to cross-platform
79 // initialization? 149 // initialization?
80 150
(...skipping 15 matching lines...) Expand all
96 new base::android::JavaHandlerThread("shell_thread")); 166 new base::android::JavaHandlerThread("shell_thread"));
97 g_shell_thread.Get()->Start(); 167 g_shell_thread.Get()->Start();
98 g_shell_thread.Get()->message_loop()->PostTask( 168 g_shell_thread.Get()->message_loop()->PostTask(
99 FROM_HERE, base::Bind(&RunShell, app_urls)); 169 FROM_HERE, base::Bind(&RunShell, app_urls));
100 } 170 }
101 171
102 bool RegisterMojoMain(JNIEnv* env) { 172 bool RegisterMojoMain(JNIEnv* env) {
103 return RegisterNativesImpl(env); 173 return RegisterNativesImpl(env);
104 } 174 }
105 175
176 } // namespace shell
106 } // namespace mojo 177 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/android/mojo_main.h ('k') | shell/android/ui_application_loader_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698