OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/resource_coordinator/memory/coordinator/process_map.h" |
| 6 |
| 7 #include "base/process/process_handle.h" |
| 8 #include "mojo/public/cpp/bindings/binding.h" |
| 9 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" |
| 10 #include "services/service_manager/public/cpp/connector.h" |
| 11 #include "services/service_manager/public/cpp/identity.h" |
| 12 #include "services/service_manager/public/interfaces/constants.mojom.h" |
| 13 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
| 14 |
| 15 namespace memory_instrumentation { |
| 16 |
| 17 ProcessMap::ProcessMap(service_manager::Connector* connector) : binding_(this) { |
| 18 if (connector) { |
| 19 service_manager::mojom::ServiceManagerPtr service_manager; |
| 20 connector->BindInterface(service_manager::mojom::kServiceName, |
| 21 &service_manager); |
| 22 service_manager::mojom::ServiceManagerListenerPtr listener; |
| 23 service_manager::mojom::ServiceManagerListenerRequest request( |
| 24 mojo::MakeRequest(&listener)); |
| 25 service_manager->AddListener(std::move(listener)); |
| 26 |
| 27 binding_.Bind(std::move(request)); |
| 28 } |
| 29 } |
| 30 |
| 31 ProcessMap::~ProcessMap() {} |
| 32 |
| 33 void ProcessMap::OnInit(std::vector<RunningServiceInfoPtr> instances) { |
| 34 // This callback should only be called with an empty model. |
| 35 DCHECK(instances_.empty()); |
| 36 for (size_t i = 0; i < instances.size(); ++i) { |
| 37 const service_manager::Identity& identity = instances[i]->identity; |
| 38 instances_.emplace(identity, instances[i]->pid); |
| 39 } |
| 40 } |
| 41 |
| 42 void ProcessMap::OnServiceCreated(RunningServiceInfoPtr instance) { |
| 43 if (instance->pid == base::kNullProcessId) |
| 44 return; |
| 45 |
| 46 const service_manager::Identity& identity = instance->identity; |
| 47 DCHECK(instances_.find(identity) == instances_.end()); |
| 48 instances_.emplace(identity, instance->pid); |
| 49 } |
| 50 |
| 51 void ProcessMap::OnServiceStarted(const service_manager::Identity& identity, |
| 52 uint32_t pid) { |
| 53 instances_[identity] = pid; |
| 54 } |
| 55 |
| 56 void ProcessMap::OnServiceStopped(const service_manager::Identity& identity) { |
| 57 instances_.erase(identity); |
| 58 } |
| 59 |
| 60 base::ProcessId ProcessMap::GetProcessId( |
| 61 service_manager::Identity identity) const { |
| 62 auto instance = instances_.find(identity); |
| 63 if (instance == instances_.end()) |
| 64 return base::kNullProcessId; |
| 65 return instance->second; |
| 66 } |
| 67 |
| 68 } // namespace memory_instrumentation |
OLD | NEW |