| 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/main.h" | 5 #include "mojo/shell/android/main.h" |
| 6 | 6 |
| 7 #include "base/android/fifo_utils.h" | 7 #include "base/android/fifo_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.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/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/threading/simple_thread.h" | 21 #include "base/threading/simple_thread.h" |
| 22 #include "jni/ShellMain_jni.h" | 22 #include "jni/ShellMain_jni.h" |
| 23 #include "mojo/common/message_pump_mojo.h" | 23 #include "mojo/common/message_pump_mojo.h" |
| 24 #include "mojo/shell/android/android_handler_loader.h" | 24 #include "mojo/shell/android/android_handler_loader.h" |
| 25 #include "mojo/shell/android/background_application_loader.h" | 25 #include "mojo/shell/android/background_application_loader.h" |
| 26 #include "mojo/shell/android/native_viewport_application_loader.h" | 26 #include "mojo/shell/android/native_viewport_application_loader.h" |
| 27 #include "mojo/shell/android/ui_application_loader_android.h" | 27 #include "mojo/shell/android/ui_application_loader_android.h" |
| 28 #include "mojo/shell/application_manager/application_loader.h" | 28 #include "mojo/shell/application_manager/application_loader.h" |
| 29 #include "mojo/shell/command_line_util.h" | |
| 30 #include "mojo/shell/context.h" | 29 #include "mojo/shell/context.h" |
| 31 #include "mojo/shell/init.h" | 30 #include "mojo/shell/init.h" |
| 32 #include "ui/gl/gl_surface_egl.h" | 31 #include "ui/gl/gl_surface_egl.h" |
| 33 | 32 |
| 34 using base::LazyInstance; | 33 using base::LazyInstance; |
| 35 | 34 |
| 36 namespace mojo { | 35 namespace mojo { |
| 37 namespace shell { | 36 namespace shell { |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 // Tag for logging. | 40 // Tag for logging. |
| 42 const char kLogTag[] = "chromium"; | 41 const char kLogTag[] = "chromium"; |
| 43 | 42 |
| 44 // Command line argument for the communication fifo. | 43 // Command line argument for the communication fifo. |
| 45 const char kFifoPath[] = "fifo-path"; | 44 const char kFifoPath[] = "fifo-path"; |
| 46 | 45 |
| 47 class MojoShellRunner : public base::DelegateSimpleThread::Delegate { | 46 class MojoShellRunner : public base::DelegateSimpleThread::Delegate { |
| 48 public: | 47 public: |
| 49 MojoShellRunner(const std::vector<std::string>& parameters) | 48 MojoShellRunner(const std::vector<std::string>& parameters) {} |
| 50 : parameters_(parameters) {} | |
| 51 ~MojoShellRunner() override {} | 49 ~MojoShellRunner() override {} |
| 52 | 50 |
| 53 private: | 51 private: |
| 54 void Run() override; | 52 void Run() override; |
| 55 | 53 |
| 56 std::vector<std::string> parameters_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(MojoShellRunner); | 54 DISALLOW_COPY_AND_ASSIGN(MojoShellRunner); |
| 59 }; | 55 }; |
| 60 | 56 |
| 61 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = | 57 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = |
| 62 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
| 63 | 59 |
| 64 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER; | 60 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER; |
| 65 | 61 |
| 66 LazyInstance<scoped_ptr<MojoShellRunner>> g_shell_runner = | 62 LazyInstance<scoped_ptr<MojoShellRunner>> g_shell_runner = |
| 67 LAZY_INSTANCE_INITIALIZER; | 63 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 g_main_activiy.Get().obj()); | 96 g_main_activiy.Get().obj()); |
| 101 exit(0); | 97 exit(0); |
| 102 } | 98 } |
| 103 | 99 |
| 104 void MojoShellRunner::Run() { | 100 void MojoShellRunner::Run() { |
| 105 base::MessageLoop loop(common::MessagePumpMojo::Create()); | 101 base::MessageLoop loop(common::MessagePumpMojo::Create()); |
| 106 Context* context = g_context.Pointer()->get(); | 102 Context* context = g_context.Pointer()->get(); |
| 107 ConfigureAndroidServices(context); | 103 ConfigureAndroidServices(context); |
| 108 context->Init(); | 104 context->Init(); |
| 109 | 105 |
| 110 for (auto& args : parameters_) | 106 context->Run(GURL("mojo:window_manager")); |
| 111 ApplyApplicationArgs(context, args); | |
| 112 | |
| 113 RunCommandLineApps(context); | |
| 114 loop.Run(); | 107 loop.Run(); |
| 115 | 108 |
| 116 g_java_message_loop.Pointer()->get()->PostTask(FROM_HERE, | 109 g_java_message_loop.Pointer()->get()->PostTask(FROM_HERE, |
| 117 base::Bind(&QuitShellThread)); | 110 base::Bind(&QuitShellThread)); |
| 118 } | 111 } |
| 119 | 112 |
| 120 // Initialize stdout redirection if the command line switch is present. | 113 // Initialize stdout redirection if the command line switch is present. |
| 121 void InitializeRedirection() { | 114 void InitializeRedirection() { |
| 122 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(kFifoPath)) | 115 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(kFifoPath)) |
| 123 return; | 116 return; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 206 } |
| 214 | 207 |
| 215 } // namespace shell | 208 } // namespace shell |
| 216 } // namespace mojo | 209 } // namespace mojo |
| 217 | 210 |
| 218 // TODO(vtl): Even though main() should never be called, mojo_shell fails to | 211 // TODO(vtl): Even though main() should never be called, mojo_shell fails to |
| 219 // link without it. Figure out if we can avoid this. | 212 // link without it. Figure out if we can avoid this. |
| 220 int main(int argc, char** argv) { | 213 int main(int argc, char** argv) { |
| 221 NOTREACHED(); | 214 NOTREACHED(); |
| 222 } | 215 } |
| OLD | NEW |