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

Side by Side Diff: services/shell/tests/connect/connect_test_class_app.cc

Issue 2419723002: Move services/shell to services/service_manager (Closed)
Patch Set: rebase Created 4 years, 2 months 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
(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 "base/bind.h"
6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "mojo/public/cpp/bindings/binding_set.h"
10 #include "services/shell/public/c/main.h"
11 #include "services/shell/public/cpp/connector.h"
12 #include "services/shell/public/cpp/interface_factory.h"
13 #include "services/shell/public/cpp/interface_registry.h"
14 #include "services/shell/public/cpp/service.h"
15 #include "services/shell/public/cpp/service_runner.h"
16 #include "services/shell/public/interfaces/connector.mojom.h"
17 #include "services/shell/tests/connect/connect_test.mojom.h"
18
19 namespace shell {
20
21 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback;
22
23 class ConnectTestClassApp
24 : public Service,
25 public InterfaceFactory<test::mojom::ConnectTestService>,
26 public InterfaceFactory<test::mojom::ClassInterface>,
27 public test::mojom::ConnectTestService,
28 public test::mojom::ClassInterface {
29 public:
30 ConnectTestClassApp() {}
31 ~ConnectTestClassApp() override {}
32
33 private:
34 // shell::Service:
35 void OnStart(const Identity& identity) override {
36 identity_ = identity;
37 }
38 bool OnConnect(const Identity& remote_identity,
39 InterfaceRegistry* registry) override {
40 registry->AddInterface<test::mojom::ConnectTestService>(this);
41 registry->AddInterface<test::mojom::ClassInterface>(this);
42 inbound_connections_.insert(registry);
43 registry->SetConnectionLostClosure(
44 base::Bind(&ConnectTestClassApp::OnConnectionError,
45 base::Unretained(this), registry));
46 return true;
47 }
48
49 // InterfaceFactory<test::mojom::ConnectTestService>:
50 void Create(const Identity& remote_identity,
51 test::mojom::ConnectTestServiceRequest request) override {
52 bindings_.AddBinding(this, std::move(request));
53 }
54
55 // InterfaceFactory<test::mojom::ClassInterface>:
56 void Create(const Identity& remote_identity,
57 test::mojom::ClassInterfaceRequest request) override {
58 class_interface_bindings_.AddBinding(this, std::move(request));
59 }
60
61 // test::mojom::ConnectTestService:
62 void GetTitle(const GetTitleCallback& callback) override {
63 callback.Run("CLASS APP");
64 }
65 void GetInstance(const GetInstanceCallback& callback) override {
66 callback.Run(identity_.instance());
67 }
68
69 // test::mojom::ClassInterface:
70 void Ping(const PingCallback& callback) override {
71 callback.Run("PONG");
72 }
73
74 void OnConnectionError(InterfaceRegistry* registry) {
75 auto it = inbound_connections_.find(registry);
76 DCHECK(it != inbound_connections_.end());
77 inbound_connections_.erase(it);
78 if (inbound_connections_.empty())
79 base::MessageLoop::current()->QuitWhenIdle();
80 }
81
82 Identity identity_;
83 std::set<InterfaceRegistry*> inbound_connections_;
84 mojo::BindingSet<test::mojom::ConnectTestService> bindings_;
85 mojo::BindingSet<test::mojom::ClassInterface> class_interface_bindings_;
86
87 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp);
88 };
89
90 } // namespace shell
91
92
93 MojoResult ServiceMain(MojoHandle service_request_handle) {
94 shell::ServiceRunner runner(new shell::ConnectTestClassApp);
95 return runner.Run(service_request_handle);
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698