OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_TRACING_CHILD_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | |
6 #define COMPONENTS_TRACING_CHILD_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | |
7 | |
8 #include "base/trace_event/memory_dump_manager.h" | |
9 | |
10 #include <stdint.h> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/singleton.h" | |
15 #include "base/synchronization/lock.h" | |
16 #include "components/tracing/tracing_export.h" | |
17 | |
18 namespace base { | |
19 class SingleThreadTaskRunner; | |
20 } // namespace base | |
21 | |
22 namespace tracing { | |
23 | |
24 class ChildTraceMessageFilter; | |
25 | |
26 // This class is a simple proxy class between the MemoryDumpManager and the | |
27 // ChildTraceMessageFilter. It's only purpose is to adapt the lifetime of | |
28 // CTMF to the demands of MDM, which expects the delegate to be thread-safe | |
29 // and long lived. CTMF, instead, can be torn down during browser shutdown. | |
30 // This class is registered as MDM delegate in child processes and handles | |
31 // gracefully (and thread-safely) failures in the case of a lack of the CTMF. | |
32 class TRACING_EXPORT ChildMemoryDumpManagerDelegateImpl | |
33 : public base::trace_event::MemoryDumpManagerDelegate { | |
34 public: | |
35 static ChildMemoryDumpManagerDelegateImpl* GetInstance(); | |
36 | |
37 // base::trace_event::MemoryDumpManagerDelegate implementation. | |
38 void RequestGlobalMemoryDump( | |
39 const base::trace_event::MemoryDumpRequestArgs& args, | |
40 const base::trace_event::MemoryDumpCallback& callback) override; | |
41 uint64_t GetTracingProcessId() const override; | |
42 | |
43 void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf); | |
44 | |
45 // Pass kInvalidTracingProcessId to invalidate the id. | |
46 void set_tracing_process_id(uint64_t id) { | |
47 DCHECK(tracing_process_id_ == | |
48 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId || | |
49 id == | |
50 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId || | |
51 id == tracing_process_id_); | |
52 tracing_process_id_ = id; | |
53 } | |
54 | |
55 protected: | |
56 // Make CreateProcessDump() visible to ChildTraceMessageFilter. | |
57 friend class ChildTraceMessageFilter; | |
58 | |
59 private: | |
60 friend struct base::DefaultSingletonTraits< | |
61 ChildMemoryDumpManagerDelegateImpl>; | |
62 | |
63 ChildMemoryDumpManagerDelegateImpl(); | |
64 ~ChildMemoryDumpManagerDelegateImpl() override; | |
65 | |
66 ChildTraceMessageFilter* ctmf_; // Not owned. | |
67 | |
68 // The SingleThreadTaskRunner where the |ctmf_| lives. | |
69 // It is NULL iff |cmtf_| is NULL. | |
70 scoped_refptr<base::SingleThreadTaskRunner> ctmf_task_runner_; | |
71 | |
72 // Protects from concurrent access to |ctmf_task_runner_| to allow | |
73 // RequestGlobalMemoryDump to be called from arbitrary threads. | |
74 base::Lock lock_; | |
75 | |
76 // The unique id of the child process, created for tracing and is expected to | |
77 // be valid only when tracing is enabled. | |
78 uint64_t tracing_process_id_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl); | |
81 }; | |
82 | |
83 } // namespace tracing | |
84 | |
85 #endif // COMPONENTS_TRACING_CHILD_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_ | |
OLD | NEW |