| 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
|
|
|