| 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_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ | 5 #ifndef SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ |
| 6 #define SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ | 6 #define SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/trace_event/memory_dump_request_args.h" | 14 #include "base/trace_event/memory_dump_request_args.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" | 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "services/resource_coordinator/memory/coordinator/process_map.h" |
| 17 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" | 18 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" |
| 18 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" | 19 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" |
| 19 | 20 |
| 21 namespace service_manager { |
| 22 class Connector; |
| 23 } |
| 24 |
| 20 namespace memory_instrumentation { | 25 namespace memory_instrumentation { |
| 21 | 26 |
| 22 class CoordinatorImpl : public Coordinator, public mojom::Coordinator { | 27 class CoordinatorImpl : public Coordinator, public mojom::Coordinator { |
| 23 public: | 28 public: |
| 24 // The getter of the unique instance. | 29 // The getter of the unique instance. |
| 25 static CoordinatorImpl* GetInstance(); | 30 static CoordinatorImpl* GetInstance(); |
| 26 | 31 |
| 27 explicit CoordinatorImpl(bool initialize_memory_dump_manager); | 32 CoordinatorImpl(bool initialize_memory_dump_manager, |
| 33 service_manager::Connector* connector); |
| 28 | 34 |
| 29 // Coordinator | 35 // Coordinator |
| 30 void BindCoordinatorRequest( | 36 void BindCoordinatorRequest( |
| 31 const service_manager::BindSourceInfo& source_info, | 37 const service_manager::BindSourceInfo& source_info, |
| 32 mojom::CoordinatorRequest) override; | 38 mojom::CoordinatorRequest) override; |
| 33 | 39 |
| 34 bool initialize_memory_dump_manager() const { | 40 bool initialize_memory_dump_manager() const { |
| 35 return initialize_memory_dump_manager_; | 41 return initialize_memory_dump_manager_; |
| 36 } | 42 } |
| 37 | 43 |
| 44 protected: |
| 45 // virtual for testing. |
| 46 virtual service_manager::Identity GetDispatchContext() const; |
| 47 ~CoordinatorImpl() override; |
| 48 |
| 38 private: | 49 private: |
| 39 friend std::default_delete<CoordinatorImpl>; // For testing | 50 friend std::default_delete<CoordinatorImpl>; // For testing |
| 40 friend class CoordinatorImplTest; // For testing | 51 friend class CoordinatorImplTest; // For testing |
| 41 | 52 |
| 42 struct QueuedMemoryDumpRequest { | 53 struct QueuedMemoryDumpRequest { |
| 43 QueuedMemoryDumpRequest(const base::trace_event::MemoryDumpRequestArgs args, | 54 QueuedMemoryDumpRequest(const base::trace_event::MemoryDumpRequestArgs args, |
| 44 const RequestGlobalMemoryDumpCallback callback); | 55 const RequestGlobalMemoryDumpCallback callback); |
| 45 ~QueuedMemoryDumpRequest(); | 56 ~QueuedMemoryDumpRequest(); |
| 46 const base::trace_event::MemoryDumpRequestArgs args; | 57 const base::trace_event::MemoryDumpRequestArgs args; |
| 47 const RequestGlobalMemoryDumpCallback callback; | 58 const RequestGlobalMemoryDumpCallback callback; |
| 48 | 59 |
| 49 // Collects the data received from OnProcessMemoryDumpResponse(). | 60 // Collects the data received from OnProcessMemoryDumpResponse(). |
| 50 std::vector<mojom::ProcessMemoryDumpPtr> process_memory_dumps; | 61 std::vector<std::pair<base::ProcessId, mojom::ProcessMemoryDumpPtr>> |
| 62 process_memory_dumps; |
| 51 }; | 63 }; |
| 52 | 64 |
| 53 ~CoordinatorImpl() override; | 65 using ProcessLocalDumpManagerEntry = |
| 66 std::pair<mojom::ProcessLocalDumpManagerPtr, service_manager::Identity>; |
| 54 | 67 |
| 55 // mojom::Coordinator | 68 // mojom::Coordinator |
| 56 void RegisterProcessLocalDumpManager( | 69 void RegisterProcessLocalDumpManager( |
| 57 mojom::ProcessLocalDumpManagerPtr process_manager) override; | 70 mojom::ProcessLocalDumpManagerPtr process_manager) override; |
| 58 | 71 |
| 59 // Broadcasts a dump request to all the process-local managers registered and | 72 // Broadcasts a dump request to all the process-local managers registered and |
| 60 // notifies when all of them have completed, or the global dump attempt | 73 // notifies when all of them have completed, or the global dump attempt |
| 61 // failed. This is in the mojom::Coordinator interface. | 74 // failed. This is in the mojom::Coordinator interface. |
| 62 void RequestGlobalMemoryDump( | 75 void RequestGlobalMemoryDump( |
| 63 const base::trace_event::MemoryDumpRequestArgs& args, | 76 const base::trace_event::MemoryDumpRequestArgs& args, |
| 64 const RequestGlobalMemoryDumpCallback& callback) override; | 77 const RequestGlobalMemoryDumpCallback& callback) override; |
| 65 | 78 |
| 66 // Called when a process-local manager gets disconnected. | 79 // Called when a process-local manager gets disconnected. |
| 67 void UnregisterProcessLocalDumpManager( | 80 void UnregisterProcessLocalDumpManager( |
| 68 mojom::ProcessLocalDumpManager* process_manager); | 81 mojom::ProcessLocalDumpManager* process_manager); |
| 69 | 82 |
| 70 // Callback of RequestProcessMemoryDump. | 83 // Callback of RequestProcessMemoryDump. |
| 71 void OnProcessMemoryDumpResponse( | 84 void OnProcessMemoryDumpResponse( |
| 72 mojom::ProcessLocalDumpManager* process_manager, | 85 mojom::ProcessLocalDumpManager* process_manager, |
| 73 uint64_t dump_guid, | 86 uint64_t dump_guid, |
| 74 bool success, | 87 bool success, |
| 75 mojom::ProcessMemoryDumpPtr process_memory_dump); | 88 mojom::ProcessMemoryDumpPtr process_memory_dump); |
| 76 | 89 |
| 77 void PerformNextQueuedGlobalMemoryDump(); | 90 void PerformNextQueuedGlobalMemoryDump(); |
| 78 void FinalizeGlobalMemoryDumpIfAllManagersReplied(); | 91 void FinalizeGlobalMemoryDumpIfAllManagersReplied(); |
| 79 | 92 |
| 80 mojo::BindingSet<mojom::Coordinator> bindings_; | 93 mojo::BindingSet<mojom::Coordinator, service_manager::Identity> bindings_; |
| 81 | 94 |
| 82 // Registered ProcessLocalDumpManagers. | 95 // Registered ProcessLocalDumpManagers. |
| 83 std::map<mojom::ProcessLocalDumpManager*, mojom::ProcessLocalDumpManagerPtr> | 96 std::map<mojom::ProcessLocalDumpManager*, ProcessLocalDumpManagerEntry> |
| 84 process_managers_; | 97 process_managers_; |
| 85 | 98 |
| 86 // Pending process managers for RequestGlobalMemoryDump. | 99 // Pending process managers for RequestGlobalMemoryDump. |
| 87 std::set<mojom::ProcessLocalDumpManager*> pending_process_managers_; | 100 std::set<mojom::ProcessLocalDumpManager*> pending_process_managers_; |
| 88 int failed_memory_dump_count_; | 101 int failed_memory_dump_count_; |
| 89 std::list<QueuedMemoryDumpRequest> queued_memory_dump_requests_; | 102 std::list<QueuedMemoryDumpRequest> queued_memory_dump_requests_; |
| 90 | 103 |
| 91 const bool initialize_memory_dump_manager_; | 104 const bool initialize_memory_dump_manager_; |
| 92 | 105 |
| 93 base::ThreadChecker thread_checker_; | 106 base::ThreadChecker thread_checker_; |
| 94 | 107 |
| 108 std::unique_ptr<ProcessMap> process_map_; |
| 109 |
| 95 DISALLOW_COPY_AND_ASSIGN(CoordinatorImpl); | 110 DISALLOW_COPY_AND_ASSIGN(CoordinatorImpl); |
| 96 }; | 111 }; |
| 97 | 112 |
| 98 } // namespace memory_instrumentation | 113 } // namespace memory_instrumentation |
| 99 #endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ | 114 #endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_COORDINATOR_IMPL_H_ |
| OLD | NEW |