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