Chromium Code Reviews| 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/public/cpp/application/application_runner_chromium.h" | 5 #include "mojo/public/cpp/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/memory/scoped_ptr.h" | |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "mojo/common/message_pump_mojo.h" | |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 12 | 14 |
| 13 namespace mojo { | 15 namespace mojo { |
| 14 | 16 |
| 15 // static | 17 // static |
| 16 void ApplicationImpl::Terminate() { | 18 void ApplicationImpl::Terminate() { |
| 17 if (base::MessageLoop::current()->is_running()) | 19 if (base::MessageLoop::current()->is_running()) |
| 18 base::MessageLoop::current()->Quit(); | 20 base::MessageLoop::current()->Quit(); |
| 19 } | 21 } |
| 20 | 22 |
| 21 ApplicationRunnerChromium::ApplicationRunnerChromium( | 23 ApplicationRunnerChromium::ApplicationRunnerChromium( |
| 22 ApplicationDelegate* delegate) | 24 ApplicationDelegate* delegate) |
| 23 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), | 25 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), |
| 24 message_loop_type_(base::MessageLoop::TYPE_DEFAULT) {} | 26 message_loop_type_(base::MessageLoop::TYPE_CUSTOM) {} |
| 25 | 27 |
| 26 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} | 28 ApplicationRunnerChromium::~ApplicationRunnerChromium() {} |
| 27 | 29 |
| 28 void ApplicationRunnerChromium::set_message_loop_type( | 30 void ApplicationRunnerChromium::set_message_loop_type( |
| 29 base::MessageLoop::Type type) { | 31 base::MessageLoop::Type type) { |
| 30 DCHECK_EQ(base::MessageLoop::TYPE_DEFAULT, message_loop_type_); | 32 DCHECK_EQ(base::MessageLoop::TYPE_CUSTOM, message_loop_type_); |
|
darin (slow to review)
2014/08/27 21:20:43
I don't understand this assertion. Why is it inval
yzshen1
2014/08/27 22:31:48
I honestly didn't think about it. :)
| |
| 31 message_loop_type_ = type; | 33 message_loop_type_ = type; |
| 32 } | 34 } |
| 33 | 35 |
| 34 MojoResult ApplicationRunnerChromium::Run(MojoHandle shell_handle) { | 36 MojoResult ApplicationRunnerChromium::Run(MojoHandle shell_handle) { |
| 35 base::CommandLine::Init(0, NULL); | 37 base::CommandLine::Init(0, NULL); |
| 36 #if !defined(COMPONENT_BUILD) | 38 #if !defined(COMPONENT_BUILD) |
| 37 base::AtExitManager at_exit; | 39 base::AtExitManager at_exit; |
| 38 #endif | 40 #endif |
| 39 | 41 |
| 40 { | 42 { |
| 41 base::MessageLoop loop(message_loop_type_); | 43 scoped_ptr<base::MessageLoop> loop; |
| 44 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) { | |
| 45 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); | |
| 46 } else { | |
| 47 loop.reset(new base::MessageLoop(message_loop_type_)); | |
| 48 } | |
| 49 | |
| 42 ApplicationImpl impl(delegate_.get(), | 50 ApplicationImpl impl(delegate_.get(), |
| 43 MakeScopedHandle(MessagePipeHandle(shell_handle))); | 51 MakeScopedHandle(MessagePipeHandle(shell_handle))); |
| 44 loop.Run(); | 52 loop->Run(); |
| 45 } | 53 } |
| 46 delegate_.reset(); | 54 delegate_.reset(); |
| 47 return MOJO_RESULT_OK; | 55 return MOJO_RESULT_OK; |
| 48 } | 56 } |
| 49 | 57 |
| 50 } // namespace mojo | 58 } // namespace mojo |
| OLD | NEW |