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

Side by Side Diff: services/resource_coordinator/memory/coordinator/process_map.h

Issue 2883693002: [Memory-UMA] Implement basic working prototype. (Closed)
Patch Set: Respecify dependent CL, which had somehow gotten lost. 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 unified diff | Download patch
OLDNEW
(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 #ifndef SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_
6 #define SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_
7
8 #include <unordered_map>
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 s/unordered_map/map/ (see other comment below)
erikchen 2017/05/15 17:29:15 Done.
9 #include <vector>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/hash.h"
13 #include "base/process/process_handle.h"
14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h"
16 #include "services/service_manager/public/cpp/identity.h"
17 #include "services/service_manager/public/interfaces/service_manager.mojom.h"
18
19 namespace memory_instrumentation {
20
21 struct IdentityHasher {
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 no need of this. Use a std::map (see brett's post
erikchen 2017/05/15 17:29:15 Done.
22 std::size_t operator()(const service_manager::Identity& identity) const {
23 return base::Hash(identity.name() + identity.user_id() +
24 identity.instance());
25 }
26 };
27
28 // Maintains an unordered_map from service_manager::Identity to
29 // base::ProcessId pid. This allows |pid| lookup by service_manager::Identity.
30 class ProcessMap : public service_manager::mojom::ServiceManagerListener {
31 public:
32 ProcessMap();
33 ~ProcessMap() override;
34
35 // Must be called exactly once to start receiving callbacks.
36 void BindRequest(
37 service_manager::mojom::ServiceManagerListenerRequest request);
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 if you just pass the Connector in the ctor there i
erikchen 2017/05/15 17:29:15 Done.
38
39 base::ProcessId GetProcessId(service_manager::Identity identity) const;
40
41 protected:
42 private:
43 FRIEND_TEST_ALL_PREFIXES(ProcessMapTest, TypicalCase);
44 FRIEND_TEST_ALL_PREFIXES(ProcessMapTest, PresentInInit);
45
46 using RunningServiceInfoPtr = service_manager::mojom::RunningServiceInfoPtr;
47
48 // Overridden from service_manager::mojom::ServiceManagerListener:
49 void OnInit(std::vector<RunningServiceInfoPtr> instances) override;
50
51 void OnServiceCreated(RunningServiceInfoPtr instance) override;
52
53 void OnServiceStarted(const service_manager::Identity& identity,
54 uint32_t pid) override;
55 void OnServiceFailedToStart(
56 const service_manager::Identity& identity) override {}
57
58 void OnServiceStopped(const service_manager::Identity& identity) override;
59
60 mojo::Binding<service_manager::mojom::ServiceManagerListener> binding_;
61 std::unordered_map<service_manager::Identity, base::ProcessId, IdentityHasher>
62 instances_;
63
64 DISALLOW_COPY_AND_ASSIGN(ProcessMap);
65 };
66
67 } // namespace memory_instrumentation
68 #endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698