Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: services/service_manager/tests/lifecycle/app_client.cc

Issue 2480603004: Service Manager: Implement graceful service termination (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) { 18 void AppClient::OnStart(ServiceContext* context) {
19 context_ = context; 19 context_ = context;
20 } 20 }
21 21
22 bool AppClient::OnConnect(const ServiceInfo& remote_info, 22 bool AppClient::OnConnect(const ServiceInfo& remote_info,
23 InterfaceRegistry* registry) { 23 InterfaceRegistry* registry) {
24 registry->AddInterface<mojom::LifecycleControl>(this); 24 registry->AddInterface<mojom::LifecycleControl>(this);
25 return true; 25 return true;
26 } 26 }
27 27
28 bool AppClient::OnStop() {
29 base::MessageLoop::current()->QuitWhenIdle();
30 return true;
31 }
32
28 void AppClient::Create(const Identity& remote_identity, 33 void AppClient::Create(const Identity& remote_identity,
29 mojom::LifecycleControlRequest request) { 34 mojom::LifecycleControlRequest request) {
30 bindings_.AddBinding(this, std::move(request)); 35 bindings_.AddBinding(this, std::move(request));
31 } 36 }
32 37
33 void AppClient::Ping(const PingCallback& callback) { 38 void AppClient::Ping(const PingCallback& callback) {
34 callback.Run(); 39 callback.Run();
35 } 40 }
36 41
37 void AppClient::GracefulQuit() { 42 void AppClient::GracefulQuit() {
38 base::MessageLoop::current()->QuitWhenIdle(); 43 context_->RequestQuit();
39 } 44 }
40 45
41 void AppClient::Crash() { 46 void AppClient::Crash() {
42 // Rather than actually crash, which causes a bunch of console spray and 47 // Rather than actually crash, which causes a bunch of console spray and
43 // maybe UI clutter on some platforms, just exit without shutting anything 48 // maybe UI clutter on some platforms, just exit without shutting anything
44 // down properly. 49 // down properly.
45 exit(1); 50 exit(1);
46 } 51 }
47 52
48 void AppClient::CloseServiceManagerConnection() { 53 void AppClient::CloseServiceManagerConnection() {
49 context_->DisconnectFromServiceManager(); 54 context_->DisconnectFromServiceManager();
50 bindings_.set_connection_error_handler( 55 bindings_.set_connection_error_handler(
51 base::Bind(&AppClient::BindingLost, base::Unretained(this))); 56 base::Bind(&AppClient::BindingLost, base::Unretained(this)));
52 } 57 }
53 58
54 void AppClient::BindingLost() { 59 void AppClient::BindingLost() {
55 if (bindings_.empty()) 60 if (bindings_.empty())
56 GracefulQuit(); 61 OnStop();
57 } 62 }
58 63
59 } // namespace test 64 } // namespace test
60 } // namespace service_manager 65 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698