OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/test/service_impl.h" |
| 6 |
| 7 #include "mojo/public/cpp/system/platform_handle.h" |
| 8 #include "services/service_manager/public/cpp/service_info.h" |
| 9 |
| 10 namespace test { |
| 11 |
| 12 ServiceImpl::ServiceImpl() { |
| 13 registry_.AddInterface<mojom::Service>(this); |
| 14 } |
| 15 |
| 16 ServiceImpl::~ServiceImpl() = default; |
| 17 |
| 18 void ServiceImpl::OnBindInterface( |
| 19 const service_manager::ServiceInfo& source_info, |
| 20 const std::string& interface_name, |
| 21 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 22 registry_.BindInterface(source_info.identity, interface_name, |
| 23 std::move(interface_pipe)); |
| 24 } |
| 25 |
| 26 void ServiceImpl::Create(const service_manager::Identity& remote_identity, |
| 27 mojom::ServiceRequest request) { |
| 28 service_bindings_.AddBinding(this, std::move(request)); |
| 29 } |
| 30 |
| 31 void ServiceImpl::ShareBufferToTestReceiver(mojom::ReceiverPtr receiver) { |
| 32 test_receiver_ = std::move(receiver); |
| 33 const size_t kMemorySize = 1024; |
| 34 bool create_memory_success = |
| 35 shared_memory_.CreateAndMapAnonymous(kMemorySize); |
| 36 CHECK(create_memory_success); |
| 37 mojo::ScopedSharedBufferHandle handle = mojo::WrapSharedMemoryHandle( |
| 38 base::SharedMemory::DuplicateHandle(shared_memory_.handle()), kMemorySize, |
| 39 false /* read_only */); |
| 40 test_receiver_->ReceiveBufferHandle(std::move(handle)); |
| 41 } |
| 42 |
| 43 } // namespace test |
OLD | NEW |