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_MEMORY_DUMP_MANAGER_DELE
GATE_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_MEMORY_DUMP_MANAGER_DELE
GATE_IMPL_H_ |
7 | 7 |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/synchronization/lock.h" |
8 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
9 #include "base/trace_event/memory_dump_request_args.h" | 11 #include "base/trace_event/memory_dump_request_args.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" | 13 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" |
12 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" | 14 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" |
13 #include "services/service_manager/public/cpp/interface_provider.h" | 15 #include "services/service_manager/public/cpp/interface_provider.h" |
14 | 16 |
15 namespace memory_instrumentation { | 17 namespace memory_instrumentation { |
16 | 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. |
17 class MemoryDumpManagerDelegateImpl | 27 class MemoryDumpManagerDelegateImpl |
18 : public base::trace_event::MemoryDumpManagerDelegate, | 28 : public base::trace_event::MemoryDumpManagerDelegate, |
19 public mojom::ProcessLocalDumpManager { | 29 public mojom::ProcessLocalDumpManager { |
20 public: | 30 public: |
21 // Use to bind to a remote coordinator. | 31 class Config { |
22 MemoryDumpManagerDelegateImpl( | 32 public: |
23 service_manager::InterfaceProvider* interface_provider); | 33 Config(service_manager::InterfaceProvider* interface_provider) |
| 34 : interface_provider_(interface_provider), coordinator_(nullptr) {} |
| 35 Config(Coordinator* coordinator) |
| 36 : interface_provider_(nullptr), coordinator_(coordinator) {} |
| 37 ~Config(); |
24 | 38 |
25 // Use to bind to a coordinator in the same process. | 39 service_manager::InterfaceProvider* interface_provider() const { |
26 MemoryDumpManagerDelegateImpl(Coordinator* coordinator); | 40 return interface_provider_; |
27 ~MemoryDumpManagerDelegateImpl() override; | 41 } |
28 | 42 |
29 bool IsCoordinator() const; | 43 Coordinator* coordinator() const { return coordinator_; } |
| 44 |
| 45 private: |
| 46 service_manager::InterfaceProvider* interface_provider_; |
| 47 Coordinator* coordinator_; |
| 48 bool is_test_config_; |
| 49 }; |
| 50 |
| 51 // |
| 52 static MemoryDumpManagerDelegateImpl* Create(const Config& config); |
| 53 |
| 54 bool IsCoordinator() const override; |
30 | 55 |
31 // The base::trace_event::MemoryDumpManager calls this. | 56 // The base::trace_event::MemoryDumpManager calls this. |
32 void RequestGlobalMemoryDump( | 57 void RequestGlobalMemoryDump( |
33 const base::trace_event::MemoryDumpRequestArgs& args, | 58 const base::trace_event::MemoryDumpRequestArgs& args, |
34 const base::trace_event::MemoryDumpCallback& callback) override; | 59 const base::trace_event::MemoryDumpCallback& callback) override; |
35 | 60 |
| 61 Config config() { return config_; } |
| 62 void SetAsNonCoordinatorForTesting(); |
| 63 |
36 private: | 64 private: |
| 65 friend std::default_delete<MemoryDumpManagerDelegateImpl>; // For testing |
| 66 friend class MemoryDumpManagerDelegateImplTest; // For testing |
| 67 |
| 68 MemoryDumpManagerDelegateImpl(const Config& config); |
| 69 ~MemoryDumpManagerDelegateImpl() override; |
| 70 |
37 // The ProcessLocalDumpManager interface. The coordinator calls this. | 71 // The ProcessLocalDumpManager interface. The coordinator calls this. |
38 void RequestProcessMemoryDump( | 72 void RequestProcessMemoryDump( |
39 const base::trace_event::MemoryDumpRequestArgs& args, | 73 const base::trace_event::MemoryDumpRequestArgs& args, |
40 const RequestProcessMemoryDumpCallback& callback) override; | 74 const RequestProcessMemoryDumpCallback& callback) override; |
41 | 75 |
42 bool is_coordinator_; | 76 // A proxy callback for updating |pending_memory_dump_guid_|. |
| 77 void MemoryDumpCallbackProxy( |
| 78 const base::trace_event::MemoryDumpCallback& callback, |
| 79 uint64_t dump_guid, |
| 80 bool success); |
| 81 |
43 mojom::CoordinatorPtr coordinator_; | 82 mojom::CoordinatorPtr coordinator_; |
44 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; | 83 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; |
| 84 const Config config_; |
| 85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 86 uint64_t pending_memory_dump_guid_; |
| 87 |
| 88 // Prevents racy access to |pending_memory_dump_guid_|. |
| 89 base::Lock pending_memory_dump_guid_lock_; |
| 90 |
| 91 // Prevents racy access to |initialized_|. |
| 92 base::Lock initialized_lock_; |
45 | 93 |
46 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); | 94 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); |
47 }; | 95 }; |
48 | 96 |
49 } // namespace memory_instrumentation | 97 } // namespace memory_instrumentation |
50 | 98 |
51 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D
ELEGATE_IMPL_H_ | 99 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D
ELEGATE_IMPL_H_ |
OLD | NEW |