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" | |
11 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
12 #include "mojo/common/message_pump_mojo.h" | 11 #include "mojo/message_pump/message_pump_mojo.h" |
13 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.
h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
14 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 14 #include "mojo/public/cpp/system/handle.h" |
| 15 #include "mojo/public/cpp/system/message_pipe.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 | 18 |
18 // static | 19 // static |
19 void ApplicationImpl::Terminate() { | 20 void ApplicationImpl::Terminate() { |
20 if (base::MessageLoop::current()->is_running()) | 21 if (base::MessageLoop::current()->is_running()) |
21 base::MessageLoop::current()->Quit(); | 22 base::MessageLoop::current()->Quit(); |
22 } | 23 } |
23 | 24 |
24 ApplicationRunnerChromium::ApplicationRunnerChromium( | 25 ApplicationRunnerChromium::ApplicationRunnerChromium( |
25 ApplicationDelegate* delegate) | 26 ApplicationDelegate* delegate) |
26 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), | 27 : delegate_(delegate), |
27 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), | 28 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), |
28 has_run_(false) { | 29 has_run_(false) {} |
29 } | |
30 | 30 |
31 ApplicationRunnerChromium::~ApplicationRunnerChromium() { | 31 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} |
32 } | |
33 | 32 |
34 void ApplicationRunnerChromium::set_message_loop_type( | 33 void ApplicationRunnerChromium::set_message_loop_type( |
35 base::MessageLoop::Type type) { | 34 base::MessageLoop::Type type) { |
36 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); | 35 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); |
37 DCHECK(!has_run_); | 36 DCHECK(!has_run_); |
38 | 37 |
39 message_loop_type_ = type; | 38 message_loop_type_ = type; |
40 } | 39 } |
41 | 40 |
42 MojoResult ApplicationRunnerChromium::Run( | 41 MojoResult ApplicationRunnerChromium::Run( |
43 MojoHandle application_request_handle) { | 42 MojoHandle application_request_handle) { |
44 DCHECK(!has_run_); | 43 DCHECK(!has_run_); |
45 has_run_ = true; | 44 has_run_ = true; |
46 | 45 |
47 base::CommandLine::Init(0, NULL); | 46 base::CommandLine::Init(0, NULL); |
48 base::AtExitManager at_exit; | 47 base::AtExitManager at_exit; |
49 | 48 |
50 #if !defined(NDEBUG) && !defined(OS_NACL) | 49 #if !defined(NDEBUG) && !defined(OS_NACL) |
51 base::debug::EnableInProcessStackDumping(); | 50 base::debug::EnableInProcessStackDumping(); |
52 #endif | 51 #endif |
53 | 52 |
54 { | 53 { |
55 scoped_ptr<base::MessageLoop> loop; | 54 std::unique_ptr<base::MessageLoop> loop; |
56 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) | 55 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) |
57 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | 56 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); |
58 else | 57 else |
59 loop.reset(new base::MessageLoop(message_loop_type_)); | 58 loop.reset(new base::MessageLoop(message_loop_type_)); |
60 | 59 |
61 ApplicationImpl impl(delegate_.get(), | 60 ApplicationImpl impl(delegate_.get(), |
62 MakeRequest<Application>(MakeScopedHandle( | 61 MakeRequest<Application>(MakeScopedHandle( |
63 MessagePipeHandle(application_request_handle)))); | 62 MessagePipeHandle(application_request_handle)))); |
64 loop->Run(); | 63 loop->Run(); |
65 } | 64 } |
66 delegate_.reset(); | 65 delegate_.reset(); |
67 return MOJO_RESULT_OK; | 66 return MOJO_RESULT_OK; |
68 } | 67 } |
69 | 68 |
70 } // namespace mojo | 69 } // namespace mojo |
OLD | NEW |