Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / tracing / child_memory_dump_manager_delegate_impl.h
blob099948e64185bd5edf20d0865fd33dab1bde1f28
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"
13 namespace base {
14 class SingleThreadTaskRunner;
15 } // namespace base
17 namespace tracing {
19 class ChildTraceMessageFilter;
21 // This class is a simple proxy class between the MemoryDumpManager and the
22 // ChildTraceMessageFilter. It's only purpose is to adapt the lifetime of
23 // CTMF to the demands of MDM, which expects the delegate to be thread-safe
24 // and long lived. CTMF, instead, can be torn down during browser shutdown.
25 // This class is registered as MDM delegate in child processes and handles
26 // gracefully (and thread-safely) failures in the case of a lack of the CTMF.
27 class ChildMemoryDumpManagerDelegateImpl
28 : public base::trace_event::MemoryDumpManagerDelegate {
29 public:
30 static ChildMemoryDumpManagerDelegateImpl* GetInstance();
32 // base::trace_event::MemoryDumpManagerDelegate implementation.
33 void RequestGlobalMemoryDump(
34 const base::trace_event::MemoryDumpRequestArgs& args,
35 const base::trace_event::MemoryDumpCallback& callback) override;
36 uint64 GetTracingProcessId() const override;
38 void SetChildTraceMessageFilter(ChildTraceMessageFilter* ctmf);
40 // Pass kInvalidTracingProcessId to invalidate the id.
41 void set_tracing_process_id(uint64 id) {
42 DCHECK_IMPLIES(
43 tracing_process_id_ !=
44 base::trace_event::MemoryDumpManager::kInvalidTracingProcessId,
45 id == base::trace_event::MemoryDumpManager::kInvalidTracingProcessId ||
46 id == tracing_process_id_);
47 tracing_process_id_ = id;
50 protected:
51 // Make CreateProcessDump() visible to ChildTraceMessageFilter.
52 friend class ChildTraceMessageFilter;
54 private:
55 friend struct base::DefaultSingletonTraits<
56 ChildMemoryDumpManagerDelegateImpl>;
58 ChildMemoryDumpManagerDelegateImpl();
59 ~ChildMemoryDumpManagerDelegateImpl() override;
61 ChildTraceMessageFilter* ctmf_; // Not owned.
63 // The SingleThreadTaskRunner where the |ctmf_| lives.
64 // It is NULL iff |cmtf_| is NULL.
65 scoped_refptr<base::SingleThreadTaskRunner> ctmf_task_runner_;
67 // The unique id of the child process, created for tracing and is expected to
68 // be valid only when tracing is enabled.
69 uint64 tracing_process_id_;
71 DISALLOW_COPY_AND_ASSIGN(ChildMemoryDumpManagerDelegateImpl);
74 } // namespace tracing
76 #endif // COMPONENTS_TRACING_CHILD_MEMORY_DUMP_MANAGER_DELEGATE_IMPL_H_