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/public/cpp/application/application_runner_chromium.h" |
| 6 |
| 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 |
| 13 namespace mojo { |
| 14 |
| 15 // static |
| 16 void ApplicationImpl::Terminate() { |
| 17 if (base::MessageLoop::current()->is_running()) |
| 18 base::MessageLoop::current()->Quit(); |
| 19 } |
| 20 |
| 21 ApplicationRunnerChromium::ApplicationRunnerChromium( |
| 22 ApplicationDelegate* delegate) |
| 23 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), |
| 24 loop_type_(base::MessageLoop::TYPE_DEFAULT) {} |
| 25 |
| 26 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} |
| 27 |
| 28 void ApplicationRunnerChromium::set_loop_type(base::MessageLoop::Type type) { |
| 29 DCHECK_EQ(base::MessageLoop::TYPE_DEFAULT, loop_type_); |
| 30 loop_type_ = type; |
| 31 } |
| 32 |
| 33 MojoResult ApplicationRunnerChromium::Run(MojoHandle shell_handle) { |
| 34 base::CommandLine::Init(0, NULL); |
| 35 #if !defined(COMPONENT_BUILD) |
| 36 base::AtExitManager at_exit; |
| 37 #endif |
| 38 |
| 39 { |
| 40 base::MessageLoop loop(loop_type_); |
| 41 ApplicationImpl impl(delegate_.get(), |
| 42 MakeScopedHandle(MessagePipeHandle(shell_handle))); |
| 43 loop.Run(); |
| 44 } |
| 45 delegate_.reset(); |
| 46 return MOJO_RESULT_OK; |
| 47 } |
| 48 |
| 49 } // namespace mojo |
OLD | NEW |