| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/shell/tests/lifecycle/app_client.h" |
| 6 |
| 7 #include "mojo/shell/public/cpp/shell_connection.h" |
| 8 |
| 9 namespace mojo { |
| 10 namespace shell { |
| 11 namespace test { |
| 12 |
| 13 AppClient::AppClient() {} |
| 14 AppClient::AppClient(shell::mojom::ShellClientRequest request) |
| 15 : connection_(new ShellConnection(this, std::move(request))) {} |
| 16 AppClient::~AppClient() {} |
| 17 |
| 18 bool AppClient::AcceptConnection(mojo::Connection* connection) { |
| 19 connection->AddInterface<LifecycleControl>(this); |
| 20 return true; |
| 21 } |
| 22 |
| 23 void AppClient::Create(mojo::Connection* connection, |
| 24 LifecycleControlRequest request) { |
| 25 bindings_.AddBinding(this, std::move(request)); |
| 26 } |
| 27 |
| 28 void AppClient::Ping(const PingCallback& callback) { |
| 29 callback.Run(); |
| 30 } |
| 31 |
| 32 void AppClient::GracefulQuit() { |
| 33 base::MessageLoop::current()->QuitWhenIdle(); |
| 34 } |
| 35 |
| 36 void AppClient::Crash() { |
| 37 // Rather than actually crash, which causes a bunch of console spray and |
| 38 // maybe UI clutter on some platforms, just exit without shutting anything |
| 39 // down properly. |
| 40 exit(1); |
| 41 } |
| 42 |
| 43 void AppClient::CloseShellConnection() { |
| 44 DCHECK(runner_); |
| 45 runner_->DestroyShellConnection(); |
| 46 // Quit the app once the caller goes away. |
| 47 bindings_.set_connection_error_handler( |
| 48 base::Bind(&AppClient::BindingLost, base::Unretained(this))); |
| 49 } |
| 50 |
| 51 void AppClient::BindingLost() { |
| 52 if (bindings_.empty()) |
| 53 GracefulQuit(); |
| 54 } |
| 55 |
| 56 } // namespace test |
| 57 } // namespace shell |
| 58 } // namespace mojo |
| 59 |
| 60 |
| OLD | NEW |