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

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

Issue 240003006: Get sample_app running on Android again (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 8 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
« mojo/mojo_public.gypi ('K') | « mojo/mojo_services.gypi ('k') | no next file » | 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 "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/services/native_viewport/native_viewport_service.h"
20 #include "mojo/shell/context.h" 20 #include "mojo/shell/context.h"
21 #include "mojo/shell/init.h" 21 #include "mojo/shell/init.h"
22 #include "mojo/shell/run.h" 22 #include "mojo/shell/run.h"
23 #include "ui/gl/gl_surface_egl.h" 23 #include "ui/gl/gl_surface_egl.h"
24 24
25 using base::LazyInstance; 25 using base::LazyInstance;
26 26
27 namespace mojo { 27 namespace mojo {
28 28
29 namespace { 29 namespace {
30 30
31 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = 31 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop =
32 LAZY_INSTANCE_INITIALIZER; 32 LAZY_INSTANCE_INITIALIZER;
33 33
34 LazyInstance<scoped_ptr<shell::Context> > g_context = 34 LazyInstance<scoped_ptr<shell::Context> > g_context =
35 LAZY_INSTANCE_INITIALIZER; 35 LAZY_INSTANCE_INITIALIZER;
36 36
37 class NativeViewportServiceLoader : public ServiceLoader { 37 LazyInstance<scoped_ptr<mojo::Environment> > g_env =
38 public: 38 LAZY_INSTANCE_INITIALIZER;
39 NativeViewportServiceLoader() {}
40 virtual ~NativeViewportServiceLoader() {}
41
42 private:
43 virtual void LoadService(ServiceManager* manager,
44 const GURL& url,
45 ScopedShellHandle service_handle) OVERRIDE {
46 app_.reset(CreateNativeViewportService(g_context.Get().get(),
47 service_handle.Pass()));
48 }
49
50 virtual void OnServiceError(ServiceManager* manager,
51 const GURL& url) OVERRIDE {
52 }
53
54 scoped_ptr<Application> app_;
55 };
56
57 LazyInstance<scoped_ptr<NativeViewportServiceLoader> >
58 g_viewport_service_loader = LAZY_INSTANCE_INITIALIZER;
59 39
60 } // namspace 40 } // namspace
61 41
62 static void Init(JNIEnv* env, jclass clazz, jobject context) { 42 static void Init(JNIEnv* env, jclass clazz, jobject context) {
63 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); 43 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context);
64 44
65 base::android::InitApplicationContext(env, scoped_context); 45 base::android::InitApplicationContext(env, scoped_context);
66 46
67 CommandLine::Init(0, 0); 47 CommandLine::Init(0, 0);
68 mojo::shell::InitializeLogging(); 48 mojo::shell::InitializeLogging();
(...skipping 17 matching lines...) Expand all
86 if (jurl) 66 if (jurl)
87 app_url = base::android::ConvertJavaStringToUTF8(env, jurl); 67 app_url = base::android::ConvertJavaStringToUTF8(env, jurl);
88 #endif 68 #endif
89 if (!app_url.empty()) { 69 if (!app_url.empty()) {
90 std::vector<std::string> argv; 70 std::vector<std::string> argv;
91 argv.push_back("mojo_shell"); 71 argv.push_back("mojo_shell");
92 argv.push_back(app_url); 72 argv.push_back(app_url);
93 CommandLine::ForCurrentProcess()->InitFromArgv(argv); 73 CommandLine::ForCurrentProcess()->InitFromArgv(argv);
94 } 74 }
95 75
76 g_env.Get().reset(new Environment);
77
96 base::android::ScopedJavaGlobalRef<jobject> activity; 78 base::android::ScopedJavaGlobalRef<jobject> activity;
97 activity.Reset(env, context); 79 activity.Reset(env, context);
98 80
99 shell::Context* shell_context = new shell::Context(); 81 shell::Context* shell_context = new shell::Context();
100 shell_context->set_activity(activity.obj()); 82 shell_context->set_activity(activity.obj());
101 g_viewport_service_loader.Get().reset(new NativeViewportServiceLoader());
102 shell_context->service_manager()->SetLoaderForURL(
103 g_viewport_service_loader.Get().get(),
104 GURL("mojo:mojo_native_viewport_service"));
105 83
106 g_context.Get().reset(shell_context); 84 g_context.Get().reset(shell_context);
107 shell::Run(shell_context); 85 shell::Run(shell_context);
108 } 86 }
109 87
110 bool RegisterMojoMain(JNIEnv* env) { 88 bool RegisterMojoMain(JNIEnv* env) {
111 return RegisterNativesImpl(env); 89 return RegisterNativesImpl(env);
112 } 90 }
113 91
114 } // namespace mojo 92 } // namespace mojo
OLDNEW
« mojo/mojo_public.gypi ('K') | « mojo/mojo_services.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698