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