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