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