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