Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/device/device_service_test_base.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/threading/thread.h" | |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 12 #include "services/device/device_service.h" | |
| 13 #include "services/device/public/interfaces/constants.mojom.h" | |
| 14 #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" | |
| 17 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | |
| 18 | |
| 19 namespace device { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const char kTestServiceName[] = "device_unittests"; | |
| 24 | |
| 25 // The test service responsible to package Device Service. | |
| 26 class ServiceTestClient : public service_manager::test::ServiceTestClient, | |
| 27 public service_manager::mojom::ServiceFactory, | |
| 28 public service_manager::InterfaceFactory< | |
| 29 service_manager::mojom::ServiceFactory> { | |
| 30 public: | |
| 31 explicit ServiceTestClient(service_manager::test::ServiceTest* test) | |
| 32 : service_manager::test::ServiceTestClient(test), | |
| 33 io_thread_("DeviceServiceTestIOThread"), | |
| 34 file_thread_("DeviceServiceTestFileThread") {} | |
| 35 ~ServiceTestClient() override {} | |
| 36 | |
| 37 protected: | |
| 38 bool OnConnect(const service_manager::ServiceInfo& remote_info, | |
| 39 service_manager::InterfaceRegistry* registry) override { | |
| 40 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 void CreateService(service_manager::mojom::ServiceRequest request, | |
| 45 const std::string& name) override { | |
| 46 if (name == device::mojom::kServiceName) { | |
| 47 io_thread_.Start(); | |
| 48 file_thread_.Start(); | |
| 49 #if defined(OS_ANDROID) | |
| 50 device_service_context_.reset(new service_manager::ServiceContext( | |
| 51 CreateDeviceService(file_thread_.task_runner(), | |
| 52 io_thread_.task_runner(), | |
| 53 wake_lock_context_callback_), | |
| 54 std::move(request))); | |
| 55 #else | |
| 56 device_service_context_.reset(new service_manager::ServiceContext( | |
| 57 CreateDeviceService(file_thread_.task_runner(), | |
| 58 io_thread_.task_runner()), | |
| 59 std::move(request))); | |
| 60 #endif | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void Create(const service_manager::Identity& remote_identity, | |
| 65 service_manager::mojom::ServiceFactoryRequest request) override { | |
| 66 service_factory_bindings_.AddBinding(this, std::move(request)); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 mojo::BindingSet<service_manager::mojom::ServiceFactory> | |
| 71 service_factory_bindings_; | |
| 72 std::unique_ptr<service_manager::ServiceContext> device_service_context_; | |
| 73 | |
| 74 base::Thread io_thread_; | |
|
blundell
2017/03/31 11:22:30
nit: These should be moved above line 72 so that t
leonhsl(Using Gerrit)
2017/03/31 12:14:45
Acknowledged.
leonhsl(Using Gerrit)
2017/04/11 08:32:02
Done.
| |
| 75 base::Thread file_thread_; | |
| 76 WakeLockContextCallback wake_lock_context_callback_; | |
| 77 }; | |
| 78 | |
| 79 } // namespace | |
| 80 | |
| 81 DeviceServiceTestBase::DeviceServiceTestBase() | |
| 82 : ServiceTest(kTestServiceName) {} | |
| 83 | |
| 84 DeviceServiceTestBase::~DeviceServiceTestBase() {} | |
| 85 | |
| 86 std::unique_ptr<service_manager::Service> | |
| 87 DeviceServiceTestBase::CreateService() { | |
| 88 return base::MakeUnique<ServiceTestClient>(this); | |
| 89 } | |
| 90 | |
| 91 } // namespace device | |
| OLD | NEW |