| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/application/application_runner_chromium.h" | |
| 6 | |
| 7 #include "base/at_exit.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/debug/stack_trace.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "mojo/application/public/cpp/application_delegate.h" | |
| 13 #include "mojo/application/public/cpp/application_impl.h" | |
| 14 #include "mojo/common/message_pump_mojo.h" | |
| 15 | |
| 16 int g_argc; | |
| 17 const char* const* g_argv; | |
| 18 #if !defined(OS_WIN) | |
| 19 extern "C" { | |
| 20 __attribute__((visibility("default"))) void InitCommandLineArgs( | |
| 21 int argc, const char* const* argv) { | |
| 22 g_argc = argc; | |
| 23 g_argv = argv; | |
| 24 } | |
| 25 } | |
| 26 #endif | |
| 27 | |
| 28 namespace mojo { | |
| 29 | |
| 30 // static | |
| 31 void ApplicationImpl::Terminate() { | |
| 32 if (base::MessageLoop::current()->is_running()) | |
| 33 base::MessageLoop::current()->Quit(); | |
| 34 } | |
| 35 | |
| 36 ApplicationRunnerChromium::ApplicationRunnerChromium( | |
| 37 ApplicationDelegate* delegate) | |
| 38 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), | |
| 39 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), | |
| 40 has_run_(false) {} | |
| 41 | |
| 42 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} | |
| 43 | |
| 44 void ApplicationRunnerChromium::InitBaseCommandLine() { | |
| 45 base::CommandLine::Init(g_argc, g_argv); | |
| 46 } | |
| 47 | |
| 48 void ApplicationRunnerChromium::set_message_loop_type( | |
| 49 base::MessageLoop::Type type) { | |
| 50 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); | |
| 51 DCHECK(!has_run_); | |
| 52 | |
| 53 message_loop_type_ = type; | |
| 54 } | |
| 55 | |
| 56 MojoResult ApplicationRunnerChromium::Run( | |
| 57 MojoHandle application_request_handle) { | |
| 58 DCHECK(!has_run_); | |
| 59 has_run_ = true; | |
| 60 | |
| 61 InitBaseCommandLine(); | |
| 62 base::AtExitManager at_exit; | |
| 63 | |
| 64 #ifndef NDEBUG | |
| 65 base::debug::EnableInProcessStackDumping(); | |
| 66 #endif | |
| 67 | |
| 68 { | |
| 69 scoped_ptr<base::MessageLoop> loop; | |
| 70 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) | |
| 71 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | |
| 72 else | |
| 73 loop.reset(new base::MessageLoop(message_loop_type_)); | |
| 74 | |
| 75 ApplicationImpl impl(delegate_.get(), | |
| 76 MakeRequest<Application>(MakeScopedHandle( | |
| 77 MessagePipeHandle(application_request_handle)))); | |
| 78 loop->Run(); | |
| 79 } | |
| 80 delegate_.reset(); | |
| 81 return MOJO_RESULT_OK; | |
| 82 } | |
| 83 | |
| 84 } // namespace mojo | |
| OLD | NEW |