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