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

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

Issue 810803003: Moves NativeViewportApplicationLoader into own files (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix 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/BUILD.gn ('k') | shell/android/native_viewport_application_loader.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"
22 #include "mojo/application_manager/background_shell_application_loader.h" 21 #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" 22 #include "shell/android/android_handler_loader.h"
23 #include "shell/android/native_viewport_application_loader.h"
26 #include "shell/android/ui_application_loader_android.h" 24 #include "shell/android/ui_application_loader_android.h"
27 #include "shell/context.h" 25 #include "shell/context.h"
28 #include "shell/init.h" 26 #include "shell/init.h"
29 #include "ui/gl/gl_surface_egl.h" 27 #include "ui/gl/gl_surface_egl.h"
30 28
31 using base::LazyInstance; 29 using base::LazyInstance;
32 30
33 namespace mojo { 31 namespace mojo {
34 namespace shell { 32 namespace shell {
35 33
36 namespace { 34 namespace {
37 35
38 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = 36 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop =
39 LAZY_INSTANCE_INITIALIZER; 37 LAZY_INSTANCE_INITIALIZER;
40 38
41 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER; 39 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER;
42 40
43 LazyInstance<scoped_ptr<base::android::JavaHandlerThread>> g_shell_thread = 41 LazyInstance<scoped_ptr<base::android::JavaHandlerThread>> g_shell_thread =
44 LAZY_INSTANCE_INITIALIZER; 42 LAZY_INSTANCE_INITIALIZER;
45 43
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) { 44 void ConfigureAndroidServices(Context* context) {
94 context->application_manager()->SetLoaderForURL( 45 context->application_manager()->SetLoaderForURL(
95 make_scoped_ptr(new UIApplicationLoader( 46 make_scoped_ptr(new UIApplicationLoader(
96 make_scoped_ptr(new NativeViewportApplicationLoader()), 47 make_scoped_ptr(new NativeViewportApplicationLoader()),
97 g_java_message_loop.Get().get())), 48 g_java_message_loop.Get().get())),
98 GURL("mojo:native_viewport_service")); 49 GURL("mojo:native_viewport_service"));
99 50
100 // Android handler is bundled with the Mojo shell, because it uses the 51 // Android handler is bundled with the Mojo shell, because it uses the
101 // MojoShell application as the JNI bridge to bootstrap execution of other 52 // MojoShell application as the JNI bridge to bootstrap execution of other
102 // Android Mojo apps that need JNI. 53 // Android Mojo apps that need JNI.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 g_shell_thread.Get()->message_loop()->PostTask( 119 g_shell_thread.Get()->message_loop()->PostTask(
169 FROM_HERE, base::Bind(&RunShell, app_urls)); 120 FROM_HERE, base::Bind(&RunShell, app_urls));
170 } 121 }
171 122
172 bool RegisterMojoMain(JNIEnv* env) { 123 bool RegisterMojoMain(JNIEnv* env) {
173 return RegisterNativesImpl(env); 124 return RegisterNativesImpl(env);
174 } 125 }
175 126
176 } // namespace shell 127 } // namespace shell
177 } // namespace mojo 128 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/BUILD.gn ('k') | shell/android/native_viewport_application_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698