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

Side by Side Diff: services/service_manager/background/tests/test_service.cc

Issue 2804373002: Eliminate Connector::Connect(), Connection, etc. (Closed)
Patch Set: . Created 3 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
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 "mojo/public/cpp/bindings/binding_set.h" 5 #include "mojo/public/cpp/bindings/binding_set.h"
6 #include "services/service_manager/background/tests/test.mojom.h" 6 #include "services/service_manager/background/tests/test.mojom.h"
7 #include "services/service_manager/public/c/main.h" 7 #include "services/service_manager/public/c/main.h"
8 #include "services/service_manager/public/cpp/interface_registry.h" 8 #include "services/service_manager/public/cpp/binder_registry.h"
9 #include "services/service_manager/public/cpp/service.h" 9 #include "services/service_manager/public/cpp/service.h"
10 #include "services/service_manager/public/cpp/service_context.h" 10 #include "services/service_manager/public/cpp/service_context.h"
11 #include "services/service_manager/public/cpp/service_runner.h" 11 #include "services/service_manager/public/cpp/service_runner.h"
12 12
13 namespace service_manager { 13 namespace service_manager {
14 14
15 // A service that exports a simple interface for testing. Used to test the 15 // A service that exports a simple interface for testing. Used to test the
16 // parent background service manager. 16 // parent background service manager.
17 class TestClient : public Service, 17 class TestClient : public Service,
18 public InterfaceFactory<mojom::TestService>, 18 public InterfaceFactory<mojom::TestService>,
19 public mojom::TestService { 19 public mojom::TestService {
20 public: 20 public:
21 TestClient() {} 21 TestClient() { registry_.AddInterface(this); }
22 ~TestClient() override {} 22 ~TestClient() override {}
23 23
24 private: 24 private:
25 // Service: 25 // Service:
26 bool OnConnect(const ServiceInfo& remote_info, 26 void OnBindInterface(const ServiceInfo& source_info,
27 InterfaceRegistry* registry) override { 27 const std::string& interface_name,
28 registry->AddInterface(this); 28 mojo::ScopedMessagePipeHandle interface_pipe) override {
29 return true; 29 registry_.BindInterface(source_info.identity, interface_name,
30 std::move(interface_pipe));
30 } 31 }
31 32
32 // InterfaceFactory<mojom::TestService>: 33 // InterfaceFactory<mojom::TestService>:
33 void Create(const Identity& remote_identity, 34 void Create(const Identity& remote_identity,
34 mojo::InterfaceRequest<mojom::TestService> request) override { 35 mojo::InterfaceRequest<mojom::TestService> request) override {
35 bindings_.AddBinding(this, std::move(request)); 36 bindings_.AddBinding(this, std::move(request));
36 } 37 }
37 38
38 // mojom::TestService 39 // mojom::TestService
39 void Test(const TestCallback& callback) override { 40 void Test(const TestCallback& callback) override {
40 callback.Run(); 41 callback.Run();
41 } 42 }
42 43
43 void Quit() override { context()->RequestQuit(); } 44 void Quit() override { context()->RequestQuit(); }
44 45
46 BinderRegistry registry_;
45 mojo::BindingSet<mojom::TestService> bindings_; 47 mojo::BindingSet<mojom::TestService> bindings_;
46 48
47 DISALLOW_COPY_AND_ASSIGN(TestClient); 49 DISALLOW_COPY_AND_ASSIGN(TestClient);
48 }; 50 };
49 51
50 } // namespace service_manager 52 } // namespace service_manager
51 53
52 MojoResult ServiceMain(MojoHandle service_request_handle) { 54 MojoResult ServiceMain(MojoHandle service_request_handle) {
53 service_manager::ServiceRunner runner(new service_manager::TestClient); 55 service_manager::ServiceRunner runner(new service_manager::TestClient);
54 return runner.Run(service_request_handle); 56 return runner.Run(service_request_handle);
55 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698