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

Unified Diff: services/test/service_impl.cc

Issue 2829003005: Test service as minimum repro for sharing memory handle (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/test/service_impl.h ('k') | services/test/service_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « services/test/service_impl.h ('k') | services/test/service_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698