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

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

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

Powered by Google App Engine
This is Rietveld 408576698