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 #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE
GATE_IMPL_H_ | |
6 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_DELE
GATE_IMPL_H_ | |
7 | |
8 #include "base/single_thread_task_runner.h" | |
9 #include "base/synchronization/lock.h" | |
10 #include "base/trace_event/memory_dump_manager.h" | |
11 #include "base/trace_event/memory_dump_request_args.h" | |
12 #include "mojo/public/cpp/bindings/binding.h" | |
13 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" | |
14 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" | |
15 #include "services/service_manager/public/cpp/connector.h" | |
16 | |
17 namespace memory_instrumentation { | |
18 | |
19 // This is the bridge between MemoryDumpManager and the Coordinator service. | |
20 // This indirection is needed to avoid a dependency from //base, where | |
21 // MemoryDumpManager lives, to //services, where the Coordinator service lives. | |
22 // | |
23 // This cannot just be implemented by the Coordinator service, because there is | |
24 // no Coordinator service in child processes. So, in a child process, the | |
25 // delegate remotely connects to the Coordinator service. In the browser | |
26 // process, the delegate locally connects to the Coordinator service. | |
27 class MemoryDumpManagerDelegateImpl | |
28 : public base::trace_event::MemoryDumpManagerDelegate, | |
29 public mojom::ProcessLocalDumpManager { | |
30 public: | |
31 class Config { | |
32 public: | |
33 Config(service_manager::Connector* connector, | |
34 const std::string& service_name) | |
35 : connector_(connector), | |
36 service_name_(service_name), | |
37 coordinator_(nullptr) {} | |
38 Config(Coordinator* coordinator) | |
39 : connector_(nullptr), coordinator_(coordinator) {} | |
40 ~Config(); | |
41 | |
42 service_manager::Connector* connector() const { return connector_; } | |
43 | |
44 const std::string& service_name() const { return service_name_; } | |
45 | |
46 Coordinator* coordinator() const { return coordinator_; } | |
47 | |
48 private: | |
49 service_manager::Connector* connector_; | |
50 const std::string service_name_; | |
51 Coordinator* coordinator_; | |
52 bool is_test_config_; | |
53 }; | |
54 | |
55 explicit MemoryDumpManagerDelegateImpl(const Config& config); | |
56 ~MemoryDumpManagerDelegateImpl() override; | |
57 | |
58 bool IsCoordinator() const override; | |
59 | |
60 // The base::trace_event::MemoryDumpManager calls this. | |
61 void RequestGlobalMemoryDump( | |
62 const base::trace_event::MemoryDumpRequestArgs& args, | |
63 const base::trace_event::GlobalMemoryDumpCallback& callback) override; | |
64 | |
65 Config config() { return config_; } | |
66 void SetAsNonCoordinatorForTesting(); | |
67 | |
68 private: | |
69 friend std::default_delete<MemoryDumpManagerDelegateImpl>; // For testing | |
70 friend class MemoryDumpManagerDelegateImplTest; // For testing | |
71 | |
72 // The ProcessLocalDumpManager interface. The coordinator calls this. | |
73 void RequestProcessMemoryDump( | |
74 const base::trace_event::MemoryDumpRequestArgs& args, | |
75 const RequestProcessMemoryDumpCallback& callback) override; | |
76 | |
77 // A proxy callback for updating |pending_memory_dump_guid_|. | |
78 void MemoryDumpCallbackProxy( | |
79 const base::trace_event::GlobalMemoryDumpCallback& callback, | |
80 uint64_t dump_guid, | |
81 bool success); | |
82 | |
83 mojom::CoordinatorPtr coordinator_; | |
84 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; | |
85 const Config config_; | |
86 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
87 uint64_t pending_memory_dump_guid_; | |
88 | |
89 // Prevents racy access to |pending_memory_dump_guid_|. | |
90 base::Lock pending_memory_dump_guid_lock_; | |
91 | |
92 // Prevents racy access to |initialized_|. | |
93 base::Lock initialized_lock_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); | |
96 }; | |
97 | |
98 } // namespace memory_instrumentation | |
99 | |
100 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D
ELEGATE_IMPL_H_ | |
OLD | NEW |