Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / components / tracing / child_memory_dump_manager_delegate_impl.h
blobca5de293ed7f233cd06dcd286806c8161bd97b08
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.
5 #ifndef COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_
6 #define COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_
8 #include "base/trace_event/memory_dump_manager.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/singleton.h"
12 #include "base/synchronization/lock.h"
14 namespace base {
15 class SingleThreadTaskRunner;
16 } // namespace base
18 namespace tracing {
20 class ChildTraceMessageFilter;
22 // 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 // 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 // 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 class ChildMemoryDumpManagerDelegateImpl
29 : public base::trace_event::MemoryDumpManagerDelegate {
30 public:
31 static ChildMemoryDumpManagerDelegateImpl* GetInstance();
33 // base::trace_event::MemoryDumpManagerDelegate implementation.
34 void RequestGlobalMemoryDump(
35 const base::trace_event::MemoryDumpRequestArgs& args,
36 const base::trace_event::MemoryDumpCallback& callback) override;
37 uint64 GetTracingProcessId() const override;
39 void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf);
41 // Pass kInvalidTracingProcessId to invalidate the id.
42 void set_tracing_process_id(uint64 id) {
43 DCHECK_IMPLIES(
44 tracing_process_id_ !=
45 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId,
46 id == base::trace_event::MemoryDumpManager::kInvalidTracingProcessId ||
47 id == tracing_process_id_);
48 tracing_process_id_ = id;
51 protected:
52 // Make CreateProcessDump() visible to ChildTraceMessageFilter.
53 friend class ChildTraceMessageFilter;
55 private:
56 friend struct base::DefaultSingletonTraits<
57 ChildMemoryDumpManagerDelegateImpl>;
59 ChildMemoryDumpManagerDelegateImpl();
60 ~ChildMemoryDumpManagerDelegateImpl() override;
62 ChildTraceMessageFilter* ctmf_; // Not owned.
64 // The SingleThreadTaskRunner where the |ctmf_| lives.
65 // It is NULL iff |cmtf_| is NULL.
66 scoped_refptr<base::SingleThreadTaskRunner> ctmf_task_runner_;
68 // Protects from concurrent access to |ctmf_task_runner_| to allow
69 // RequestGlobalMemoryDump to be called from arbitrary threads.
70 base::Lock lock_;
72 // The unique id of the child process, created for tracing and is expected to
73 // be valid only when tracing is enabled.
74 uint64 tracing_process_id_;
76 DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl);
79 } // namespace tracing
81 #endif // COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_