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

Unified Diff: services/blamer/blamer_service.cc

Issue 2885363004: [Hacky prototype] Create a shared-memory high-performance reporting service.
Patch Set: Created 3 years, 7 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
Index: services/blamer/blamer_service.cc
diff --git a/services/blamer/blamer_service.cc b/services/blamer/blamer_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..76e7c4e5aebede073f1750c24fb00b26d52042a4
--- /dev/null
+++ b/services/blamer/blamer_service.cc
@@ -0,0 +1,51 @@
+// Copyright 2017 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/blamer/blamer_service.h"
+
+#include "base/bind.h"
+#include "services/blamer/shared_memory_heap_registry.h"
+#include "services/service_manager/public/cpp/interface_registry.h"
+#include "services/service_manager/public/cpp/service_context.h"
+
+namespace blamer {
+
+namespace {
+
+void OnConnectionLost(std::unique_ptr<service_manager::ServiceContextRef> ref) {
+ // No-op. Merely takes ownership of |ref| so it can be destroyed when this
+ // function is invoked.
+}
+
+} // namespace
+
+BlamerService::BlamerService() : weak_factory_(this) {}
+
+BlamerService::~BlamerService() = default;
+
+// static
+std::unique_ptr<service_manager::Service> BlamerService::Create() {
+ return base::MakeUnique<BlamerService>();
+}
+
+void BlamerService::OnStart() {
+ ref_factory_.reset(new service_manager::ServiceContextRefFactory(
+ base::Bind(&service_manager::ServiceContext::RequestQuit,
+ base::Unretained(context()))));
+}
+
+bool BlamerService::OnConnect(const service_manager::ServiceInfo& remote_info,
+ service_manager::InterfaceRegistry* registry) {
+ // Add a reference to the service and tie it to the lifetime of the
+ // InterfaceRegistry's connection.
+ std::unique_ptr<service_manager::ServiceContextRef> connection_ref =
+ ref_factory_->CreateRef();
+ registry->AddConnectionLostClosure(
+ base::Bind(&OnConnectionLost, base::Passed(&connection_ref)));
+ registry->AddInterface(base::Bind(&SharedMemoryHeapRegistry::Create,
+ base::Unretained(ref_factory_.get())));
+ return true;
+}
+
+} // namespace blamer

Powered by Google App Engine
This is Rietveld 408576698