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/shell/public/cpp/application_runner.h" | 5 #include "mojo/shell/public/cpp/application_runner.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/process/launch.h" | 12 #include "base/process/launch.h" |
12 #include "mojo/shell/public/cpp/shell_client.h" | 13 #include "mojo/shell/public/cpp/shell_client.h" |
13 #include "mojo/shell/public/cpp/shell_connection.h" | 14 #include "mojo/shell/public/cpp/shell_connection.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
17 namespace { | |
18 | |
19 void QuitMessageLoop() { | |
20 if (base::MessageLoop::current() && | |
21 base::MessageLoop::current()->is_running()) { | |
22 base::MessageLoop::current()->QuitWhenIdle(); | |
sky
2016/03/18 16:20:37
If the messageloop is nested this quits the topmos
| |
23 } | |
24 } | |
25 | |
26 } // namespace | |
16 | 27 |
17 int g_application_runner_argc; | 28 int g_application_runner_argc; |
18 const char* const* g_application_runner_argv; | 29 const char* const* g_application_runner_argv; |
19 | 30 |
20 ApplicationRunner::ApplicationRunner(ShellClient* client) | 31 ApplicationRunner::ApplicationRunner(ShellClient* client) |
21 : client_(scoped_ptr<ShellClient>(client)), | 32 : client_(scoped_ptr<ShellClient>(client)), |
22 message_loop_type_(base::MessageLoop::TYPE_DEFAULT), | 33 message_loop_type_(base::MessageLoop::TYPE_DEFAULT), |
23 has_run_(false) {} | 34 has_run_(false) {} |
24 | 35 |
25 ApplicationRunner::~ApplicationRunner() {} | 36 ApplicationRunner::~ApplicationRunner() {} |
(...skipping 21 matching lines...) Expand all Loading... | |
47 } | 58 } |
48 | 59 |
49 { | 60 { |
50 scoped_ptr<base::MessageLoop> loop; | 61 scoped_ptr<base::MessageLoop> loop; |
51 loop.reset(new base::MessageLoop(message_loop_type_)); | 62 loop.reset(new base::MessageLoop(message_loop_type_)); |
52 | 63 |
53 connection_.reset(new ShellConnection( | 64 connection_.reset(new ShellConnection( |
54 client_.get(), | 65 client_.get(), |
55 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( | 66 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( |
56 MessagePipeHandle(shell_client_request_handle))))); | 67 MessagePipeHandle(shell_client_request_handle))))); |
68 connection_->set_connection_lost_closure(base::Bind(&QuitMessageLoop)); | |
57 loop->Run(); | 69 loop->Run(); |
58 // It's very common for the client to cache the app and terminate on errors. | 70 // It's very common for the client to cache the app and terminate on errors. |
59 // If we don't delete the client before the app we run the risk of the | 71 // If we don't delete the client before the app we run the risk of the |
60 // client having a stale reference to the app and trying to use it. | 72 // client having a stale reference to the app and trying to use it. |
61 // Note that we destruct the message loop first because that might trigger | 73 // Note that we destruct the message loop first because that might trigger |
62 // connection error handlers and they might access objects created by the | 74 // connection error handlers and they might access objects created by the |
63 // client. | 75 // client. |
64 loop.reset(); | 76 loop.reset(); |
65 client_.reset(); | 77 client_.reset(); |
66 connection_.reset(); | 78 connection_.reset(); |
(...skipping 12 matching lines...) Expand all Loading... | |
79 | 91 |
80 void ApplicationRunner::DestroyShellConnection() { | 92 void ApplicationRunner::DestroyShellConnection() { |
81 connection_.reset(); | 93 connection_.reset(); |
82 } | 94 } |
83 | 95 |
84 void ApplicationRunner::Quit() { | 96 void ApplicationRunner::Quit() { |
85 base::MessageLoop::current()->QuitWhenIdle(); | 97 base::MessageLoop::current()->QuitWhenIdle(); |
86 } | 98 } |
87 | 99 |
88 } // namespace mojo | 100 } // namespace mojo |
OLD | NEW |