Index: services/test/service_impl.cc |
diff --git a/services/test/service_impl.cc b/services/test/service_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d60360e13b5c2d187a445c1abd89527f8933d781 |
--- /dev/null |
+++ b/services/test/service_impl.cc |
@@ -0,0 +1,43 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/test/service_impl.h" |
+ |
+#include "mojo/public/cpp/system/platform_handle.h" |
+#include "services/service_manager/public/cpp/service_info.h" |
+ |
+namespace test { |
+ |
+ServiceImpl::ServiceImpl() { |
+ registry_.AddInterface<mojom::Service>(this); |
+} |
+ |
+ServiceImpl::~ServiceImpl() = default; |
+ |
+void ServiceImpl::OnBindInterface( |
+ const service_manager::ServiceInfo& source_info, |
+ const std::string& interface_name, |
+ mojo::ScopedMessagePipeHandle interface_pipe) { |
+ registry_.BindInterface(source_info.identity, interface_name, |
+ std::move(interface_pipe)); |
+} |
+ |
+void ServiceImpl::Create(const service_manager::Identity& remote_identity, |
+ mojom::ServiceRequest request) { |
+ service_bindings_.AddBinding(this, std::move(request)); |
+} |
+ |
+void ServiceImpl::ShareBufferToTestReceiver(mojom::ReceiverPtr receiver) { |
+ test_receiver_ = std::move(receiver); |
+ const size_t kMemorySize = 1024; |
+ bool create_memory_success = |
+ shared_memory_.CreateAndMapAnonymous(kMemorySize); |
+ CHECK(create_memory_success); |
+ mojo::ScopedSharedBufferHandle handle = mojo::WrapSharedMemoryHandle( |
+ base::SharedMemory::DuplicateHandle(shared_memory_.handle()), kMemorySize, |
+ false /* read_only */); |
+ test_receiver_->ReceiveBufferHandle(std::move(handle)); |
+} |
+ |
+} // namespace test |