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

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

Issue 2486073003: Revert of 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
« no previous file with comments | « services/service_manager/tests/lifecycle/app_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
33 void AppClient::Create(const Identity& remote_identity, 28 void AppClient::Create(const Identity& remote_identity,
34 mojom::LifecycleControlRequest request) { 29 mojom::LifecycleControlRequest request) {
35 bindings_.AddBinding(this, std::move(request)); 30 bindings_.AddBinding(this, std::move(request));
36 } 31 }
37 32
38 void AppClient::Ping(const PingCallback& callback) { 33 void AppClient::Ping(const PingCallback& callback) {
39 callback.Run(); 34 callback.Run();
40 } 35 }
41 36
42 void AppClient::GracefulQuit() { 37 void AppClient::GracefulQuit() {
43 context_->RequestQuit(); 38 base::MessageLoop::current()->QuitWhenIdle();
44 } 39 }
45 40
46 void AppClient::Crash() { 41 void AppClient::Crash() {
47 // 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
48 // maybe UI clutter on some platforms, just exit without shutting anything 43 // maybe UI clutter on some platforms, just exit without shutting anything
49 // down properly. 44 // down properly.
50 exit(1); 45 exit(1);
51 } 46 }
52 47
53 void AppClient::CloseServiceManagerConnection() { 48 void AppClient::CloseServiceManagerConnection() {
54 context_->DisconnectFromServiceManager(); 49 context_->DisconnectFromServiceManager();
55 bindings_.set_connection_error_handler( 50 bindings_.set_connection_error_handler(
56 base::Bind(&AppClient::BindingLost, base::Unretained(this))); 51 base::Bind(&AppClient::BindingLost, base::Unretained(this)));
57 } 52 }
58 53
59 void AppClient::BindingLost() { 54 void AppClient::BindingLost() {
60 if (bindings_.empty()) 55 if (bindings_.empty())
61 OnStop(); 56 GracefulQuit();
62 } 57 }
63 58
64 } // namespace test 59 } // namespace test
65 } // namespace service_manager 60 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/tests/lifecycle/app_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698