| Index: services/resource_coordinator/memory/coordinator/process_map.cc
|
| diff --git a/services/resource_coordinator/memory/coordinator/process_map.cc b/services/resource_coordinator/memory/coordinator/process_map.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2b2e610c53163f0b8563687e13ac9e007881df3b
|
| --- /dev/null
|
| +++ b/services/resource_coordinator/memory/coordinator/process_map.cc
|
| @@ -0,0 +1,60 @@
|
| +// 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/resource_coordinator/memory/coordinator/process_map.h"
|
| +
|
| +#include "base/process/process_handle.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "services/resource_coordinator/public/interfaces/memory/memory_instrumentation.mojom.h"
|
| +#include "services/service_manager/public/cpp/identity.h"
|
| +#include "services/service_manager/public/interfaces/service_manager.mojom.h"
|
| +
|
| +namespace memory_instrumentation {
|
| +
|
| +ProcessMap::ProcessMap(
|
| + service_manager::mojom::ServiceManagerListenerRequest request)
|
| + : binding_(this, std::move(request)) {}
|
| +
|
| +ProcessMap::~ProcessMap() {}
|
| +
|
| +void ProcessMap::OnInit(std::vector<RunningServiceInfoPtr> instances) {
|
| + // This callback should only be called with an empty model.
|
| + DCHECK(instances_.empty());
|
| + for (size_t i = 0; i < instances.size(); ++i) {
|
| + const service_manager::Identity& identity = instances[i]->identity;
|
| + instances_.emplace(identity, instances[i]->pid);
|
| + }
|
| +}
|
| +
|
| +void ProcessMap::OnServiceCreated(RunningServiceInfoPtr instance) {
|
| + service_manager::Identity identity = instance->identity;
|
| + // The instance should not already exists
|
| + DCHECK(instances_.find(identity) == instances_.end());
|
| + instances_.emplace(identity, instance->pid);
|
| +}
|
| +
|
| +void ProcessMap::OnServiceStarted(const service_manager::Identity& identity,
|
| + uint32_t pid) {
|
| + auto instance = instances_.find(identity);
|
| + if (instance != instances_.end()) {
|
| + instance->second = pid;
|
| + }
|
| +}
|
| +
|
| +void ProcessMap::OnServiceStopped(const service_manager::Identity& identity) {
|
| + auto instance = instances_.find(identity);
|
| + DCHECK(instance != instances_.end());
|
| + instances_.erase(instance);
|
| +}
|
| +
|
| +base::ProcessId ProcessMap::GetProcessId(
|
| + service_manager::Identity identity) const {
|
| + auto instance = instances_.find(identity);
|
| + if (instance == instances_.end())
|
| +
|
| + return base::kNullProcessHandle;
|
| + return instance->second;
|
| +}
|
| +
|
| +} // namespace memory_instrumentation
|
|
|