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

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

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 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/c/system/main.h"
10 #include "mojo/public/cpp/bindings/binding_set.h"
11 #include "mojo/shell/public/cpp/application_runner.h"
12 #include "mojo/shell/public/cpp/connector.h"
13 #include "mojo/shell/public/cpp/interface_factory.h"
14 #include "mojo/shell/public/cpp/shell_client.h"
15 #include "mojo/shell/public/interfaces/connector.mojom.h"
16 #include "mojo/shell/tests/connect/connect_test.mojom.h"
17
18 namespace mojo {
19 namespace shell {
20
21 using GetTitleCallback = test::mojom::ConnectTestService::GetTitleCallback;
22
23 class ConnectTestClassApp
24 : public ShellClient,
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 // mojo::ShellClient:
35 void Initialize(Connector* connector, const Identity& identity,
36 uint32_t id) override {
37 connector_ = connector;
38 identity_ = identity;
39 }
40 bool AcceptConnection(Connection* connection) override {
41 CHECK(connection->HasCapabilityClass("class"));
42 connection->AddInterface<test::mojom::ConnectTestService>(this);
43 connection->AddInterface<test::mojom::ClassInterface>(this);
44 inbound_connections_.insert(connection);
45 connection->SetConnectionLostClosure(
46 base::Bind(&ConnectTestClassApp::OnConnectionError,
47 base::Unretained(this), connection));
48 return true;
49 }
50
51 // InterfaceFactory<test::mojom::ConnectTestService>:
52 void Create(Connection* connection,
53 test::mojom::ConnectTestServiceRequest request) override {
54 bindings_.AddBinding(this, std::move(request));
55 }
56
57 // InterfaceFactory<test::mojom::ClassInterface>:
58 void Create(Connection* connection,
59 test::mojom::ClassInterfaceRequest request) override {
60 class_interface_bindings_.AddBinding(this, std::move(request));
61 }
62
63 // test::mojom::ConnectTestService:
64 void GetTitle(const GetTitleCallback& callback) override {
65 callback.Run("CLASS APP");
66 }
67 void GetInstance(const GetInstanceCallback& callback) override {
68 callback.Run(identity_.instance());
69 }
70
71 // test::mojom::ClassInterface:
72 void Ping(const PingCallback& callback) override {
73 callback.Run("PONG");
74 }
75
76 void OnConnectionError(Connection* connection) {
77 auto it = inbound_connections_.find(connection);
78 DCHECK(it != inbound_connections_.end());
79 inbound_connections_.erase(it);
80 if (inbound_connections_.empty())
81 base::MessageLoop::current()->QuitWhenIdle();
82 }
83
84 Connector* connector_ = nullptr;
85 Identity identity_;
86 std::set<Connection*> inbound_connections_;
87 BindingSet<test::mojom::ConnectTestService> bindings_;
88 BindingSet<test::mojom::ClassInterface> class_interface_bindings_;
89
90 DISALLOW_COPY_AND_ASSIGN(ConnectTestClassApp);
91 };
92
93 } // namespace shell
94 } // namespace mojo
95
96
97 MojoResult MojoMain(MojoHandle shell_handle) {
98 MojoResult rv = mojo::ApplicationRunner(
99 new mojo::shell::ConnectTestClassApp).Run(shell_handle);
100 return rv;
101 }
OLDNEW
« no previous file with comments | « mojo/shell/tests/connect/connect_test_app_manifest.json ('k') | mojo/shell/tests/connect/connect_test_class_app_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698