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/identity.h" |
| 11 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
| 12 |
| 13 namespace memory_instrumentation { |
| 14 |
| 15 ProcessMap::ProcessMap() : binding_(this) {} |
| 16 |
| 17 ProcessMap::~ProcessMap() {} |
| 18 |
| 19 void ProcessMap::BindRequest( |
| 20 service_manager::mojom::ServiceManagerListenerRequest request) { |
| 21 DCHECK(!binding_.is_bound()); |
| 22 binding_.Bind(std::move(request)); |
| 23 } |
| 24 |
| 25 void ProcessMap::OnInit(std::vector<RunningServiceInfoPtr> instances) { |
| 26 // This callback should only be called with an empty model. |
| 27 DCHECK(instances_.empty()); |
| 28 for (size_t i = 0; i < instances.size(); ++i) { |
| 29 const service_manager::Identity& identity = instances[i]->identity; |
| 30 instances_.emplace(identity, instances[i]->pid); |
| 31 } |
| 32 } |
| 33 |
| 34 void ProcessMap::OnServiceCreated(RunningServiceInfoPtr instance) { |
| 35 const service_manager::Identity& identity = instance->identity; |
| 36 // The instance should not already exists |
| 37 DCHECK(instances_.find(identity) == instances_.end()); |
| 38 instances_.emplace(identity, instance->pid); |
| 39 } |
| 40 |
| 41 void ProcessMap::OnServiceStarted(const service_manager::Identity& identity, |
| 42 uint32_t pid) { |
| 43 instances_[identity] = pid; |
| 44 } |
| 45 |
| 46 void ProcessMap::OnServiceStopped(const service_manager::Identity& identity) { |
| 47 DCHECK(instances_.find(identity) != instances_.end()); |
| 48 instances_.erase(identity); |
| 49 } |
| 50 |
| 51 base::ProcessId ProcessMap::GetProcessId( |
| 52 service_manager::Identity identity) const { |
| 53 auto instance = instances_.find(identity); |
| 54 if (instance == instances_.end()) |
| 55 return base::kNullProcessId; |
| 56 return instance->second; |
| 57 } |
| 58 |
| 59 } // namespace memory_instrumentation |
OLD | NEW |