OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
10 #include "services/service_manager/public/cpp/connection.h" | 10 #include "services/service_manager/public/cpp/connection.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 class Target : public service_manager::Service, | 25 class Target : public service_manager::Service, |
26 public service_manager::InterfaceFactory<ConnectTestService>, | 26 public service_manager::InterfaceFactory<ConnectTestService>, |
27 public ConnectTestService { | 27 public ConnectTestService { |
28 public: | 28 public: |
29 Target() {} | 29 Target() {} |
30 ~Target() override {} | 30 ~Target() override {} |
31 | 31 |
32 private: | 32 private: |
33 // service_manager::Service: | 33 // service_manager::Service: |
34 void OnStart(service_manager::ServiceContext* context) override { | |
35 identity_ = context->identity(); | |
36 } | |
37 | |
38 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 34 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
39 service_manager::InterfaceRegistry* registry) override { | 35 service_manager::InterfaceRegistry* registry) override { |
40 registry->AddInterface<ConnectTestService>(this); | 36 registry->AddInterface<ConnectTestService>(this); |
41 return true; | 37 return true; |
42 } | 38 } |
43 | 39 |
44 // service_manager::InterfaceFactory<ConnectTestService>: | 40 // service_manager::InterfaceFactory<ConnectTestService>: |
45 void Create(const service_manager::Identity& remote_identity, | 41 void Create(const service_manager::Identity& remote_identity, |
46 ConnectTestServiceRequest request) override { | 42 ConnectTestServiceRequest request) override { |
47 bindings_.AddBinding(this, std::move(request)); | 43 bindings_.AddBinding(this, std::move(request)); |
48 } | 44 } |
49 | 45 |
50 // ConnectTestService: | 46 // ConnectTestService: |
51 void GetTitle(const GetTitleCallback& callback) override { | 47 void GetTitle(const GetTitleCallback& callback) override { |
52 callback.Run("connect_test_exe"); | 48 callback.Run("connect_test_exe"); |
53 } | 49 } |
54 void GetInstance(const GetInstanceCallback& callback) override { | 50 void GetInstance(const GetInstanceCallback& callback) override { |
55 callback.Run(identity_.instance()); | 51 callback.Run(context()->identity().instance()); |
56 } | 52 } |
57 | 53 |
58 service_manager::Identity identity_; | |
59 mojo::BindingSet<ConnectTestService> bindings_; | 54 mojo::BindingSet<ConnectTestService> bindings_; |
60 | 55 |
61 DISALLOW_COPY_AND_ASSIGN(Target); | 56 DISALLOW_COPY_AND_ASSIGN(Target); |
62 }; | 57 }; |
63 | 58 |
64 } // namespace | 59 } // namespace |
65 | 60 |
66 int main(int argc, char** argv) { | 61 int main(int argc, char** argv) { |
67 base::AtExitManager at_exit; | 62 base::AtExitManager at_exit; |
68 base::CommandLine::Init(argc, argv); | 63 base::CommandLine::Init(argc, argv); |
69 | 64 |
70 service_manager::InitializeLogging(); | 65 service_manager::InitializeLogging(); |
71 return service_manager::TestNativeMain(base::MakeUnique<Target>()); | 66 return service_manager::TestNativeMain(base::MakeUnique<Target>()); |
72 } | 67 } |
OLD | NEW |