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 | |
28 namespace mojo { | 16 namespace mojo { |
29 | 17 |
30 // static | 18 // static |
31 void ApplicationImpl::Terminate() { | 19 void ApplicationImpl::Terminate() { |
32 if (base::MessageLoop::current()->is_running()) | 20 if (base::MessageLoop::current()->is_running()) |
33 base::MessageLoop::current()->Quit(); | 21 base::MessageLoop::current()->Quit(); |
34 } | 22 } |
35 | 23 |
36 ApplicationRunnerChromium::ApplicationRunnerChromium( | 24 ApplicationRunnerChromium::ApplicationRunnerChromium( |
37 ApplicationDelegate* delegate) | 25 ApplicationDelegate* delegate) |
38 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), | 26 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), |
39 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), | 27 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), |
40 has_run_(false) {} | 28 has_run_(false) {} |
41 | 29 |
42 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} | 30 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} |
43 | 31 |
44 void ApplicationRunnerChromium::set_message_loop_type( | 32 void ApplicationRunnerChromium::set_message_loop_type( |
45 base::MessageLoop::Type type) { | 33 base::MessageLoop::Type type) { |
46 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); | 34 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); |
47 DCHECK(!has_run_); | 35 DCHECK(!has_run_); |
48 | 36 |
49 message_loop_type_ = type; | 37 message_loop_type_ = type; |
50 } | 38 } |
51 | 39 |
52 MojoResult ApplicationRunnerChromium::Run( | 40 MojoResult ApplicationRunnerChromium::Run( |
53 MojoHandle application_request_handle) { | 41 MojoHandle application_request_handle) { |
54 DCHECK(!has_run_); | 42 DCHECK(!has_run_); |
55 has_run_ = true; | 43 has_run_ = true; |
56 | 44 |
57 base::CommandLine::Init(g_argc, g_argv); | 45 base::CommandLine::Init(0, NULL); |
58 base::AtExitManager at_exit; | 46 base::AtExitManager at_exit; |
59 | 47 |
60 #ifndef NDEBUG | 48 #ifndef NDEBUG |
61 base::debug::EnableInProcessStackDumping(); | 49 base::debug::EnableInProcessStackDumping(); |
62 #endif | 50 #endif |
63 | 51 |
64 { | 52 { |
65 scoped_ptr<base::MessageLoop> loop; | 53 scoped_ptr<base::MessageLoop> loop; |
66 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) | 54 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) |
67 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | 55 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); |
68 else | 56 else |
69 loop.reset(new base::MessageLoop(message_loop_type_)); | 57 loop.reset(new base::MessageLoop(message_loop_type_)); |
70 | 58 |
71 ApplicationImpl impl(delegate_.get(), | 59 ApplicationImpl impl(delegate_.get(), |
72 MakeRequest<Application>(MakeScopedHandle( | 60 MakeRequest<Application>(MakeScopedHandle( |
73 MessagePipeHandle(application_request_handle)))); | 61 MessagePipeHandle(application_request_handle)))); |
74 loop->Run(); | 62 loop->Run(); |
75 } | 63 } |
76 delegate_.reset(); | 64 delegate_.reset(); |
77 return MOJO_RESULT_OK; | 65 return MOJO_RESULT_OK; |
78 } | 66 } |
79 | 67 |
80 } // namespace mojo | 68 } // namespace mojo |
OLD | NEW |