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