OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | 5 #ifndef COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ |
6 #define COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | 6 #define COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ |
7 | 7 |
8 #include "base/trace_event/memory_dump_manager.h" | 8 #include "base/trace_event/memory_dump_manager.h" |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "components/tracing/tracing_messages.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
16 } // namespace base | 17 } // namespace base |
17 | 18 |
18 namespace tracing { | 19 namespace tracing { |
19 | 20 |
20 class ChildTraceMessageFilter; | 21 class ChildTraceMessageFilter; |
21 | 22 |
22 // This class is a simple proxy class between the MemoryDumpManager and the | 23 // This class is a simple proxy class between the MemoryDumpManager and the |
23 // ChildTraceMessageFilter. It's only purpose is to adapt the lifetime of | 24 // ChildTraceMessageFilter. It's only purpose is to adapt the lifetime of |
24 // CTMF to the demands of MDM, which expects the delegate to be thread-safe | 25 // CTMF to the demands of MDM, which expects the delegate to be thread-safe |
25 // and long lived. CTMF, instead, can be torn down during browser shutdown. | 26 // and long lived. CTMF, instead, can be torn down during browser shutdown. |
26 // This class is registered as MDM delegate in child processes and handles | 27 // This class is registered as MDM delegate in child processes and handles |
27 // gracefully (and thread-safely) failures in the case of a lack of the CTMF. | 28 // gracefully (and thread-safely) failures in the case of a lack of the CTMF. |
28 class ChildMemoryDumpManagerDelegateImpl | 29 class ChildMemoryDumpManagerDelegateImpl |
29 : public base::trace_event::MemoryDumpManagerDelegate { | 30 : public base::trace_event::MemoryDumpManagerDelegate { |
30 public: | 31 public: |
31 static ChildMemoryDumpManagerDelegateImpl* GetInstance(); | 32 static ChildMemoryDumpManagerDelegateImpl* GetInstance(); |
32 | 33 |
33 // base::trace_event::MemoryDumpManagerDelegate implementation. | 34 // base::trace_event::MemoryDumpManagerDelegate implementation. |
34 void RequestGlobalMemoryDump( | 35 void RequestGlobalMemoryDump( |
35 const base::trace_event::MemoryDumpRequestArgs& args, | 36 const base::trace_event::MemoryDumpRequestArgs& args, |
36 const base::trace_event::MemoryDumpCallback& callback) override; | 37 const base::trace_event::MemoryDumpCallback& callback) override; |
37 uint64 GetTracingProcessId() const override; | 38 uint64 GetTracingProcessId() const override; |
38 | 39 |
39 void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf); | 40 void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf); |
40 | 41 |
41 // Pass kInvalidTracingProcessId to invalidate the id. | 42 // Set the child process tracing id and file descriptors for tracing. This |
42 void set_tracing_process_id(uint64 id) { | 43 // sets tracing_process_id and sends the file decriptor to relevant dump |
43 DCHECK_IMPLIES( | 44 // providers. ResetMemoryTracingInfo should be called at the end of tracing to |
44 tracing_process_id_ != | 45 // close these files which are not supposed to be used in child if not for |
45 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId, | 46 // tracing. |
46 id == base::trace_event::MemoryDumpManager::kInvalidTracingProcessId || | 47 void SetMemoryTracingInfo( |
47 id == tracing_process_id_); | 48 const TracingMsg_MemoryTracingInfo& memory_tracing_info); |
48 tracing_process_id_ = id; | 49 |
49 } | 50 // Resets the tracing process id and resets the relevant dump providers. |
| 51 void ResetMemoryTracingInfo(); |
50 | 52 |
51 protected: | 53 protected: |
52 // Make CreateProcessDump() visible to ChildTraceMessageFilter. | 54 // Make CreateProcessDump() visible to ChildTraceMessageFilter. |
53 friend class ChildTraceMessageFilter; | 55 friend class ChildTraceMessageFilter; |
54 | 56 |
55 private: | 57 private: |
56 friend struct base::DefaultSingletonTraits< | 58 friend struct base::DefaultSingletonTraits< |
57 ChildMemoryDumpManagerDelegateImpl>; | 59 ChildMemoryDumpManagerDelegateImpl>; |
58 | 60 |
59 ChildMemoryDumpManagerDelegateImpl(); | 61 ChildMemoryDumpManagerDelegateImpl(); |
(...skipping 12 matching lines...) Expand all Loading... |
72 // The unique id of the child process, created for tracing and is expected to | 74 // The unique id of the child process, created for tracing and is expected to |
73 // be valid only when tracing is enabled. | 75 // be valid only when tracing is enabled. |
74 uint64 tracing_process_id_; | 76 uint64 tracing_process_id_; |
75 | 77 |
76 DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl); | 78 DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl); |
77 }; | 79 }; |
78 | 80 |
79 } // namespace tracing | 81 } // namespace tracing |
80 | 82 |
81 #endif // COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | 83 #endif // COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ |
OLD | NEW |