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

Unified Diff: services/resource_coordinator/memory/coordinator/process_map.cc

Issue 2883693002: [Memory-UMA] Implement basic working prototype. (Closed)
Patch Set: Fix test. 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/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..b20be808aa9b8d189f828b57303b5b3e475d9388
--- /dev/null
+++ b/services/resource_coordinator/memory/coordinator/process_map.cc
@@ -0,0 +1,68 @@
+// 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/connector.h"
+#include "services/service_manager/public/cpp/identity.h"
+#include "services/service_manager/public/interfaces/constants.mojom.h"
+#include "services/service_manager/public/interfaces/service_manager.mojom.h"
+
+namespace memory_instrumentation {
+
+ProcessMap::ProcessMap(service_manager::Connector* connector) : binding_(this) {
+ if (connector) {
+ service_manager::mojom::ServiceManagerPtr service_manager;
+ connector->BindInterface(service_manager::mojom::kServiceName,
+ &service_manager);
+ service_manager::mojom::ServiceManagerListenerPtr listener;
+ service_manager::mojom::ServiceManagerListenerRequest request(
+ mojo::MakeRequest(&listener));
+ service_manager->AddListener(std::move(listener));
+
+ binding_.Bind(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) {
+ if (instance->pid == base::kNullProcessId)
+ return;
+
+ const service_manager::Identity& identity = instance->identity;
+ DCHECK(instances_.find(identity) == instances_.end());
+ instances_.emplace(identity, instance->pid);
+}
+
+void ProcessMap::OnServiceStarted(const service_manager::Identity& identity,
+ uint32_t pid) {
+ instances_[identity] = pid;
+}
+
+void ProcessMap::OnServiceStopped(const service_manager::Identity& identity) {
+ instances_.erase(identity);
+}
+
+base::ProcessId ProcessMap::GetProcessId(
+ service_manager::Identity identity) const {
+ auto instance = instances_.find(identity);
+ if (instance == instances_.end())
+ return base::kNullProcessId;
+ return instance->second;
+}
+
+} // namespace memory_instrumentation

Powered by Google App Engine
This is Rietveld 408576698