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