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

Side by Side Diff: services/device/device_service_test_base.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/device/device_service_test_base.h" 5 #include "services/device/device_service_test_base.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "mojo/public/cpp/bindings/binding_set.h" 11 #include "mojo/public/cpp/bindings/binding_set.h"
12 #include "services/device/device_service.h" 12 #include "services/device/device_service.h"
13 #include "services/device/public/interfaces/constants.mojom.h" 13 #include "services/device/public/interfaces/constants.mojom.h"
14 #include "services/service_manager/public/cpp/binder_registry.h"
14 #include "services/service_manager/public/cpp/interface_factory.h" 15 #include "services/service_manager/public/cpp/interface_factory.h"
15 #include "services/service_manager/public/cpp/interface_registry.h"
16 #include "services/service_manager/public/cpp/service_context.h" 16 #include "services/service_manager/public/cpp/service_context.h"
17 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 17 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
18 18
19 namespace device { 19 namespace device {
20 20
21 namespace { 21 namespace {
22 22
23 const char kTestServiceName[] = "device_unittests"; 23 const char kTestServiceName[] = "device_unittests";
24 24
25 // The test service responsible to package Device Service. 25 // The test service responsible to package Device Service.
26 class ServiceTestClient : public service_manager::test::ServiceTestClient, 26 class ServiceTestClient : public service_manager::test::ServiceTestClient,
27 public service_manager::mojom::ServiceFactory, 27 public service_manager::mojom::ServiceFactory,
28 public service_manager::InterfaceFactory< 28 public service_manager::InterfaceFactory<
29 service_manager::mojom::ServiceFactory> { 29 service_manager::mojom::ServiceFactory> {
30 public: 30 public:
31 explicit ServiceTestClient(service_manager::test::ServiceTest* test) 31 explicit ServiceTestClient(service_manager::test::ServiceTest* test)
32 : service_manager::test::ServiceTestClient(test), 32 : service_manager::test::ServiceTestClient(test),
33 io_thread_("DeviceServiceTestIOThread"), 33 io_thread_("DeviceServiceTestIOThread"),
34 file_thread_("DeviceServiceTestFileThread") {} 34 file_thread_("DeviceServiceTestFileThread") {
35 registry_.AddInterface<service_manager::mojom::ServiceFactory>(this);
36 }
35 ~ServiceTestClient() override {} 37 ~ServiceTestClient() override {}
36 38
37 protected: 39 protected:
38 bool OnConnect(const service_manager::ServiceInfo& remote_info, 40 void OnBindInterface(const service_manager::ServiceInfo& source_info,
39 service_manager::InterfaceRegistry* registry) override { 41 const std::string& interface_name,
40 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); 42 mojo::ScopedMessagePipeHandle interface_pipe) override {
41 return true; 43 registry_.BindInterface(source_info.identity, interface_name,
44 std::move(interface_pipe));
42 } 45 }
43 46
44 void CreateService(service_manager::mojom::ServiceRequest request, 47 void CreateService(service_manager::mojom::ServiceRequest request,
45 const std::string& name) override { 48 const std::string& name) override {
46 if (name == device::mojom::kServiceName) { 49 if (name == device::mojom::kServiceName) {
47 io_thread_.Start(); 50 io_thread_.Start();
48 file_thread_.Start(); 51 file_thread_.Start();
49 #if defined(OS_ANDROID) 52 #if defined(OS_ANDROID)
50 device_service_context_.reset(new service_manager::ServiceContext( 53 device_service_context_.reset(new service_manager::ServiceContext(
51 CreateDeviceService(file_thread_.task_runner(), 54 CreateDeviceService(file_thread_.task_runner(),
(...skipping 10 matching lines...) Expand all
62 } 65 }
63 66
64 void Create(const service_manager::Identity& remote_identity, 67 void Create(const service_manager::Identity& remote_identity,
65 service_manager::mojom::ServiceFactoryRequest request) override { 68 service_manager::mojom::ServiceFactoryRequest request) override {
66 service_factory_bindings_.AddBinding(this, std::move(request)); 69 service_factory_bindings_.AddBinding(this, std::move(request));
67 } 70 }
68 71
69 private: 72 private:
70 base::Thread io_thread_; 73 base::Thread io_thread_;
71 base::Thread file_thread_; 74 base::Thread file_thread_;
75 service_manager::BinderRegistry registry_;
72 mojo::BindingSet<service_manager::mojom::ServiceFactory> 76 mojo::BindingSet<service_manager::mojom::ServiceFactory>
73 service_factory_bindings_; 77 service_factory_bindings_;
74 std::unique_ptr<service_manager::ServiceContext> device_service_context_; 78 std::unique_ptr<service_manager::ServiceContext> device_service_context_;
75 79
76 WakeLockContextCallback wake_lock_context_callback_; 80 WakeLockContextCallback wake_lock_context_callback_;
77 }; 81 };
78 82
79 } // namespace 83 } // namespace
80 84
81 DeviceServiceTestBase::DeviceServiceTestBase() 85 DeviceServiceTestBase::DeviceServiceTestBase()
82 : ServiceTest(kTestServiceName) {} 86 : ServiceTest(kTestServiceName) {}
83 87
84 DeviceServiceTestBase::~DeviceServiceTestBase() {} 88 DeviceServiceTestBase::~DeviceServiceTestBase() {}
85 89
86 std::unique_ptr<service_manager::Service> 90 std::unique_ptr<service_manager::Service>
87 DeviceServiceTestBase::CreateService() { 91 DeviceServiceTestBase::CreateService() {
88 return base::MakeUnique<ServiceTestClient>(this); 92 return base::MakeUnique<ServiceTestClient>(this);
89 } 93 }
90 94
91 } // namespace device 95 } // namespace device
OLDNEW
« no previous file with comments | « services/device/device_service.cc ('k') | services/device/public/cpp/power_monitor/power_monitor_broadcast_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698