Autofill: improve handling of nameless, ID-less inputs.
[chromium-blink-merge.git] / mojo / application / application_runner_chromium.cc
blobe49b8e206e003590c3b2616b711544e76104788b
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.
5 #include "mojo/application/application_runner_chromium.h"
7 #include "base/at_exit.h"
8 #include "base/command_line.h"
9 #include "base/debug/stack_trace.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "mojo/common/message_pump_mojo.h"
13 #include "mojo/public/cpp/application/application_delegate.h"
14 #include "mojo/public/cpp/application/application_impl.h"
16 namespace mojo {
18 // static
19 void ApplicationImpl::Terminate() {
20 if (base::MessageLoop::current()->is_running())
21 base::MessageLoop::current()->Quit();
24 ApplicationRunnerChromium::ApplicationRunnerChromium(
25 ApplicationDelegate* delegate)
26 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)),
27 message_loop_type_(base::MessageLoop::TYPE_CUSTOM),
28 has_run_(false) {}
30 ApplicationRunnerChromium::~ApplicationRunnerChromium() {}
32 void ApplicationRunnerChromium::set_message_loop_type(
33 base::MessageLoop::Type type) {
34 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type);
35 DCHECK(!has_run_);
37 message_loop_type_ = type;
40 MojoResult ApplicationRunnerChromium::Run(MojoHandle shell_handle) {
41 DCHECK(!has_run_);
42 has_run_ = true;
44 base::CommandLine::Init(0, NULL);
45 #if !defined(COMPONENT_BUILD)
46 base::AtExitManager at_exit;
47 #endif
49 #ifndef NDEBUG
50 base::debug::EnableInProcessStackDumping();
51 #endif
54 scoped_ptr<base::MessageLoop> loop;
55 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM)
56 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create()));
57 else
58 loop.reset(new base::MessageLoop(message_loop_type_));
60 ApplicationImpl impl(delegate_.get(),
61 MakeScopedHandle(MessagePipeHandle(shell_handle)));
62 loop->Run();
64 delegate_.reset();
65 return MOJO_RESULT_OK;
68 } // namespace mojo