Chromium Code Reviews| 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/lazy_instance.h" | |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 8 #include "base/trace_event/memory_dump_manager.h" | 11 #include "base/trace_event/memory_dump_manager.h" |
| 9 #include "base/trace_event/memory_dump_request_args.h" | 12 #include "base/trace_event/memory_dump_request_args.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" | 14 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" |
| 12 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" | 15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" |
| 13 #include "services/service_manager/public/cpp/interface_provider.h" | 16 #include "services/service_manager/public/cpp/interface_provider.h" |
| 14 | 17 |
| 15 namespace memory_instrumentation { | 18 namespace memory_instrumentation { |
| 16 | 19 |
| 17 class MemoryDumpManagerDelegateImpl | 20 class MemoryDumpManagerDelegateImpl |
| 18 : public base::trace_event::MemoryDumpManagerDelegate, | 21 : public base::trace_event::MemoryDumpManagerDelegate, |
| 19 public mojom::ProcessLocalDumpManager { | 22 public mojom::ProcessLocalDumpManager { |
| 20 public: | 23 public: |
| 24 static MemoryDumpManagerDelegateImpl* GetInstance(); | |
| 25 | |
| 21 // Use to bind to a remote coordinator. | 26 // Use to bind to a remote coordinator. |
| 22 MemoryDumpManagerDelegateImpl( | 27 void InitializeWithInterfaceProvider( |
| 23 service_manager::InterfaceProvider* interface_provider); | 28 service_manager::InterfaceProvider* interface_provider); |
| 24 | 29 |
| 25 // Use to bind to a coordinator in the same process. | 30 // Use to bind to a coordinator in the same process. |
| 26 MemoryDumpManagerDelegateImpl(Coordinator* coordinator); | 31 void InitializeWithCoordinator( |
| 27 ~MemoryDumpManagerDelegateImpl() override; | 32 Coordinator* coordinator, |
| 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 28 | 34 |
| 29 bool IsCoordinator() const; | 35 bool IsCoordinator() const override; |
| 30 | 36 |
| 31 // The base::trace_event::MemoryDumpManager calls this. | 37 // The base::trace_event::MemoryDumpManager calls this. |
| 32 void RequestGlobalMemoryDump( | 38 void RequestGlobalMemoryDump( |
| 33 const base::trace_event::MemoryDumpRequestArgs& args, | 39 const base::trace_event::MemoryDumpRequestArgs& args, |
| 34 const base::trace_event::MemoryDumpCallback& callback) override; | 40 const base::trace_event::MemoryDumpCallback& callback) override; |
| 35 | 41 |
| 42 void SetAsNonCoordinatorForTesting(); | |
| 43 | |
| 36 private: | 44 private: |
| 45 friend std::default_delete<MemoryDumpManagerDelegateImpl>; // For testing | |
| 46 friend class MemoryDumpManagerDelegateImplTest; // For testing | |
| 47 friend struct base::DefaultLazyInstanceTraits<MemoryDumpManagerDelegateImpl>; | |
| 48 | |
| 49 MemoryDumpManagerDelegateImpl(); | |
| 50 ~MemoryDumpManagerDelegateImpl() override; | |
| 51 | |
| 37 // The ProcessLocalDumpManager interface. The coordinator calls this. | 52 // The ProcessLocalDumpManager interface. The coordinator calls this. |
| 38 void RequestProcessMemoryDump( | 53 void RequestProcessMemoryDump( |
| 39 const base::trace_event::MemoryDumpRequestArgs& args, | 54 const base::trace_event::MemoryDumpRequestArgs& args, |
| 40 const RequestProcessMemoryDumpCallback& callback) override; | 55 const RequestProcessMemoryDumpCallback& callback) override; |
| 41 | 56 |
| 57 // A proxy callback for updating |pending_memory_dump_guid_|. | |
| 58 void MemoryDumpCallbackProxy( | |
| 59 const base::trace_event::MemoryDumpCallback& callback, | |
| 60 uint64_t dump_guid, | |
| 61 bool success); | |
| 62 | |
| 63 bool initialized_; | |
| 42 bool is_coordinator_; | 64 bool is_coordinator_; |
| 43 mojom::CoordinatorPtr coordinator_; | 65 mojom::CoordinatorPtr coordinator_; |
| 44 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; | 66 mojo::Binding<mojom::ProcessLocalDumpManager> binding_; |
| 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
|
ssid
2017/02/24 23:19:05
Why do we have task runner here? It sounds cleaner
chiniforooshan
2017/02/25 00:04:51
In the case of child processes, CoordinatorImpl wi
ssid
2017/02/25 16:07:21
Hmm thanks for explaining. Sg
| |
| 68 uint64_t pending_memory_dump_guid_; | |
| 69 | |
| 70 // Prevents racy access to |pending_memory_dump_guid_|. | |
| 71 base::Lock pending_memory_dump_guid_lock_; | |
| 72 | |
| 73 // Prevents racy access to |initialized_|. | |
| 74 base::Lock initialized_lock_; | |
| 45 | 75 |
| 46 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); | 76 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegateImpl); |
| 47 }; | 77 }; |
| 48 | 78 |
| 49 } // namespace memory_instrumentation | 79 } // namespace memory_instrumentation |
| 50 | 80 |
| 51 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_ | 81 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_MEMORY_MEMORY_DUMP_MANAGER_D ELEGATE_IMPL_H_ |
| OLD | NEW |